Class OpaqueTokenAuthenticationProvider

  • All Implemented Interfaces:
    org.springframework.security.authentication.AuthenticationProvider

    public final class OpaqueTokenAuthenticationProvider
    extends java.lang.Object
    implements org.springframework.security.authentication.AuthenticationProvider
    An AuthenticationProvider implementation for opaque Bearer Tokens, using an OAuth 2.0 Introspection Endpoint to check the token's validity and reveal its attributes.

    This AuthenticationProvider is responsible for introspecting and verifying an opaque access token, returning its attributes set as part of the Authentication statement.

    Scopes are translated into GrantedAuthoritys according to the following algorithm:

    1. If there is a "scope" attribute, then convert to a Collection of Strings.
    2. Take the resulting Collection and prepend the "SCOPE_" keyword to each element, adding as GrantedAuthoritys.

    An OpaqueTokenIntrospector is responsible for retrieving token attributes from an authorization server.

    An OpaqueTokenAuthenticationConverter is responsible for turning a successful introspection result into an Authentication instance (which may include mapping GrantedAuthoritys from token attributes or retrieving from another source).

    Since:
    5.2
    See Also:
    AuthenticationProvider
    • Constructor Detail

      • OpaqueTokenAuthenticationProvider

        public OpaqueTokenAuthenticationProvider​(OpaqueTokenIntrospector introspector)
        Creates a OpaqueTokenAuthenticationProvider with the provided parameters
        Parameters:
        introspector - The OpaqueTokenIntrospector to use
    • Method Detail

      • authenticate

        public org.springframework.security.core.Authentication authenticate​(org.springframework.security.core.Authentication authentication)
                                                                      throws org.springframework.security.core.AuthenticationException
        Introspect and validate the opaque Bearer Token and then delegates Authentication instantiation to OpaqueTokenAuthenticationConverter.

        If created Authentication is instance of AbstractAuthenticationToken and details are null, then introspection result details are used.

        Specified by:
        authenticate in interface org.springframework.security.authentication.AuthenticationProvider
        Parameters:
        authentication - the authentication request object.
        Returns:
        A successful authentication
        Throws:
        org.springframework.security.core.AuthenticationException - if authentication failed for some reason
      • supports

        public boolean supports​(java.lang.Class<?> authentication)
        Specified by:
        supports in interface org.springframework.security.authentication.AuthenticationProvider
      • setAuthenticationConverter

        public void setAuthenticationConverter​(OpaqueTokenAuthenticationConverter authenticationConverter)
        Provide with a custom bean to turn successful introspection result into an Authentication instance of your choice. By default, BearerTokenAuthentication will be built.
        Parameters:
        authenticationConverter - the converter to use
        Since:
        5.8