diff --git a/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/ScopeAuthorizationManagerFactory.java b/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/ScopeAuthorizationManagerFactory.java new file mode 100644 index 0000000000..c9e9fa0fcd --- /dev/null +++ b/oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/ScopeAuthorizationManagerFactory.java @@ -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 AuthorityAuthorizationManager hasScope(String scope) { + return AuthorityAuthorizationManager.hasAuthority("SCOPE_" + scope); + } + + public static AuthorityAuthorizationManager hasAnyScope(String... scopes) { + String[] mappedScopes = Arrays.stream(scopes).map(s -> "SCOPE_" + s).toArray(String[]::new); + return AuthorityAuthorizationManager.hasAnyAuthority(mappedScopes); + } +}