Search in sources :

Example 1 with DefaultMessageDescriptor

use of org.apereo.cas.DefaultMessageDescriptor in project cas by apereo.

the class DefaultAccountStateHandler method handleWarning.

/**
     * Handle an account state warning produced by ldaptive account state machinery.
     * <p>
     * Override this method to provide custom warning message handling.
     *
     * @param warning       the account state warning messages.
     * @param response      Ldaptive authentication response.
     * @param configuration Password policy configuration.
     * @param messages      Container for messages produced by account state warning handling.
     */
protected void handleWarning(final AccountState.Warning warning, final AuthenticationResponse response, final LdapPasswordPolicyConfiguration configuration, final List<MessageDescriptor> messages) {
    LOGGER.debug("Handling warning [{}]", warning);
    if (warning == null) {
        LOGGER.debug("Account state warning not defined");
        return;
    }
    final ZonedDateTime expDate = DateTimeUtils.zonedDateTimeOf(warning.getExpiration());
    final long ttl = ZonedDateTime.now(ZoneOffset.UTC).until(expDate, ChronoUnit.DAYS);
    LOGGER.debug("Password expires in [{}] days. Expiration warning threshold is [{}] days.", ttl, configuration.getPasswordWarningNumberOfDays());
    if (configuration.isAlwaysDisplayPasswordExpirationWarning() || ttl < configuration.getPasswordWarningNumberOfDays()) {
        messages.add(new PasswordExpiringWarningMessageDescriptor("Password expires in {0} days.", ttl));
    }
    if (warning.getLoginsRemaining() > 0) {
        messages.add(new DefaultMessageDescriptor("password.expiration.loginsRemaining", "You have {0} logins remaining before you MUST change your password.", warning.getLoginsRemaining()));
    }
}
Also used : PasswordExpiringWarningMessageDescriptor(org.apereo.cas.authentication.support.password.PasswordExpiringWarningMessageDescriptor) ZonedDateTime(java.time.ZonedDateTime) DefaultMessageDescriptor(org.apereo.cas.DefaultMessageDescriptor)

Aggregations

ZonedDateTime (java.time.ZonedDateTime)1 DefaultMessageDescriptor (org.apereo.cas.DefaultMessageDescriptor)1 PasswordExpiringWarningMessageDescriptor (org.apereo.cas.authentication.support.password.PasswordExpiringWarningMessageDescriptor)1