Class NimbusResponseEncoder

All Implemented Interfaces:
Component, DestructableComponent, InitializableComponent, UnmodifiableComponent, MessageEncoder, HttpServletResponseMessageEncoder

public class NimbusResponseEncoder extends AbstractHttpServletResponseMessageEncoder
A message encodes that encodes the Nimbus Response in the message context inside the attached HttpServletResponse. All the other headers found from the Response except
Location
are included to the HttpServletResponse. The Location header is ignored, but its value is given as the parameter to HttpServletResponse.sendRedirect(String). The response is assumed not to committed before this encoder is used.
  • Field Details

    • log

      @Nonnull private final org.slf4j.Logger log
      Class logger.
    • DEFAULT_TEMPLATE_ID

      @Nonnull @NotEmpty public static final String DEFAULT_TEMPLATE_ID
      Default template ID for using FORM POST response mode.
      See Also:
    • velocityEngine

      @Nullable private org.apache.velocity.app.VelocityEngine velocityEngine
      Velocity engine used to evaluate the template when using FORM POST response mode.
    • velocityTemplateId

      @Nonnull @NotEmpty private String velocityTemplateId
      ID of the Velocity template used when using FORM POST response mode.
    • objectMapper

      @NonnullAfterInit private com.fasterxml.jackson.databind.ObjectMapper objectMapper
      Object mapper used for pretty-printing JSON response.
    • cspDigester

      @Nullable private StringDigester cspDigester
      CSP digester for generating CSP hashes.
    • cspNonceGenerator

      @Nullable private IdentifierGenerationStrategy cspNonceGenerator
      CSP nonce generator.
  • Constructor Details

    • NimbusResponseEncoder

      public NimbusResponseEncoder()
      Constructor.
  • Method Details

    • setVelocityTemplateId

      public void setVelocityTemplateId(String newVelocityTemplateId)
      Set the Velocity template id.

      Defaults to DEFAULT_TEMPLATE_ID.

      Parameters:
      newVelocityTemplateId - the new Velocity template id
    • setVelocityEngine

      public void setVelocityEngine(org.apache.velocity.app.VelocityEngine newVelocityEngine)
      Set the VelocityEngine instance.
      Parameters:
      newVelocityEngine - the new VelocityEngine instane
    • setObjectMapper

      public void setObjectMapper(@Nonnull com.fasterxml.jackson.databind.ObjectMapper mapper)
      Set the object mapper used for pretty-printing JSON in the request.
      Parameters:
      mapper - What to set.
      Since:
      4.1.0
    • setCSPDigester

      public void setCSPDigester(@Nullable StringDigester digester)
      Sets a StringDigester to use in computing CSP digests in views.
      Parameters:
      digester - digester to set
      Since:
      4.1.0
    • setCSPNonceGenerator

      public void setCSPNonceGenerator(@Nullable IdentifierGenerationStrategy strategy)
      Sets an IdentifierGenerationStrategy to use in computing CSP nonces in views.
      Parameters:
      strategy - nonce strategy
      Since:
      4.1.0
    • impliesFormPost

      private boolean impliesFormPost(@Nullable Object response)
      Whether we should use FORM POST response encoding.
      Parameters:
      response - response message.
      Returns:
      true if DORM POST should be used.
    • doPostEncode

      private org.apache.velocity.VelocityContext doPostEncode(@Nonnull AuthorizationResponse message)
      Set response message to FORM POST velocity context.
      Parameters:
      message - response message.
      Returns:
      response message as velocity context.
    • doEncode

      protected void doEncode() throws MessageEncodingException
      Specified by:
      doEncode in class AbstractMessageEncoder
      Throws:
      MessageEncodingException
    • processHeaders

      @Nullable protected String processHeaders(@Nullable Map<String,List<String>> headers, @Nonnull HttpServletResponse response)
      Adds all the other given headers to the given HttpServletResponse except the location header, whose first value is returned by this method if any value exists.
      Parameters:
      headers - the headers to be added to the servlet response
      response - the servlet response for which the headers are populated
      Returns:
      the first value of Location header, if any value existed in the given map of headers
    • serializeMessageForLogging

      @Nullable protected String serializeMessageForLogging(@Nullable Object message)
      Overrides:
      serializeMessageForLogging in class AbstractMessageEncoder