Class CookieLoginHandler

java.lang.Object
io.micronaut.security.token.cookie.CookieLoginHandler
All Implemented Interfaces:
LoginHandler<io.micronaut.http.HttpRequest<?>,io.micronaut.http.MutableHttpResponse<?>>, RedirectingLoginHandler<io.micronaut.http.HttpRequest<?>,io.micronaut.http.MutableHttpResponse<?>>
Direct Known Subclasses:
IdTokenLoginHandler, TokenCookieLoginHandler

public abstract class CookieLoginHandler extends Object implements RedirectingLoginHandler<io.micronaut.http.HttpRequest<?>,io.micronaut.http.MutableHttpResponse<?>>
Abstract class which defines an implementation of RedirectingLoginHandler where a redirect response is issued. For a successful login a cookie is added to the response with a token.
Since:
2.0.0
Author:
Sergio del Amo
  • Field Details

    • accessTokenCookieConfiguration

      protected final AccessTokenCookieConfiguration accessTokenCookieConfiguration
    • priorToLoginPersistence

      protected final PriorToLoginPersistence<io.micronaut.http.HttpRequest<?>,io.micronaut.http.MutableHttpResponse<?>> priorToLoginPersistence
    • loginFailure

      @Nullable protected final @Nullable String loginFailure
    • loginSuccess

      @Nullable protected final @Nullable String loginSuccess
    • refresh

      @Nullable protected final @Nullable String refresh
  • Constructor Details

    • CookieLoginHandler

      protected CookieLoginHandler(AccessTokenCookieConfiguration accessTokenCookieConfiguration, RedirectConfiguration redirectConfiguration, RedirectService redirectService, @Nullable @Nullable PriorToLoginPersistence priorToLoginPersistence)
      Parameters:
      accessTokenCookieConfiguration - Access token cookie configuration
      redirectConfiguration - Redirect configuration
      redirectService - Redirect service
      priorToLoginPersistence - The prior to login persistence strategy
  • Method Details

    • getCookies

      public abstract List<io.micronaut.http.cookie.Cookie> getCookies(Authentication authentication, io.micronaut.http.HttpRequest<?> request)
      Return the cookies for the given parameters. This method will generate new cookies based on the current configuration.
      Parameters:
      authentication - The Authenticated user's representation
      request - The current request
      Returns:
      A list of cookies
    • getCookies

      public abstract List<io.micronaut.http.cookie.Cookie> getCookies(Authentication authentication, String refreshToken, io.micronaut.http.HttpRequest<?> request)
      Return the cookies for the given parameters. This method will generate new cookies based on the current configuration.
      Parameters:
      authentication - The Authenticated user's representation
      refreshToken - The access refresh token
      request - The current request
      Returns:
      A list of cookies
    • loginSuccess

      public io.micronaut.http.MutableHttpResponse<?> loginSuccess(Authentication authentication, io.micronaut.http.HttpRequest<?> request)
      Specified by:
      loginSuccess in interface LoginHandler<io.micronaut.http.HttpRequest<?>,io.micronaut.http.MutableHttpResponse<?>>
      Parameters:
      authentication - Authenticated user's representation.
      request - The HTTP Request being executed
      Returns:
      An HTTP Response. Eg. a redirect or an JWT token rendered to the response
    • loginFailed

      public io.micronaut.http.MutableHttpResponse<?> loginFailed(AuthenticationResponse authenticationFailed, io.micronaut.http.HttpRequest<?> request)
      Specified by:
      loginFailed in interface LoginHandler<io.micronaut.http.HttpRequest<?>,io.micronaut.http.MutableHttpResponse<?>>
      Parameters:
      authenticationFailed - Object encapsulates the Login failure
      request - The HttpRequest being executed
      Returns:
      A 303 HTTP Response or 401 HTTP Response if loginFailure is null, for example if RedirectConfiguration is disabled.
    • loginRefresh

      public io.micronaut.http.MutableHttpResponse<?> loginRefresh(Authentication authentication, String refreshToken, io.micronaut.http.HttpRequest<?> request)
      Specified by:
      loginRefresh in interface LoginHandler<io.micronaut.http.HttpRequest<?>,io.micronaut.http.MutableHttpResponse<?>>
      Parameters:
      authentication - Authenticated user's representation.
      refreshToken - The refresh token
      request - The HTTP Request being executed
      Returns:
      An HTTP Response. Eg. a redirect or an JWT token rendered to the response
    • createSuccessResponse

      protected io.micronaut.http.MutableHttpResponse<?> createSuccessResponse(io.micronaut.http.HttpRequest<?> request)
      Parameters:
      request - The request
      Returns:
      A 303 HTTP Response or 200 HTTP Response if loginSuccess is null, for example if RedirectConfiguration is disabled.
    • createRefreshResponse

      protected io.micronaut.http.MutableHttpResponse<?> createRefreshResponse(io.micronaut.http.HttpRequest<?> request)
      Parameters:
      request - The request
      Returns:
      A 303 HTTP Response or 200 HTTP Response if refresh is null.
    • applyCookies

      protected io.micronaut.http.MutableHttpResponse<?> applyCookies(io.micronaut.http.MutableHttpResponse<?> response, List<io.micronaut.http.cookie.Cookie> cookies)
      Parameters:
      response - The response
      cookies - Cookies to be added to the response
      Returns:
      A 303 HTTP Response with cookies