use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class PasswordChangeAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
try {
val creds = Objects.requireNonNull(WebUtils.getCredential(requestContext, UsernamePasswordCredential.class));
val bean = getPasswordChangeRequest(requestContext);
LOGGER.debug("Attempting to validate the password change bean for username [{}]", creds.getUsername());
if (!passwordValidationService.isValid(creds, bean)) {
LOGGER.error("Failed to validate the provided password");
return getErrorEvent(requestContext, PASSWORD_VALIDATION_FAILURE_CODE, DEFAULT_MESSAGE);
}
if (passwordManagementService.change(creds, bean)) {
WebUtils.putCredential(requestContext, new UsernamePasswordCredential(creds.getUsername(), bean.getPassword()));
LOGGER.info("Password successfully changed for [{}]", bean.getUsername());
return getSuccessEvent(requestContext, bean);
}
} catch (final InvalidPasswordException e) {
return getErrorEvent(requestContext, PASSWORD_VALIDATION_FAILURE_CODE + StringUtils.defaultIfBlank(e.getCode(), StringUtils.EMPTY), StringUtils.defaultIfBlank(e.getValidationMessage(), DEFAULT_MESSAGE), e.getParams());
} catch (final Exception e) {
LoggingUtils.error(LOGGER, e);
}
return getErrorEvent(requestContext, "pm.updateFailure", DEFAULT_MESSAGE);
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class InitPasswordResetAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) {
val token = PasswordManagementWebflowUtils.getPasswordResetToken(requestContext);
if (StringUtils.isBlank(token)) {
LOGGER.error("Password reset token is missing");
return error();
}
val username = passwordManagementService.parseToken(token);
if (StringUtils.isBlank(username)) {
LOGGER.error("Password reset token could not be verified to determine username");
return error();
}
val c = new UsernamePasswordCredential();
c.setUsername(username);
WebUtils.putCredential(requestContext, c);
return success();
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class ADPasswordManagementServiceTests method verifyPasswordReset.
@Test
public void verifyPasswordReset() {
val credential = new UsernamePasswordCredential("changepassword", StringUtils.EMPTY);
val bean = new PasswordChangeRequest();
bean.setConfirmedPassword("P@ssw0rdMellon");
bean.setPassword("P@ssw0rdMellon");
bean.setUsername(credential.getUsername());
assertTrue(passwordChangeService.change(credential, bean));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class ADPasswordManagementServiceTests method verifyPasswordChange.
@Test
public void verifyPasswordChange() {
val credential = new UsernamePasswordCredential("changepasswordnoreset", "P@ssw0rd");
val bean = new PasswordChangeRequest();
bean.setConfirmedPassword("P@ssw0rd2");
bean.setPassword("P@ssw0rd2");
bean.setUsername(credential.getUsername());
assertTrue(passwordChangeService.change(credential, bean));
}
use of org.apereo.cas.authentication.credential.UsernamePasswordCredential in project cas by apereo.
the class JsonResourcePasswordManagementService method changeInternal.
@Override
public boolean changeInternal(@NonNull final Credential credential, @NonNull final PasswordChangeRequest bean) {
val c = (UsernamePasswordCredential) credential;
if (StringUtils.isBlank(bean.getPassword())) {
LOGGER.error("Password cannot be blank");
return false;
}
if (!StringUtils.equals(bean.getPassword(), bean.getConfirmedPassword())) {
LOGGER.error("Password does not match and cannot be confirmed");
return false;
}
val account = this.jsonBackedAccounts.getOrDefault(c.getId(), null);
if (account == null) {
LOGGER.error("User account [{}] cannot be found", c.getId());
return false;
}
account.setPassword(bean.getPassword());
this.jsonBackedAccounts.put(c.getId(), account);
return writeAccountToJsonResource();
}
Aggregations