Class LegacyImplicitResponseHandler

java.lang.Object
com.irurueta.authserver.authorization.api.web.implicit.LegacyImplicitResponseHandler
All Implemented Interfaces:
org.springframework.security.web.authentication.AuthenticationSuccessHandler

public class LegacyImplicitResponseHandler extends Object implements org.springframework.security.web.authentication.AuthenticationSuccessHandler
Answers the authorization endpoint: for the two results of the legacy implicit flow it redirects with 302 to the registered redirect URI and carries the token, or the error, in its fragment (so it never reaches a server log as a query would); any other result is the framework's authorization code response and goes to the delegate. The response is never cached and the browser sends no referrer, so the fragment does not leak through the next request.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final String
    Token type reported to the client.
    private final org.springframework.security.web.authentication.AuthenticationSuccessHandler
    Answers the results that are not the legacy flow's.
    (package private) static final String
    Value of Referrer-Policy of the response.
    (package private) static final String
    Value of Cache-Control of the response.
    private static final String
    Name of the Referrer-Policy header.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private static void
    addState(ArrayList<String> parameters, String state)
    Adds the state, when the request had one.
    private static String
    Builds the fragment of a refusal.
    private static long
    expiresIn(org.springframework.security.oauth2.core.OAuth2AccessToken token)
    Computes the lifetime of a token in seconds.
    private static String
    Builds the fragment of a granted request.
    void
    onAuthenticationSuccess(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.Authentication authentication)
    Answers a result.
    private static String
    parameter(String name, String value)
    Encodes one parameter.
    private static void
    redirect(jakarta.servlet.http.HttpServletResponse response, String redirectUri, String fragment)
    Sends the redirect, with the headers that keep the fragment private.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.security.web.authentication.AuthenticationSuccessHandler

    onAuthenticationSuccess
  • Field Details

    • NO_STORE

      static final String NO_STORE
      Value of Cache-Control of the response.
      See Also:
    • NO_REFERRER

      static final String NO_REFERRER
      Value of Referrer-Policy of the response.
      See Also:
    • REFERRER_POLICY

      private static final String REFERRER_POLICY
      Name of the Referrer-Policy header.
      See Also:
    • BEARER

      private static final String BEARER
      Token type reported to the client.
      See Also:
    • delegate

      private final org.springframework.security.web.authentication.AuthenticationSuccessHandler delegate
      Answers the results that are not the legacy flow's.
  • Constructor Details

    • LegacyImplicitResponseHandler

      public LegacyImplicitResponseHandler()
  • Method Details

    • onAuthenticationSuccess

      public void onAuthenticationSuccess(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.security.core.Authentication authentication) throws IOException, jakarta.servlet.ServletException
      Answers a result.
      Specified by:
      onAuthenticationSuccess in interface org.springframework.security.web.authentication.AuthenticationSuccessHandler
      Parameters:
      request - the request.
      response - the response.
      authentication - the result of the authorization request.
      Throws:
      IOException - if the response cannot be written.
      jakarta.servlet.ServletException - if the delegate fails.
    • grantedFragment

      private static String grantedFragment(LegacyImplicitAccessTokenToken granted)
      Builds the fragment of a granted request.
      Parameters:
      granted - the result.
      Returns:
      the encoded fragment.
    • errorFragment

      private static String errorFragment(LegacyImplicitErrorToken refused)
      Builds the fragment of a refusal.
      Parameters:
      refused - the result.
      Returns:
      the encoded fragment.
    • addState

      private static void addState(ArrayList<String> parameters, String state)
      Adds the state, when the request had one.
      Parameters:
      parameters - the encoded parameters.
      state - the state, may be null.
    • parameter

      private static String parameter(String name, String value)
      Encodes one parameter.
      Parameters:
      name - name of the parameter.
      value - value of the parameter.
      Returns:
      name=value, with the value encoded.
    • expiresIn

      private static long expiresIn(org.springframework.security.oauth2.core.OAuth2AccessToken token)
      Computes the lifetime of a token in seconds.
      Parameters:
      token - the token.
      Returns:
      the seconds between its issue and its expiry.
    • redirect

      private static void redirect(jakarta.servlet.http.HttpServletResponse response, String redirectUri, String fragment) throws IOException
      Sends the redirect, with the headers that keep the fragment private.
      Parameters:
      response - the response.
      redirectUri - the registered redirect URI.
      fragment - the encoded fragment.
      Throws:
      IOException - if the response cannot be written.