ForcePasswordChangeController { @RequestMapping(value = "/force_password_change", method = POST) public String handleForcePasswordChange(Model model, @RequestParam("password") String password, @RequestParam("password_confirmation") String passwordConfirmation, HttpServletRequest request, HttpServletResponse response, HttpSession httpSession) { SecurityContext securityContext = SecurityContextHolder.getContext(); UaaAuthentication authentication = ((UaaAuthentication) securityContext.getAuthentication()); UaaPrincipal principal = authentication.getPrincipal(); String email = principal.getEmail(); PasswordConfirmationValidation validation = new PasswordConfirmationValidation(email, password, passwordConfirmation); if (!validation.valid()) { return handleUnprocessableEntity(model, response, email, resourcePropertySource.getProperty("force_password_change.form_error").toString()); } logger.debug("Processing handleForcePasswordChange for user: " + email); try { resetPasswordService.resetUserPassword(principal.getId(), password); } catch (InvalidPasswordException exception) { return handleUnprocessableEntity(model, response, email, exception.getMessagesAsOneString()); } logger.debug(String.format("Successful password change for username:%s in zone:%s ", principal.getName(), IdentityZoneHolder.get().getId())); SessionUtils.setPasswordChangeRequired(httpSession, false); authentication.setAuthenticatedTime(System.currentTimeMillis()); SessionUtils.setSecurityContext(request.getSession(), SecurityContextHolder.getContext()); return "redirect:/force_password_change_completed"; } ForcePasswordChangeController(
            final ResourcePropertySource resourcePropertySource,
            final @Qualifier("resetPasswordService") ResetPasswordService resetPasswordService); @RequestMapping(value = "/force_password_change", method = GET) String forcePasswordChangePage(Model model); @RequestMapping(value = "/force_password_change", method = POST) String handleForcePasswordChange(Model model,
                                            @RequestParam("password") String password,
                                            @RequestParam("password_confirmation") String passwordConfirmation,
                                            HttpServletRequest request,
                                            HttpServletResponse response, HttpSession httpSession);  }
@Test void handleForcePasswordChange() throws Exception { mockMvc.perform( post("/uaa/force_password_change") .param("password", "pwd") .param("password_confirmation", "pwd") .contextPath("/uaa")) .andExpect(status().isFound()) .andExpect(redirectedUrl("/uaa/force_password_change_completed")); verify(mockUaaAuthentication, times(1)).setAuthenticatedTime(anyLong()); }