1
1
/*
2
- * Copyright 2002-2021 the original author or authors.
2
+ * Copyright 2002-2022 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
17
17
package org .springframework .security .authorization ;
18
18
19
19
import java .util .HashSet ;
20
+ import java .util .List ;
20
21
import java .util .Set ;
21
22
import java .util .function .Supplier ;
22
23
@@ -37,10 +38,10 @@ public final class AuthorityAuthorizationManager<T> implements AuthorizationMana
37
38
38
39
private static final String ROLE_PREFIX = "ROLE_" ;
39
40
40
- private final Set <GrantedAuthority > authorities ;
41
+ private final List <GrantedAuthority > authorities ;
41
42
42
43
private AuthorityAuthorizationManager (String ... authorities ) {
43
- this .authorities = new HashSet <>( AuthorityUtils .createAuthorityList (authorities ) );
44
+ this .authorities = AuthorityUtils .createAuthorityList (authorities );
44
45
}
45
46
46
47
/**
@@ -132,16 +133,23 @@ private boolean isGranted(Authentication authentication) {
132
133
}
133
134
134
135
private boolean isAuthorized (Authentication authentication ) {
136
+ Set <String > authorities = getAuthoritySet ();
135
137
for (GrantedAuthority grantedAuthority : authentication .getAuthorities ()) {
136
- for (GrantedAuthority authority : this .authorities ) {
137
- if (authority .getAuthority ().equals (grantedAuthority .getAuthority ())) {
138
- return true ;
139
- }
138
+ if (authorities .contains (grantedAuthority .getAuthority ())) {
139
+ return true ;
140
140
}
141
141
}
142
142
return false ;
143
143
}
144
144
145
+ private Set <String > getAuthoritySet () {
146
+ Set <String > result = new HashSet <>();
147
+ for (GrantedAuthority grantedAuthority : this .authorities ) {
148
+ result .add (grantedAuthority .getAuthority ());
149
+ }
150
+ return result ;
151
+ }
152
+
145
153
@ Override
146
154
public String toString () {
147
155
return "AuthorityAuthorizationManager[authorities=" + this .authorities + "]" ;
0 commit comments