@Test public void testOkWithSavedGET() throws ServletException, IOException { when(requestCache.getRequest(req, resp)).thenReturn(savedRequest); RedirectStrategy redirectStrategy = mock(RedirectStrategy.class); testee.setRedirectStrategy(redirectStrategy); testee.onAuthenticationSuccess(req, resp, auth); verify(redirectStrategy, times(1)).sendRedirect(any(HttpServletRequest.class), any(HttpServletResponse.class), eq(URL)); }
@Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { SavedRequest savedRequest = requestCache.getRequest(request, response); if (savedRequest == null) { super.onAuthenticationSuccess(request, response, authentication); return; } String targetUrlParameter = getTargetUrlParameter(); if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request .getParameter(targetUrlParameter)))) { requestCache.removeRequest(request, response); super.onAuthenticationSuccess(request, response, authentication); return; } clearAuthenticationAttributes(request); String targetUrl = savedRequest.getRedirectUrl(); String targetUri = ((DefaultSavedRequest) savedRequest).getRequestURI(); if (savedRequest.getMethod().equalsIgnoreCase(HttpMethod.POST.name()) && djupintegrationPattern.matcher(targetUri).matches()) { WebCertUser webCertUser = (WebCertUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (webCertUser == null) { throw new IllegalStateException("No user principal, cannot bind integration params."); } if (webCertUser.getParameters() != null) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "This user session is already active and using Webcert. " + "Please use a new user session for each deep integration link."); } IntegrationParameters integrationParameters = IntegrationParameters.of( fromSavedReq(savedRequest, IntygIntegrationController.PARAM_REFERENCE), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_RESPONSIBLE_HOSP_NAME), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_ALTERNATE_SSN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_FORNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_MELLANNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_EFTERNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTADRESS), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTNUMMER), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTORT), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_COHERENT_JOURNALING), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_PATIENT_DECEASED), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_INACTIVE_UNIT), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_FORNYA_OK, true)); webCertUser.setParameters(integrationParameters); targetUrl = targetUrl + "/saved"; if (savedRequest.getParameterMap().containsKey(PARAM_ENHET_ID)) { targetUrl = targetUrl + "?" + PARAM_ENHET_ID + "=" + fromSavedReq(savedRequest, PARAM_ENHET_ID); } } logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl); getRedirectStrategy().sendRedirect(request, response, targetUrl); }
WebcertAuthenticationSuccessHandler extends
    SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { SavedRequest savedRequest = requestCache.getRequest(request, response); if (savedRequest == null) { super.onAuthenticationSuccess(request, response, authentication); return; } String targetUrlParameter = getTargetUrlParameter(); if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request .getParameter(targetUrlParameter)))) { requestCache.removeRequest(request, response); super.onAuthenticationSuccess(request, response, authentication); return; } clearAuthenticationAttributes(request); String targetUrl = savedRequest.getRedirectUrl(); String targetUri = ((DefaultSavedRequest) savedRequest).getRequestURI(); if (savedRequest.getMethod().equalsIgnoreCase(HttpMethod.POST.name()) && djupintegrationPattern.matcher(targetUri).matches()) { WebCertUser webCertUser = (WebCertUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (webCertUser == null) { throw new IllegalStateException("No user principal, cannot bind integration params."); } if (webCertUser.getParameters() != null) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "This user session is already active and using Webcert. " + "Please use a new user session for each deep integration link."); } IntegrationParameters integrationParameters = IntegrationParameters.of( fromSavedReq(savedRequest, IntygIntegrationController.PARAM_REFERENCE), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_RESPONSIBLE_HOSP_NAME), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_ALTERNATE_SSN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_FORNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_MELLANNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_EFTERNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTADRESS), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTNUMMER), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTORT), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_COHERENT_JOURNALING), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_PATIENT_DECEASED), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_INACTIVE_UNIT), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_FORNYA_OK, true)); webCertUser.setParameters(integrationParameters); targetUrl = targetUrl + "/saved"; if (savedRequest.getParameterMap().containsKey(PARAM_ENHET_ID)) { targetUrl = targetUrl + "?" + PARAM_ENHET_ID + "=" + fromSavedReq(savedRequest, PARAM_ENHET_ID); } } logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl); getRedirectStrategy().sendRedirect(request, response, targetUrl); } }
WebcertAuthenticationSuccessHandler extends
    SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { SavedRequest savedRequest = requestCache.getRequest(request, response); if (savedRequest == null) { super.onAuthenticationSuccess(request, response, authentication); return; } String targetUrlParameter = getTargetUrlParameter(); if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request .getParameter(targetUrlParameter)))) { requestCache.removeRequest(request, response); super.onAuthenticationSuccess(request, response, authentication); return; } clearAuthenticationAttributes(request); String targetUrl = savedRequest.getRedirectUrl(); String targetUri = ((DefaultSavedRequest) savedRequest).getRequestURI(); if (savedRequest.getMethod().equalsIgnoreCase(HttpMethod.POST.name()) && djupintegrationPattern.matcher(targetUri).matches()) { WebCertUser webCertUser = (WebCertUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (webCertUser == null) { throw new IllegalStateException("No user principal, cannot bind integration params."); } if (webCertUser.getParameters() != null) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "This user session is already active and using Webcert. " + "Please use a new user session for each deep integration link."); } IntegrationParameters integrationParameters = IntegrationParameters.of( fromSavedReq(savedRequest, IntygIntegrationController.PARAM_REFERENCE), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_RESPONSIBLE_HOSP_NAME), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_ALTERNATE_SSN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_FORNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_MELLANNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_EFTERNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTADRESS), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTNUMMER), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTORT), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_COHERENT_JOURNALING), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_PATIENT_DECEASED), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_INACTIVE_UNIT), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_FORNYA_OK, true)); webCertUser.setParameters(integrationParameters); targetUrl = targetUrl + "/saved"; if (savedRequest.getParameterMap().containsKey(PARAM_ENHET_ID)) { targetUrl = targetUrl + "?" + PARAM_ENHET_ID + "=" + fromSavedReq(savedRequest, PARAM_ENHET_ID); } } logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl); getRedirectStrategy().sendRedirect(request, response, targetUrl); }  }
