@Override
  public void saveRequest(final HttpServletRequest request, final HttpServletResponse response) {
    // this might be called while in ExceptionTranslationFilter#handleSpringSecurityException in
    // this case base implementation
    if (SecurityContextHolder.getContext().getAuthentication() == null) {
      super.saveRequest(request, response);
    } else {
      final SavedRequest savedBefore = getRequest(request, response);
      if (savedBefore != null) // to not override request saved by
      // ExceptionTranslationFilter#handleSpringSecurityException
      {
        return;
      }

      if (getRequestMatcher().matches(request)) {
        final DefaultSavedRequest savedRequest =
            new DefaultSavedRequest(request, getPortResolver()) {
              private final String referer = request.getHeader(REFERER);
              private final String contextPath = request.getContextPath();

              @Override
              public String getRedirectUrl() {
                return calculateRelativeRedirectUrl(contextPath, referer);
              }
            };

        if (isCreateSessionAllowed() || request.getSession(false) != null) {
          request.getSession().setAttribute(SAVED_REQUEST, savedRequest);
          logger.debug("DefaultSavedRequest added to Session: " + savedRequest);
        }
      } else {
        logger.debug("Request not saved as configured RequestMatcher did not match");
      }
    }
  }
 @Override
 public void setPortResolver(final PortResolver portResolver) {
   this.portResolver = portResolver;
   super.setPortResolver(portResolver);
 }
 @Override
 public void setRequestMatcher(final RequestMatcher requestMatcher) {
   this.requestMatcher = requestMatcher;
   super.setRequestMatcher(requestMatcher);
 }