Class RequestWardInterceptor

All Implemented Interfaces:
org.springframework.web.servlet.AsyncHandlerInterceptor, org.springframework.web.servlet.HandlerInterceptor

@ControllerAdvice(annotations=com.blueriq.component.api.annotation.ServerContext.class) public class RequestWardInterceptor extends AbstractSessionAwareInterceptor
This interceptor checks for the presence and validity of request wards for requests that may modify an AquimaSession.

The following rules apply:

  • A request must be of type POST, PUT, PATCH or DELETE in order to be considered as potentially modifying a session.
  • The request must target a controller method that has a parameter annotated with AquimaSessionId.
  • If the controller method is annotated with RequestWard.validate() = false, verification is skipped
  • A modification request for a session will always generate a new request ward and send it in the response headers, even if request ward verification is skipped for that controller method

The X-Request-Ward header is used both for sending the request ward from the back-end to the front-end (in the response) and from the front-end to the back-end (in the request). For multipart requests, the front-end may also send the request ward as a request parameter named X-Request-Ward. This exception is made because not all front-ends support adding headers to multipart requests (eg. when what should be an AJAX file upload is simulated with a form inside a hidden iframe on older browsers).

If request ward verification fails, this interceptor will send an HTTP 400 Bad Request response and the targeted controller method will no longer be called. The error response body also contains a JsonError with JsonError.getErrorType() = ErrorType.INVALID_REQUEST_WARD. A failed request ward verification typically indicates that the session state is desynchronized between the front-end and the back-end. In this case, the front-end should refresh the state (e.g. the user should refresh the page). The title and message in the JsonError are internationalized. The message keys are:

Since:
11.0
Author:
Petru Galanton
  • Field Details Link icon

    • REQUEST_WARD_HEADER Link icon

      public static final String REQUEST_WARD_HEADER
      The name of the header checked by this interceptor for the presence and correctness of the request ward.
      See Also:
    • INVALID_TITLE_KEY Link icon

      public static final String INVALID_TITLE_KEY
      The message key for the error message title.
      See Also:
    • INVALID_MESSAGE_KEY Link icon

      public static final String INVALID_MESSAGE_KEY
      The message key for the error message itself.
      See Also:
  • Constructor Details Link icon

    • RequestWardInterceptor Link icon

      public RequestWardInterceptor(com.blueriq.component.api.IAquimaSessionsMap sessionManager, org.springframework.web.multipart.MultipartResolver multipartResolver, BlueriqSessionProperties properties)
  • Method Details Link icon