Search in sources :

Example 1 with InvalidPasswordException

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);
}
Also used : PasswordChangeBean(org.apereo.cas.pm.PasswordChangeBean) InvalidPasswordException(org.apereo.cas.pm.InvalidPasswordException) UsernamePasswordCredential(org.apereo.cas.authentication.UsernamePasswordCredential) EventFactorySupport(org.springframework.webflow.action.EventFactorySupport) InvalidPasswordException(org.apereo.cas.pm.InvalidPasswordException)

Aggregations

UsernamePasswordCredential (org.apereo.cas.authentication.UsernamePasswordCredential)1 InvalidPasswordException (org.apereo.cas.pm.InvalidPasswordException)1 PasswordChangeBean (org.apereo.cas.pm.PasswordChangeBean)1 EventFactorySupport (org.springframework.webflow.action.EventFactorySupport)1