use of org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties in project cas by apereo.
the class PasswordManagementConfiguration method passwordManagementCipherExecutor.
@ConditionalOnMissingBean(name = "passwordManagementCipherExecutor")
@RefreshScope
@Bean
public CipherExecutor passwordManagementCipherExecutor() {
final PasswordManagementProperties pm = casProperties.getAuthn().getPm();
final EncryptionJwtSigningJwtCryptographyProperties crypto = pm.getReset().getCrypto();
if (pm.isEnabled() && crypto.isEnabled()) {
return new PasswordResetTokenCipherExecutor(crypto.getEncryption().getKey(), crypto.getSigning().getKey(), crypto.getAlg());
}
return CipherExecutor.noOp();
}
use of org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties in project cas by apereo.
the class NoOpPasswordManagementServiceTests method verifyChange.
@Test
public void verifyChange() {
val properties = new PasswordManagementProperties();
val service = new NoOpPasswordManagementService(CipherExecutor.noOpOfSerializableToString(), "CAS", properties);
assertFalse(service.changeInternal(RegisteredServiceTestUtils.getCredentialsWithSameUsernameAndPassword("casuser"), new PasswordChangeRequest()));
}
use of org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties in project cas by apereo.
the class NoOpPasswordManagementServiceTests method verifyTokenParsing.
@Test
public void verifyTokenParsing() {
val request = new MockHttpServletRequest();
request.setRemoteAddr("185.86.151.11");
request.setLocalAddr("185.88.151.11");
val clientInfo = new ClientInfo(request);
ClientInfoHolder.setClientInfo(clientInfo);
val properties = new PasswordManagementProperties();
val service = new NoOpPasswordManagementService(CipherExecutor.noOpOfSerializableToString(), "CAS", properties);
val token = UUID.randomUUID().toString();
val claims = new JwtClaims();
claims.setJwtId(token);
claims.setIssuer("bad-issuer");
assertNull(service.parseToken(claims.toJson()));
claims.setIssuer("CAS");
claims.setAudience("other-audience");
assertNull(service.parseToken(claims.toJson()));
claims.setAudience("CAS");
claims.setSubject(StringUtils.EMPTY);
assertNull(service.parseToken(claims.toJson()));
claims.setClaim("origin", "whatever");
claims.setSubject("casuser");
assertNull(service.parseToken(claims.toJson()));
claims.setClaim("origin", clientInfo.getServerIpAddress());
claims.setClaim("client", "whatever");
assertNull(service.parseToken(claims.toJson()));
claims.setClaim("client", clientInfo.getClientIpAddress());
val milli = Instant.now(Clock.systemUTC()).minusSeconds(500).toEpochMilli();
claims.setExpirationTime(NumericDate.fromMilliseconds(milli));
assertNull(service.parseToken(claims.toJson()));
claims.setExpirationTime(NumericDate.now());
assertNotNull(service.parseToken(claims.toJson()));
}
use of org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties in project cas by apereo.
the class SendPasswordResetInstructionsAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
if (!communicationsManager.isMailSenderDefined()) {
LOGGER.warn("CAS is unable to send password-reset emails given no settings are defined to account for email servers");
return error();
}
final PasswordManagementProperties pm = casProperties.getAuthn().getPm();
final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
final String username = request.getParameter("username");
if (StringUtils.isBlank(username)) {
LOGGER.warn("No username is provided");
return error();
}
final String to = passwordManagementService.findEmail(username);
if (StringUtils.isBlank(to)) {
LOGGER.warn("No recipient is provided");
return error();
}
final String token = passwordManagementService.createToken(username);
final String url = casProperties.getServer().getPrefix().concat('/' + FLOW_ID_PASSWORD_RESET + '?' + PARAMETER_NAME_TOKEN + '=').concat(token);
LOGGER.debug("Generated password reset URL [{}]; Link is only active for the next [{}] minute(s)", url, pm.getReset().getExpirationMinutes());
if (sendPasswordResetEmailToAccount(to, url)) {
return success();
}
LOGGER.error("Failed to notify account [{}]", to);
return error();
}
use of org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties in project cas by apereo.
the class VerifyPasswordResetRequestAction method doExecute.
@Override
protected Event doExecute(final RequestContext requestContext) throws Exception {
final PasswordManagementProperties pm = casProperties.getAuthn().getPm();
final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
final String token = request.getParameter(PARAMETER_NAME_TOKEN);
if (StringUtils.isBlank(token)) {
LOGGER.error("Password reset token is missing");
return error();
}
final String username = passwordManagementService.parseToken(token);
if (StringUtils.isBlank(username)) {
LOGGER.error("Password reset token could not be verified");
return error();
}
if (pm.getReset().isSecurityQuestionsEnabled()) {
final Map<String, String> questions = passwordManagementService.getSecurityQuestions(username);
if (questions.isEmpty()) {
LOGGER.warn("No security questions could be found for [{}]", username);
return error();
}
requestContext.getFlowScope().put("questions", new HashSet<>(questions.keySet()));
} else {
LOGGER.debug("Security questions are not enabled");
}
requestContext.getFlowScope().put("token", token);
requestContext.getFlowScope().put("username", username);
requestContext.getFlowScope().put("questionsEnabled", pm.getReset().isSecurityQuestionsEnabled());
if (pm.getReset().isSecurityQuestionsEnabled()) {
return success();
}
return new EventFactorySupport().event(this, "questionsDisabled");
}
Aggregations