Search in sources :

Example 51 with TimeDuration

use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.

the class AbstractWordlist method containsWord.

public boolean containsWord(final String word) {
    if (wlStatus != STATUS.OPEN) {
        return false;
    }
    final String testWord = normalizeWord(word);
    if (testWord == null || testWord.length() < 1) {
        return false;
    }
    final Set<String> testWords = chunkWord(testWord, this.wordlistConfiguration.getCheckSize());
    final Instant startTime = Instant.now();
    try {
        boolean result = false;
        for (final String t : testWords) {
            if (!result) {
                // stop checking once found
                if (localDB.contains(getWordlistDB(), t)) {
                    result = true;
                }
            }
        }
        final TimeDuration timeDuration = TimeDuration.fromCurrent(startTime);
        if (timeDuration.isLongerThan(100)) {
            logger.debug("wordlist search time for " + testWords.size() + " wordlist permutations was greater then 100ms: " + timeDuration.asCompactString());
        }
        return result;
    } catch (Exception e) {
        logger.error("database error checking for word: " + e.getMessage());
    }
    return false;
}
Also used : Instant(java.time.Instant) TimeDuration(password.pwm.util.java.TimeDuration) LocalDBException(password.pwm.util.localdb.LocalDBException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 52 with TimeDuration

use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.

the class TokenService method maxTokenAge.

static TimeDuration maxTokenAge(final Configuration configuration) {
    long maxValue = 0;
    maxValue = Math.max(maxValue, configuration.readSettingAsLong(PwmSetting.TOKEN_LIFETIME));
    maxValue = Math.max(maxValue, configuration.readSettingAsLong(PwmSetting.TOKEN_LIFETIME));
    for (NewUserProfile newUserProfile : configuration.getNewUserProfiles().values()) {
        maxValue = Math.max(maxValue, newUserProfile.readSettingAsLong(PwmSetting.NEWUSER_TOKEN_LIFETIME_EMAIL));
        maxValue = Math.max(maxValue, newUserProfile.readSettingAsLong(PwmSetting.NEWUSER_TOKEN_LIFETIME_SMS));
    }
    return new TimeDuration(maxValue, TimeUnit.SECONDS);
}
Also used : TimeDuration(password.pwm.util.java.TimeDuration) NewUserProfile(password.pwm.config.profile.NewUserProfile)

Example 53 with TimeDuration

use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.

the class TelemetryService method scheduleNextJob.

private void scheduleNextJob() {
    final TimeDuration durationUntilNextPublish = durationUntilNextPublish();
    executorService.schedule(new PublishJob(), durationUntilNextPublish.getTotalMilliseconds(), TimeUnit.MILLISECONDS);
    LOGGER.trace(SessionLabel.TELEMETRY_SESSION_LABEL, "next publish time: " + durationUntilNextPublish().asCompactString());
}
Also used : TimeDuration(password.pwm.util.java.TimeDuration)

Example 54 with TimeDuration

use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.

the class ProgressInfo method debugOutput.

public String debugOutput() {
    final TimeDuration remainingTime = remainingDuration();
    final NumberFormat numberFormat = NumberFormat.getNumberInstance();
    return "processed " + numberFormat.format(nowItems) + " of " + numberFormat.format(totalItems) + " (" + percentComplete().pretty(2) + ")" + ", remaining " + numberFormat.format(itemsRemaining()) + " in " + remainingTime.asCompactString();
}
Also used : TimeDuration(password.pwm.util.java.TimeDuration) NumberFormat(java.text.NumberFormat)

Example 55 with TimeDuration

use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.

the class PasswordUtility method throwPasswordTooSoonException.

public static void throwPasswordTooSoonException(final UserInfo userInfo, final SessionLabel sessionLabel) throws PwmUnrecoverableException {
    if (!userInfo.isWithinPasswordMinimumLifetime()) {
        return;
    }
    final Instant lastModified = userInfo.getPasswordLastModifiedTime();
    final TimeDuration minimumLifetime;
    {
        final int minimumLifetimeSeconds = userInfo.getPasswordPolicy().getRuleHelper().readIntValue(PwmPasswordRule.MinimumLifetime);
        if (minimumLifetimeSeconds < 1) {
            return;
        }
        if (userInfo.getPasswordPolicy() == null) {
            LOGGER.debug(sessionLabel, "skipping minimum lifetime check, password last set time is unknown");
            return;
        }
        minimumLifetime = new TimeDuration(minimumLifetimeSeconds, TimeUnit.SECONDS);
    }
    final Instant allowedChangeDate = Instant.ofEpochMilli(lastModified.toEpochMilli() + minimumLifetime.getTotalMilliseconds());
    final TimeDuration passwordAge = TimeDuration.fromCurrent(lastModified);
    final String msg = "last password change was at " + JavaHelper.toIsoDate(lastModified) + " and is too recent (" + passwordAge.asCompactString() + " ago), password cannot be changed within minimum lifetime of " + minimumLifetime.asCompactString() + ", next eligible time to change is after " + JavaHelper.toIsoDate(allowedChangeDate);
    throw PwmUnrecoverableException.newException(PwmError.PASSWORD_TOO_SOON, msg);
}
Also used : Instant(java.time.Instant) TimeDuration(password.pwm.util.java.TimeDuration)

Aggregations

TimeDuration (password.pwm.util.java.TimeDuration)75 Instant (java.time.Instant)28 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)22 ErrorInformation (password.pwm.error.ErrorInformation)19 PwmException (password.pwm.error.PwmException)14 ArrayList (java.util.ArrayList)12 LinkedHashMap (java.util.LinkedHashMap)12 IOException (java.io.IOException)9 Configuration (password.pwm.config.Configuration)8 PwmOperationalException (password.pwm.error.PwmOperationalException)8 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)7 Map (java.util.Map)7 UserIdentity (password.pwm.bean.UserIdentity)7 HashMap (java.util.HashMap)6 HashSet (java.util.HashSet)6 List (java.util.List)6 MacroMachine (password.pwm.util.macro.MacroMachine)6 BigDecimal (java.math.BigDecimal)5 Date (java.util.Date)5 Locale (java.util.Locale)5