From 1bbbd046c33a24272bf30ab3b13e5f5f2fa6b3a1 Mon Sep 17 00:00:00 2001 From: Evgeniy Cheban Date: Wed, 4 Jan 2023 20:52:46 +0100 Subject: [PATCH] Polish gh-12231 - Update copyright header - Use Set.of instead of HashSet in AuthorityAuthorizationManager - Align roleHierarchy test name with other tests in AuthoritiesAuthorizationManagerTests --- .../authorization/AuthorityAuthorizationManager.java | 6 ++---- .../authorization/AuthoritiesAuthorizationManagerTests.java | 6 +++--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/springframework/security/authorization/AuthorityAuthorizationManager.java b/core/src/main/java/org/springframework/security/authorization/AuthorityAuthorizationManager.java index f266fa3663..db4cf42e48 100644 --- a/core/src/main/java/org/springframework/security/authorization/AuthorityAuthorizationManager.java +++ b/core/src/main/java/org/springframework/security/authorization/AuthorityAuthorizationManager.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,8 +16,6 @@ package org.springframework.security.authorization; -import java.util.Arrays; -import java.util.HashSet; import java.util.Set; import java.util.function.Supplier; @@ -43,7 +41,7 @@ public final class AuthorityAuthorizationManager implements AuthorizationMana private final Set authorities; private AuthorityAuthorizationManager(String... authorities) { - this.authorities = new HashSet<>(Arrays.asList(authorities)); + this.authorities = Set.of(authorities); } /** diff --git a/core/src/test/java/org/springframework/security/authorization/AuthoritiesAuthorizationManagerTests.java b/core/src/test/java/org/springframework/security/authorization/AuthoritiesAuthorizationManagerTests.java index 92359a64b8..79b4540c96 100644 --- a/core/src/test/java/org/springframework/security/authorization/AuthoritiesAuthorizationManagerTests.java +++ b/core/src/test/java/org/springframework/security/authorization/AuthoritiesAuthorizationManagerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -74,14 +74,14 @@ class AuthoritiesAuthorizationManagerTests { } @Test - void hasRoleWhenRoleHierarchySetThenGreaterRoleTakesPrecedence() { + void checkWhenRoleHierarchySetThenGreaterRoleTakesPrecedence() { AuthoritiesAuthorizationManager manager = new AuthoritiesAuthorizationManager(); RoleHierarchyImpl roleHierarchy = new RoleHierarchyImpl(); roleHierarchy.setHierarchy("ROLE_ADMIN > ROLE_USER"); manager.setRoleHierarchy(roleHierarchy); Supplier authentication = () -> new TestingAuthenticationToken("user", "password", "ROLE_ADMIN"); - assertThat(manager.check(authentication, Collections.singleton("ROLE_ADMIN")).isGranted()).isTrue(); + assertThat(manager.check(authentication, Collections.singleton("ROLE_USER")).isGranted()).isTrue(); } }