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);
}
}
}
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());
}
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);
}
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);
}
Aggregations