Class OpaqueTokenAuthenticationProvider
java.lang.Object
org.springframework.security.oauth2.server.resource.authentication.OpaqueTokenAuthenticationProvider
- All Implemented Interfaces:
org.springframework.security.authentication.AuthenticationProvider
public final class OpaqueTokenAuthenticationProvider
extends 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:
- If there is a "scope" attribute, then convert to a
CollectionofStrings. - Take the resulting
Collectionand prepend the "SCOPE_" keyword to each element, adding asGrantedAuthoritys.
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 Summary
ConstructorsConstructorDescriptionOpaqueTokenAuthenticationProvider(OpaqueTokenIntrospector introspector) Creates aOpaqueTokenAuthenticationProviderwith the provided parameters -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.core.Authenticationauthenticate(org.springframework.security.core.Authentication authentication) Introspect and validate the opaque Bearer Token and then delegatesAuthenticationinstantiation toOpaqueTokenAuthenticationConverter.voidsetAuthenticationConverter(OpaqueTokenAuthenticationConverter authenticationConverter) Provide with a custom bean to turn successful introspection result into anAuthenticationinstance of your choice.boolean
-
Constructor Details
-
OpaqueTokenAuthenticationProvider
Creates aOpaqueTokenAuthenticationProviderwith the provided parameters- Parameters:
introspector- TheOpaqueTokenIntrospectorto use
-
-
Method Details
-
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 delegatesAuthenticationinstantiation toOpaqueTokenAuthenticationConverter.If created Authentication is instance of
AbstractAuthenticationTokenand details are null, then introspection result details are used.- Specified by:
authenticatein interfaceorg.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
- Specified by:
supportsin interfaceorg.springframework.security.authentication.AuthenticationProvider
-
setAuthenticationConverter
Provide with a custom bean to turn successful introspection result into anAuthenticationinstance of your choice. By default,BearerTokenAuthenticationwill be built.- Parameters:
authenticationConverter- the converter to use- Since:
- 5.8
-