Class OAuth2AuthorizationManagers

java.lang.Object
org.springframework.security.oauth2.core.authorization.OAuth2AuthorizationManagers

public final class OAuth2AuthorizationManagers extends Object
A convenience class for creating OAuth 2.0-specific AuthorizationManagers.
Since:
6.2
See Also:
  • Method Details

    • hasScope

      public static <T> AuthorizationManager<T> hasScope(String scope)
      Create an AuthorizationManager that requires an Authentication to have a SCOPE_scope authority.

      For example, if you call hasScope("read"), then this will require that each authentication have a GrantedAuthority whose value is SCOPE_read.

      This would equivalent to calling AuthorityAuthorizationManager#hasAuthority("SCOPE_read").

      Type Parameters:
      T - the secure object
      Parameters:
      scope - the scope value to require
      Returns:
      an AuthorizationManager that requires a "SCOPE_scope" authority
    • hasAnyScope

      public static <T> AuthorizationManager<T> hasAnyScope(String... scopes)
      Create an AuthorizationManager that requires an Authentication to have at least one authority among SCOPE_scope1, SCOPE_scope2, ... SCOPE_scopeN.

      For example, if you call hasAnyScope("read", "write"), then this will require that each authentication have at least a GrantedAuthority whose value is either SCOPE_read or SCOPE_write.

      This would equivalent to calling AuthorityAuthorizationManager#hasAnyAuthority("SCOPE_read", "SCOPE_write").

      Type Parameters:
      T - the secure object
      Parameters:
      scopes - the scope values to allow
      Returns:
      an AuthorizationManager that requires at least one authority among "SCOPE_scope1", SCOPE_scope2, ... SCOPE_scopeN.