Class JwtAuthenticationProvider
- All Implemented Interfaces:
AuthenticationProvider
AuthenticationProvider implementation of the Jwt-encoded
Bearer
Tokens for protecting OAuth 2.0 Resource Servers.
This AuthenticationProvider is responsible for decoding and verifying a
Jwt-encoded access token, returning its claims set as part of the
Authentication statement.
Scopes are translated into GrantedAuthoritys according to the following
algorithm:
1. If there is a "scope" or "scp" attribute, then if a String, then split by
spaces and return, or if a Collection, then simply return 2. Take the resulting
Collection of Strings and prepend the "SCOPE_" keyword, adding as
GrantedAuthoritys.
- Since:
- 5.1
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionauthenticate(Authentication authentication) Decode and validate the Bearer Token.voidsetJwtAuthenticationConverter(org.springframework.core.convert.converter.Converter<Jwt, ? extends AbstractAuthenticationToken> jwtAuthenticationConverter) booleanReturnstrueif thisAuthenticationProvidersupports the indicatedAuthenticationobject.
-
Constructor Details
-
JwtAuthenticationProvider
-
-
Method Details
-
authenticate
Decode and validate the Bearer Token.- Specified by:
authenticatein interfaceAuthenticationProvider- Parameters:
authentication- the authentication request object.- Returns:
- A successful authentication
- Throws:
AuthenticationException- if authentication failed for some reason
-
supports
Description copied from interface:AuthenticationProviderReturnstrueif thisAuthenticationProvidersupports the indicatedAuthenticationobject.Returning
truedoes not guarantee anAuthenticationProviderwill be able to authenticate the presentedAuthenticationobject. It simply indicates it can support closer evaluation of it. AnAuthenticationProvidercan still returnnullfrom theAuthenticationProvider.authenticate(Authentication)method to indicate anotherAuthenticationProvidershould be tried.Selection of an
AuthenticationProvidercapable of performing authentication is conducted at runtime theProviderManager.- Specified by:
supportsin interfaceAuthenticationProvider- Returns:
trueif the implementation can more closely evaluate theAuthenticationclass presented
-
setJwtAuthenticationConverter
public void setJwtAuthenticationConverter(org.springframework.core.convert.converter.Converter<Jwt, ? extends AbstractAuthenticationToken> jwtAuthenticationConverter)
-