Closes #13754 Add hasScope and hasAnyScope for authorization rules

This commit is contained in:
Mario Petrovski 2023-09-01 13:35:17 +02:00 committed by Josh Cummings
parent ab72998b7c
commit 81a708e25f
1 changed files with 18 additions and 0 deletions

View File

@ -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);
}
}