Closes #13754 Add hasScope and hasAnyScope for authorization rules
This commit is contained in:
parent
ab72998b7c
commit
81a708e25f
|
@ -0,0 +1,18 @@
|
|||
package org.springframework.security.oauth2.core;
|
||||
|
||||
|
||||
import org.springframework.security.authorization.AuthorityAuthorizationManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ScopeAuthorizationManagerFactory {
|
||||
|
||||
public static <T> AuthorityAuthorizationManager<T> hasScope(String scope) {
|
||||
return AuthorityAuthorizationManager.hasAuthority("SCOPE_" + scope);
|
||||
}
|
||||
|
||||
public static <T> AuthorityAuthorizationManager<T> hasAnyScope(String... scopes) {
|
||||
String[] mappedScopes = Arrays.stream(scopes).map(s -> "SCOPE_" + s).toArray(String[]::new);
|
||||
return AuthorityAuthorizationManager.hasAnyAuthority(mappedScopes);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue