use of org.cloudfoundry.identity.uaa.account.PasswordConfirmationValidation.PasswordConfirmationException in project uaa by cloudfoundry.
the class ResetPasswordAuthenticationEntryPoint method commence.
@Override
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
Throwable cause = authException.getCause();
response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
HttpServletRequestWrapper wrapper = new HttpServletRequestWrapper(request) {
@Override
public String getMethod() {
return "GET";
}
@Override
public String getParameter(String name) {
if (name.equals("code")) {
return (String) getAttribute(name);
}
return super.getParameter(name);
}
@Override
public Map<String, String[]> getParameterMap() {
Map<String, String[]> map = super.getParameterMap();
if (map.containsKey("code")) {
Map<String, String[]> newMap = new HashMap<>(map);
newMap.put("code", new String[] { (String) getAttribute("code") });
map = newMap;
}
return map;
}
@Override
public String[] getParameterValues(String name) {
return getParameterMap().get(name);
}
};
if (cause instanceof PasswordConfirmationException) {
PasswordConfirmationException passwordConfirmationException = (PasswordConfirmationException) cause;
request.setAttribute("message_code", passwordConfirmationException.getMessageCode());
request.getRequestDispatcher("/reset_password").forward(wrapper, response);
return;
} else {
if (cause instanceof InvalidPasswordException) {
InvalidPasswordException exception = (InvalidPasswordException) cause;
request.setAttribute("message", exception.getMessagesAsOneString());
request.getRequestDispatcher("/reset_password").forward(wrapper, response);
} else {
request.setAttribute("message_code", "bad_code");
request.getRequestDispatcher("/forgot_password").forward(wrapper, response);
}
}
}
use of org.cloudfoundry.identity.uaa.account.PasswordConfirmationValidation.PasswordConfirmationException in project uaa by cloudfoundry.
the class ResetPasswordAuthenticationFilter method doFilterInternal.
@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String email = request.getParameter("email");
String code = request.getParameter("code");
String password = request.getParameter("password");
String passwordConfirmation = request.getParameter("password_confirmation");
PasswordConfirmationValidation validation = new PasswordConfirmationValidation(email, password, passwordConfirmation);
ExpiringCode expiringCode = null;
try {
expiringCode = expiringCodeStore.retrieveCode(code, IdentityZoneHolder.get().getId());
validation.throwIfNotValid();
if (expiringCode == null) {
throw new InvalidCodeException("invalid_code", "Sorry, your reset password link is no longer valid. Please request a new one", 422);
}
ResetPasswordService.ResetPasswordResponse resetPasswordResponse = service.resetPassword(expiringCode, password);
String redirectUri = resetPasswordResponse.getRedirectUri();
if (!StringUtils.hasText(redirectUri) || redirectUri.equals("home")) {
response.sendRedirect(request.getContextPath() + "/login?success=password_reset");
} else {
response.sendRedirect(request.getContextPath() + "/login?success=password_reset&form_redirect_uri=" + redirectUri);
}
} catch (InvalidPasswordException e) {
refreshCode(request, expiringCode);
entryPoint.commence(request, response, new BadCredentialsException(e.getMessagesAsOneString(), e));
} catch (UaaException e) {
entryPoint.commence(request, response, new InternalAuthenticationServiceException(e.getMessage(), e));
} catch (PasswordConfirmationException pe) {
refreshCode(request, expiringCode);
entryPoint.commence(request, response, new BadCredentialsException("Password did not pass validation.", pe));
}
return;
}
use of org.cloudfoundry.identity.uaa.account.PasswordConfirmationValidation.PasswordConfirmationException in project uaa by cloudfoundry.
the class ResetPasswordAuthenticationEntryPointTests method test_invalid_password_match.
@Test
public void test_invalid_password_match() throws Exception {
PasswordConfirmationException pe = new PasswordConfirmationException(messageCode, email);
BadCredentialsException be = new BadCredentialsException("", pe);
entryPoint.commence(request, response, be);
verify(request, times(1)).getRequestDispatcher(eq("/reset_password"));
verify(request, times(1)).setAttribute(eq("message_code"), eq(messageCode));
verify(requestDispatcher, timeout(1)).forward(any(HttpServletRequest.class), same(response));
verify(response, times(1)).setStatus(eq(HttpStatus.UNPROCESSABLE_ENTITY.value()));
}
use of org.cloudfoundry.identity.uaa.account.PasswordConfirmationValidation.PasswordConfirmationException in project uaa by cloudfoundry.
the class ResetPasswordAuthenticationFilterTest method invalid_password_confirmation.
@Test
public void invalid_password_confirmation() throws Exception {
request.setParameter("password_confirmation", "invalid");
Exception e = error_during_password_reset(PasswordConfirmationException.class);
assertTrue(e instanceof AuthenticationException);
assertNotNull(e.getCause());
assertTrue(e.getCause() instanceof PasswordConfirmationException);
PasswordConfirmationException pe = (PasswordConfirmationException) e.getCause();
assertEquals("form_error", pe.getMessageCode());
assertEquals(email, pe.getEmail());
}
Aggregations