Class RestClientOpaqueTokenIntrospector
java.lang.Object
org.springframework.security.oauth2.server.resource.introspection.RestClientOpaqueTokenIntrospector
- All Implemented Interfaces:
OpaqueTokenIntrospector
public final class RestClientOpaqueTokenIntrospector
extends Object
implements OpaqueTokenIntrospector
A Spring implementation of
OpaqueTokenIntrospector that verifies and
introspects a token using the configured
OAuth 2.0 Introspection
Endpoint, using RestClient for HTTP communication.- Since:
- 7.1
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classUsed to buildRestClientOpaqueTokenIntrospector. -
Constructor Summary
ConstructorsConstructorDescriptionRestClientOpaqueTokenIntrospector(String introspectionUri, org.springframework.web.client.RestClient restClient) Creates aOpaqueTokenAuthenticationProviderwith the provided parameters The givenRestClientshould perform its own client authentication against the introspection endpoint. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipalintrospect(String token) Introspect and verify the given token, returning its attributes.voidsetAuthenticationConverter(org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.core.OAuth2TokenIntrospectionClaimAccessor, ? extends org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal> authenticationConverter) Sets theConverter<OAuth2TokenIntrospectionClaimAccessor, OAuth2AuthenticatedPrincipal>to use.voidsetRequestBodyCustomizer(Consumer<org.springframework.web.client.RestClient.RequestBodySpec> requestBodyCustomizer) Sets theConsumerused to customize the introspection request after the defaults have been applied.withIntrospectionUri(String introspectionUri) Creates aRestClientOpaqueTokenIntrospector.Builderwith the given introspection endpoint uri.
-
Constructor Details
-
RestClientOpaqueTokenIntrospector
public RestClientOpaqueTokenIntrospector(String introspectionUri, org.springframework.web.client.RestClient restClient) Creates aOpaqueTokenAuthenticationProviderwith the provided parameters The givenRestClientshould perform its own client authentication against the introspection endpoint.- Parameters:
introspectionUri- The introspection endpoint urirestClient- The client for performing the introspection request
-
-
Method Details
-
introspect
public org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal introspect(String token) Description copied from interface:OpaqueTokenIntrospectorIntrospect and verify the given token, returning its attributes. Returning aOAuth2AuthenticatedPrincipalis indicative that the token is valid.- Specified by:
introspectin interfaceOpaqueTokenIntrospector- Parameters:
token- the token to introspect- Returns:
- the token's attributes
-
setAuthenticationConverter
public void setAuthenticationConverter(org.springframework.core.convert.converter.Converter<org.springframework.security.oauth2.core.OAuth2TokenIntrospectionClaimAccessor, ? extends org.springframework.security.oauth2.core.OAuth2AuthenticatedPrincipal> authenticationConverter) Sets the
Converter<OAuth2TokenIntrospectionClaimAccessor, OAuth2AuthenticatedPrincipal>to use. Defaults todefaultAuthenticationConverter(OAuth2TokenIntrospectionClaimAccessor).Use if you need a custom mapping of OAuth 2.0 token claims to the authenticated principal.
- Parameters:
authenticationConverter- the converter
-
setRequestBodyCustomizer
public void setRequestBodyCustomizer(Consumer<org.springframework.web.client.RestClient.RequestBodySpec> requestBodyCustomizer) Sets theConsumerused to customize the introspection request after the defaults have been applied. By default, the request is sent asapplication/x-www-form-urlencoded, as required by RFC 7662.Use if you need a different
Content-Typeor additional request settings. The customizer is applied after the request is prepared and before it is sent, so request material set by the customizer takes precedence over the default and over any set on theRestClient.- Parameters:
requestBodyCustomizer- theConsumerto apply to the request- Since:
- 7.2
-
withIntrospectionUri
public static RestClientOpaqueTokenIntrospector.Builder withIntrospectionUri(String introspectionUri) Creates aRestClientOpaqueTokenIntrospector.Builderwith the given introspection endpoint uri.- Parameters:
introspectionUri- The introspection endpoint uri- Returns:
- the
RestClientOpaqueTokenIntrospector.Builder
-