Class DefaultIntrospectionProcessor<T>
java.lang.Object
io.micronaut.security.endpoints.introspection.DefaultIntrospectionProcessor<T>
- Type Parameters:
T- Request
- All Implemented Interfaces:
IntrospectionProcessor<T>
@Singleton
public class DefaultIntrospectionProcessor<T>
extends Object
implements IntrospectionProcessor<T>
Validates the
IntrospectionRequest.getToken() with the available TokenValidator.
Then it creates a IntrospectionResponse with the first Authentication object.
If no TokenValidator is able to validate the token, it tries with RefreshTokenValidator.
If it cannot authenticate it returns {active: false}- Since:
- 2.1.0
- Author:
- Sergio del Amo
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected static final org.slf4j.Loggerstatic final Stringprotected final RefreshTokenValidatorstatic final Stringstatic final Stringstatic final Stringprotected final TokenConfigurationprotected final Collection<TokenValidator<T>>static final String -
Constructor Summary
ConstructorsConstructorDescriptionDefaultIntrospectionProcessor(Collection<TokenValidator<T>> tokenValidators, TokenConfiguration tokenConfiguration, @Nullable RefreshTokenValidator refreshTokenValidator) -
Method Summary
Modifier and TypeMethodDescription@NonNull IntrospectionResponsecreateIntrospectionResponse(@NonNull Authentication authentication, T requestContext) Creates anIntrospectionResponsefor anAuthentication.protected @NonNull IntrospectionResponseemptyIntrospectionResponse(@NonNull String token) Empty response for introspection response.@NonNull org.reactivestreams.Publisher<IntrospectionResponse>introspect(@NonNull Authentication authentication, T requestContext) @NonNull org.reactivestreams.Publisher<IntrospectionResponse>introspect(@NonNull IntrospectionRequest introspectionRequest, T requestContext) resolveAud(@NonNull Authentication authentication) Populates the introspection response with aud claim.resolveClientId(@NonNull Authentication authentication) Populates the introspection response client_id.resolveExpiration(@NonNull Authentication authentication) Populates the introspection response with the exp claim of authentication.resolveExtensions(@NonNull Authentication authentication) resolveIssuedAt(@NonNull Authentication authentication) Populates the introspection response with the iat claim of authentication.resolveIssuer(@NonNull Authentication authentication) Populates the introspection response with iss claim.resolveJwtId(@NonNull Authentication authentication) Populates the introspection response with jti username.resolveNotBefore(@NonNull Authentication authentication) Populates the introspection response with the nbf claim of authentication.resolveScope(@NonNull Authentication authentication) Populates the introspection response scope.protected @NonNull StringresolveSub(@NonNull Authentication authentication) Populates the introspection response with sub claim.resolveTokenType(@NonNull Authentication authentication) Populates the introspection response token type.resolveUsername(@NonNull Authentication authentication) Populates the introspection response with the username.secondsSinceEpochOfAttribute(@NonNull String attributeName, @NonNull Authentication authentication) static longtoSecondsSinceEpoch(Date date)
-
Field Details
-
CLIENT_ID
- See Also:
-
USERNAME
- See Also:
-
TOKEN_TYPE
- See Also:
-
ISSUER
- See Also:
-
SUBJECT
- See Also:
-
EXP
- See Also:
-
NOT_BEFORE
- See Also:
-
ISSUED_AT
- See Also:
-
JWT_ID
- See Also:
-
AUDIENCE
- See Also:
-
SCOPE
- See Also:
-
FIELDS_ATTRIBUTE_NAMES
-
LOG
protected static final org.slf4j.Logger LOG -
tokenValidators
-
tokenConfiguration
-
refreshTokenValidator
-
-
Constructor Details
-
DefaultIntrospectionProcessor
public DefaultIntrospectionProcessor(Collection<TokenValidator<T>> tokenValidators, TokenConfiguration tokenConfiguration, @Nullable @Nullable RefreshTokenValidator refreshTokenValidator)
-
-
Method Details
-
introspect
@NonNull public @NonNull org.reactivestreams.Publisher<IntrospectionResponse> introspect(@NonNull @NonNull IntrospectionRequest introspectionRequest, @NonNull T requestContext) - Specified by:
introspectin interfaceIntrospectionProcessor<T>- Parameters:
introspectionRequest- A parameter representing the token along with optional parameters representing additional contextrequestContext- HTTP Request- Returns:
- Introspection Response
-
emptyIntrospectionResponse
@NonNull protected @NonNull IntrospectionResponse emptyIntrospectionResponse(@NonNull @NonNull String token) Empty response for introspection response.- Parameters:
token- Token- Returns:
- Introspection Response
-
introspect
@NonNull public @NonNull org.reactivestreams.Publisher<IntrospectionResponse> introspect(@NonNull @NonNull Authentication authentication, @NonNull T requestContext) - Specified by:
introspectin interfaceIntrospectionProcessor<T>- Parameters:
authentication- The authenticationrequestContext- HTTP Request- Returns:
- Introspection Response
-
createIntrospectionResponse
@NonNull public @NonNull IntrospectionResponse createIntrospectionResponse(@NonNull @NonNull Authentication authentication, @NonNull T requestContext) Creates anIntrospectionResponsefor anAuthentication.- Parameters:
authentication- AuthenticationrequestContext- HTTP Request- Returns:
- an
IntrospectionResponse
-
resolveExtensions
@NonNull protected @NonNull Map<String,Object> resolveExtensions(@NonNull @NonNull Authentication authentication) - Parameters:
authentication- Authentication- Returns:
- Introspection response extensions
-
resolveScope
Populates the introspection response scope.- Parameters:
authentication- Authentication- Returns:
- the scope
-
resolveTokenType
@NonNull protected @NonNull Optional<String> resolveTokenType(@NonNull @NonNull Authentication authentication) Populates the introspection response token type.- Parameters:
authentication- Authentication- Returns:
- the Token type
-
resolveClientId
@NonNull protected @NonNull Optional<String> resolveClientId(@NonNull @NonNull Authentication authentication) Populates the introspection response client_id.- Parameters:
authentication- Authentication- Returns:
- client_id value
-
resolveAud
@NonNull protected @NonNull Optional<String> resolveAud(@NonNull @NonNull Authentication authentication) Populates the introspection response with aud claim.- Parameters:
authentication- Authentication- Returns:
- value of aud claim
-
resolveSub
Populates the introspection response with sub claim.- Parameters:
authentication- Authentication- Returns:
- value of sub claim
-
resolveIssuer
@NonNull protected @NonNull Optional<String> resolveIssuer(@NonNull @NonNull Authentication authentication) Populates the introspection response with iss claim.- Parameters:
authentication- Authentication- Returns:
- value of iss claim
-
resolveJwtId
@NonNull protected @NonNull Optional<String> resolveJwtId(@NonNull @NonNull Authentication authentication) Populates the introspection response with jti username.- Parameters:
authentication- Authentication- Returns:
- the jti claim value
-
resolveUsername
@NonNull protected @NonNull Optional<String> resolveUsername(@NonNull @NonNull Authentication authentication) Populates the introspection response with the username.- Parameters:
authentication- Authentication- Returns:
- the username
-
resolveExpiration
Populates the introspection response with the exp claim of authentication.- Parameters:
authentication- Authentication- Returns:
- the exp claim
-
secondsSinceEpochOfAttribute
protected Optional<Long> secondsSinceEpochOfAttribute(@NonNull @NonNull String attributeName, @NonNull @NonNull Authentication authentication) - Parameters:
attributeName- The attribute name e.g. exp nbf iatauthentication- Authentication- Returns:
- An empty optional if the authentication attribute is not found or it cannot be transformed to epoch seconds
-
resolveNotBefore
@NonNull protected @NonNull Optional<Long> resolveNotBefore(@NonNull @NonNull Authentication authentication) Populates the introspection response with the nbf claim of authentication.- Parameters:
authentication- Authentication- Returns:
- value for nbf claim
-
resolveIssuedAt
@NonNull protected @NonNull Optional<Long> resolveIssuedAt(@NonNull @NonNull Authentication authentication) Populates the introspection response with the iat claim of authentication.- Parameters:
authentication- Authentication- Returns:
- value for iat claim
-
toSecondsSinceEpoch
- Parameters:
date- Date- Returns:
- seconds since epoch
-