WebcertAuthenticationSuccessHandler extends
    SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { SavedRequest savedRequest = requestCache.getRequest(request, response); if (savedRequest == null) { super.onAuthenticationSuccess(request, response, authentication); return; } String targetUrlParameter = getTargetUrlParameter(); if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request .getParameter(targetUrlParameter)))) { requestCache.removeRequest(request, response); super.onAuthenticationSuccess(request, response, authentication); return; } clearAuthenticationAttributes(request); String targetUrl = savedRequest.getRedirectUrl(); String targetUri = ((DefaultSavedRequest) savedRequest).getRequestURI(); if (savedRequest.getMethod().equalsIgnoreCase(HttpMethod.POST.name()) && djupintegrationPattern.matcher(targetUri).matches()) { WebCertUser webCertUser = (WebCertUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (webCertUser == null) { throw new IllegalStateException("No user principal, cannot bind integration params."); } if (webCertUser.getParameters() != null) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "This user session is already active and using Webcert. " + "Please use a new user session for each deep integration link."); } IntegrationParameters integrationParameters = IntegrationParameters.of( fromSavedReq(savedRequest, IntygIntegrationController.PARAM_REFERENCE), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_RESPONSIBLE_HOSP_NAME), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_ALTERNATE_SSN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_FORNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_MELLANNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_EFTERNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTADRESS), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTNUMMER), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTORT), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_COHERENT_JOURNALING), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_PATIENT_DECEASED), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_INACTIVE_UNIT), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_FORNYA_OK, true)); webCertUser.setParameters(integrationParameters); targetUrl = targetUrl + "/saved"; if (savedRequest.getParameterMap().containsKey(PARAM_ENHET_ID)) { targetUrl = targetUrl + "?" + PARAM_ENHET_ID + "=" + fromSavedReq(savedRequest, PARAM_ENHET_ID); } } logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl); getRedirectStrategy().sendRedirect(request, response, targetUrl); }  @Override void onAuthenticationSuccess(HttpServletRequest request,
        HttpServletResponse response, Authentication authentication); void setRequestCache(RequestCache requestCache); }
WebcertAuthenticationSuccessHandler extends
    SimpleUrlAuthenticationSuccessHandler { @Override public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws ServletException, IOException { SavedRequest savedRequest = requestCache.getRequest(request, response); if (savedRequest == null) { super.onAuthenticationSuccess(request, response, authentication); return; } String targetUrlParameter = getTargetUrlParameter(); if (isAlwaysUseDefaultTargetUrl() || (targetUrlParameter != null && StringUtils.hasText(request .getParameter(targetUrlParameter)))) { requestCache.removeRequest(request, response); super.onAuthenticationSuccess(request, response, authentication); return; } clearAuthenticationAttributes(request); String targetUrl = savedRequest.getRedirectUrl(); String targetUri = ((DefaultSavedRequest) savedRequest).getRequestURI(); if (savedRequest.getMethod().equalsIgnoreCase(HttpMethod.POST.name()) && djupintegrationPattern.matcher(targetUri).matches()) { WebCertUser webCertUser = (WebCertUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (webCertUser == null) { throw new IllegalStateException("No user principal, cannot bind integration params."); } if (webCertUser.getParameters() != null) { throw new WebCertServiceException(WebCertServiceErrorCodeEnum.AUTHORIZATION_PROBLEM, "This user session is already active and using Webcert. " + "Please use a new user session for each deep integration link."); } IntegrationParameters integrationParameters = IntegrationParameters.of( fromSavedReq(savedRequest, IntygIntegrationController.PARAM_REFERENCE), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_RESPONSIBLE_HOSP_NAME), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_ALTERNATE_SSN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_FORNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_MELLANNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_EFTERNAMN), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTADRESS), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTNUMMER), fromSavedReq(savedRequest, IntygIntegrationController.PARAM_PATIENT_POSTORT), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_COHERENT_JOURNALING), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_PATIENT_DECEASED), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_INACTIVE_UNIT), fromSavedReqBoolean(savedRequest, IntygIntegrationController.PARAM_FORNYA_OK, true)); webCertUser.setParameters(integrationParameters); targetUrl = targetUrl + "/saved"; if (savedRequest.getParameterMap().containsKey(PARAM_ENHET_ID)) { targetUrl = targetUrl + "?" + PARAM_ENHET_ID + "=" + fromSavedReq(savedRequest, PARAM_ENHET_ID); } } logger.debug("Redirecting to DefaultSavedRequest Url: " + targetUrl); getRedirectStrategy().sendRedirect(request, response, targetUrl); }  @Override void onAuthenticationSuccess(HttpServletRequest request,
        HttpServletResponse response, Authentication authentication); void setRequestCache(RequestCache requestCache);  }