Search in sources :

Example 6 with RedirectAttributes

use of org.springframework.web.servlet.mvc.support.RedirectAttributes in project spring-framework by spring-projects.

the class HttpEntityMethodProcessor method saveFlashAttributes.

private void saveFlashAttributes(ModelAndViewContainer mav, NativeWebRequest request, String location) {
    mav.setRedirectModelScenario(true);
    ModelMap model = mav.getModel();
    if (model instanceof RedirectAttributes) {
        Map<String, ?> flashAttributes = ((RedirectAttributes) model).getFlashAttributes();
        if (!CollectionUtils.isEmpty(flashAttributes)) {
            HttpServletRequest req = request.getNativeRequest(HttpServletRequest.class);
            HttpServletResponse res = request.getNativeRequest(HttpServletResponse.class);
            RequestContextUtils.getOutputFlashMap(req).putAll(flashAttributes);
            RequestContextUtils.saveOutputFlashMap(location, req, res);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) ModelMap(org.springframework.ui.ModelMap) HttpServletResponse(javax.servlet.http.HttpServletResponse)

Example 7 with RedirectAttributes

use of org.springframework.web.servlet.mvc.support.RedirectAttributes in project ORCID-Source by ORCID.

the class PasswordResetControllerTest method testSubmitConsolidatedPasswordReset.

@Test
public void testSubmitConsolidatedPasswordReset() throws Exception {
    RedirectAttributes redirectAttributes = mock(RedirectAttributes.class);
    BindingResult bindingResult = mock(BindingResult.class);
    OneTimeResetPasswordForm oneTimeResetPasswordForm = new OneTimeResetPasswordForm();
    oneTimeResetPasswordForm.setEncryptedEmail("encrypted string not expired");
    when(encryptionManager.decryptForExternalUse(any(String.class))).thenReturn("email=any@orcid.org&issueDate=2070-05-29T17:04:27");
    when(bindingResult.hasErrors()).thenReturn(true);
    oneTimeResetPasswordForm = passwordResetController.submitPasswordReset(servletRequest, servletResponse, oneTimeResetPasswordForm);
    assertFalse(oneTimeResetPasswordForm.getErrors().isEmpty());
    oneTimeResetPasswordForm.setPassword("Password#123");
    when(bindingResult.hasErrors()).thenReturn(false);
    when(orcidProfileManager.retrieveOrcidProfileByEmail(eq("any@orcid.org"), Matchers.<LoadOptions>any())).thenReturn(orcidWithSecurityQuestion());
    oneTimeResetPasswordForm = passwordResetController.submitPasswordReset(servletRequest, servletResponse, oneTimeResetPasswordForm);
    assertTrue(oneTimeResetPasswordForm.getSuccessRedirectLocation().equals("https://testserver.orcid.org/my-orcid") || oneTimeResetPasswordForm.getSuccessRedirectLocation().equals("https://localhost:8443/orcid-web/my-orcid"));
    verify(redirectAttributes, never()).addFlashAttribute("passwordResetLinkExpired", true);
    when(encryptionManager.decryptForExternalUse(any(String.class))).thenReturn("email=any@orcid.org&issueDate=1970-05-29T17:04:27");
    oneTimeResetPasswordForm = passwordResetController.submitPasswordReset(servletRequest, servletResponse, oneTimeResetPasswordForm);
    assertFalse(oneTimeResetPasswordForm.getErrors().isEmpty());
}
Also used : RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) BindingResult(org.springframework.validation.BindingResult) OneTimeResetPasswordForm(org.orcid.frontend.web.forms.OneTimeResetPasswordForm) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 8 with RedirectAttributes

use of org.springframework.web.servlet.mvc.support.RedirectAttributes in project ORCID-Source by ORCID.

the class PasswordResetControllerTest method testPasswordResetLinkExpired.

@Test
public void testPasswordResetLinkExpired() throws Exception {
    HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    RedirectAttributes redirectAttributes = mock(RedirectAttributes.class);
    when(encryptionManager.decryptForExternalUse(any(String.class))).thenReturn("email=any@orcid.org&issueDate=1970-05-29T17:04:27");
    ModelAndView modelAndView = passwordResetController.resetPasswordEmail(servletRequest, "randomString", redirectAttributes);
    assertEquals("redirect:/reset-password?expired=true", modelAndView.getViewName());
    verify(redirectAttributes, times(1)).addFlashAttribute("passwordResetLinkExpired", true);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) ModelAndView(org.springframework.web.servlet.ModelAndView) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Example 9 with RedirectAttributes

use of org.springframework.web.servlet.mvc.support.RedirectAttributes in project ORCID-Source by ORCID.

the class PasswordResetControllerTest method testPasswordResetLinkValidLinkDirectsToSecurityQuestionScreenWhenSecurityQuestionPresent.

@Test
public void testPasswordResetLinkValidLinkDirectsToSecurityQuestionScreenWhenSecurityQuestionPresent() throws Exception {
    HttpServletRequest servletRequest = mock(HttpServletRequest.class);
    RedirectAttributes redirectAttributes = mock(RedirectAttributes.class);
    when(encryptionManager.decryptForExternalUse(any(String.class))).thenReturn("email=any@orcid.org&issueDate=2070-05-29T17:04:27");
    when(orcidProfileManager.retrieveOrcidProfileByEmail(eq("any@orcid.org"), Matchers.<LoadOptions>any())).thenReturn(orcidWithSecurityQuestion());
    ModelAndView modelAndView = passwordResetController.resetPasswordEmail(servletRequest, "randomString", redirectAttributes);
    assertEquals("password_one_time_reset_optional_security_questions", modelAndView.getViewName());
    verify(redirectAttributes, never()).addFlashAttribute("passwordResetLinkExpired", true);
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) HttpServletRequest(javax.servlet.http.HttpServletRequest) RedirectAttributes(org.springframework.web.servlet.mvc.support.RedirectAttributes) ModelAndView(org.springframework.web.servlet.ModelAndView) DBUnitTest(org.orcid.test.DBUnitTest) Test(org.junit.Test)

Aggregations

RedirectAttributes (org.springframework.web.servlet.mvc.support.RedirectAttributes)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)8 ModelAndView (org.springframework.web.servlet.ModelAndView)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 Test (org.junit.Test)3 DBUnitTest (org.orcid.test.DBUnitTest)3 BindingResult (org.springframework.validation.BindingResult)3 GetRequest (com.mashape.unirest.request.GetRequest)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 DateFormat (java.text.DateFormat)2 SimpleDateFormat (java.text.SimpleDateFormat)2 java.util (java.util)2 Valid (javax.validation.Valid)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Qualifier (org.springframework.beans.factory.annotation.Qualifier)2 Value (org.springframework.beans.factory.annotation.Value)2 Sort (org.springframework.data.domain.Sort)2