Class DefaultAccessRefreshTokenGenerator
java.lang.Object
io.micronaut.security.token.generator.DefaultAccessRefreshTokenGenerator
- All Implemented Interfaces:
AccessRefreshTokenGenerator
@Requires(beans={AccessTokenConfiguration.class,TokenRenderer.class,TokenGenerator.class,ClaimsGenerator.class})
@Singleton
public class DefaultAccessRefreshTokenGenerator
extends Object
implements AccessRefreshTokenGenerator
Generates http responses with access and refresh token.
- Since:
- 1.0
- Author:
- Sergio del Amo
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AccessTokenConfiguration
protected final io.micronaut.context.event.ApplicationEventPublisher<AccessTokenGeneratedEvent>
protected final io.micronaut.context.BeanContext
protected final ClaimsGenerator
protected final io.micronaut.context.event.ApplicationEventPublisher<RefreshTokenGeneratedEvent>
protected final RefreshTokenGenerator
protected final TokenGenerator
protected final TokenRenderer
-
Constructor Summary
ConstructorDescriptionDefaultAccessRefreshTokenGenerator
(AccessTokenConfiguration accessTokenConfiguration, TokenRenderer tokenRenderer, TokenGenerator tokenGenerator, io.micronaut.context.BeanContext beanContext, @Nullable RefreshTokenGenerator refreshTokenGenerator, ClaimsGenerator claimsGenerator, io.micronaut.context.event.ApplicationEventPublisher<RefreshTokenGeneratedEvent> refreshTokenGeneratedEventPublisher, io.micronaut.context.event.ApplicationEventPublisher<AccessTokenGeneratedEvent> accessTokenGeneratedEventPublisher) -
Method Summary
Modifier and TypeMethodDescription@NonNull Integer
accessTokenExpiration
(@NonNull Authentication authentication) @NonNull Integer
accessTokenExpiration
(@NonNull Map<String, ?> oldClaims) @NonNull Optional<AccessRefreshToken>
generate
(@NonNull Authentication authentication) Generate anAccessRefreshToken
response for the given user details.@NonNull Optional<AccessRefreshToken>
generate
(@Nullable String refreshToken, @NonNull Authentication authentication) Generate a new access refresh token.@NonNull Optional<AccessRefreshToken>
Generate anAccessRefreshToken
response for the given refresh token and claims.generateRefreshToken
(@NonNull Authentication authentication) Generates a refresh token and emits aRefreshTokenGeneratedEvent
.
-
Field Details
-
beanContext
protected final io.micronaut.context.BeanContext beanContext -
refreshTokenGenerator
-
claimsGenerator
-
accessTokenConfiguration
-
tokenRenderer
-
tokenGenerator
-
refreshTokenGeneratedEventPublisher
protected final io.micronaut.context.event.ApplicationEventPublisher<RefreshTokenGeneratedEvent> refreshTokenGeneratedEventPublisher -
accessTokenGeneratedEventPublisher
protected final io.micronaut.context.event.ApplicationEventPublisher<AccessTokenGeneratedEvent> accessTokenGeneratedEventPublisher
-
-
Constructor Details
-
DefaultAccessRefreshTokenGenerator
public DefaultAccessRefreshTokenGenerator(AccessTokenConfiguration accessTokenConfiguration, TokenRenderer tokenRenderer, TokenGenerator tokenGenerator, io.micronaut.context.BeanContext beanContext, @Nullable @Nullable RefreshTokenGenerator refreshTokenGenerator, ClaimsGenerator claimsGenerator, io.micronaut.context.event.ApplicationEventPublisher<RefreshTokenGeneratedEvent> refreshTokenGeneratedEventPublisher, io.micronaut.context.event.ApplicationEventPublisher<AccessTokenGeneratedEvent> accessTokenGeneratedEventPublisher) - Parameters:
accessTokenConfiguration
- The access token generator configtokenRenderer
- The token renderertokenGenerator
- The token generatorbeanContext
- Bean ContextrefreshTokenGenerator
- The refresh token generatorclaimsGenerator
- Claims generatorrefreshTokenGeneratedEventPublisher
- The Application event publisher forRefreshTokenGeneratedEvent
.accessTokenGeneratedEventPublisher
- The Application event publisher forAccessTokenGeneratedEvent
.
-
-
Method Details
-
generate
@NonNull public @NonNull Optional<AccessRefreshToken> generate(@NonNull @NonNull Authentication authentication) Generate anAccessRefreshToken
response for the given user details.- Specified by:
generate
in interfaceAccessRefreshTokenGenerator
- Parameters:
authentication
- Authenticated user's representation.- Returns:
- The http response
-
generateRefreshToken
@NonNull public @NonNull Optional<String> generateRefreshToken(@NonNull @NonNull Authentication authentication) Generates a refresh token and emits aRefreshTokenGeneratedEvent
.- Specified by:
generateRefreshToken
in interfaceAccessRefreshTokenGenerator
- Parameters:
authentication
- Authenticated user's representation.- Returns:
- Optional#empty() if refresh token was not generated or the refresh token wrapped in an Optional.
-
generate
@NonNull public @NonNull Optional<AccessRefreshToken> generate(@Nullable @Nullable String refreshToken, @NonNull @NonNull Map<String, ?> oldClaims) Generate anAccessRefreshToken
response for the given refresh token and claims.- Specified by:
generate
in interfaceAccessRefreshTokenGenerator
- Parameters:
refreshToken
- The refresh tokenoldClaims
- The claims to generate the access token- Returns:
- The http response
-
generate
@NonNull public @NonNull Optional<AccessRefreshToken> generate(@Nullable @Nullable String refreshToken, @NonNull @NonNull Authentication authentication) Generate a new access refresh token.- Specified by:
generate
in interfaceAccessRefreshTokenGenerator
- Parameters:
refreshToken
- The refresh tokenauthentication
- The user details to create a new access token- Returns:
- The optional access refresh token
-
accessTokenExpiration
@NonNull public @NonNull Integer accessTokenExpiration(@NonNull @NonNull Authentication authentication) - Parameters:
authentication
- User details for which the access token is being generated- Returns:
- expiration of the new access token
-
accessTokenExpiration
- Parameters:
oldClaims
- The old claims used to build the new token- Returns:
- expiration of the new access token
-