use of org.apereo.cas.pm.InvalidPasswordException in project cas by apereo.
the class PasswordChangeAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
try {
final UsernamePasswordCredential c = (UsernamePasswordCredential) WebUtils.getCredential(requestContext);
final PasswordChangeBean bean = requestContext.getFlowScope().get(PasswordManagementWebflowConfigurer.FLOW_VAR_ID_PASSWORD, PasswordChangeBean.class);
if (!passwordValidationService.isValid(c, bean)) {
return getErrorEvent(requestContext, PASSWORD_VALIDATION_FAILURE_CODE, DEFAULT_MESSAGE);
}
if (passwordManagementService.change(c, bean)) {
WebUtils.putCredential(requestContext, new UsernamePasswordCredential(c.getUsername(), bean.getPassword()));
return new EventFactorySupport().event(this, PASSWORD_UPDATE_SUCCESS);
}
} catch (final InvalidPasswordException e) {
return getErrorEvent(requestContext, PASSWORD_VALIDATION_FAILURE_CODE + StringUtils.defaultIfBlank(e.getCode(), ""), StringUtils.defaultIfBlank(e.getValidationMessage(), DEFAULT_MESSAGE), e.getParams());
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return getErrorEvent(requestContext, "pm.updateFailure", DEFAULT_MESSAGE);
}
Aggregations