Search in sources :

Example 46 with TimeDuration

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

the class ReportSummaryData method calcTimeWindow.

private int calcTimeWindow(final Instant eventDate, final long timeWindow, final boolean adding) {
    if (eventDate == null) {
        return 0;
    }
    final TimeDuration timeBoundary = new TimeDuration(0, timeWindow);
    final TimeDuration eventDifference = TimeDuration.fromCurrent(eventDate);
    if (timeWindow >= 0 && eventDate.isAfter(Instant.now()) && eventDifference.isShorterThan(timeBoundary)) {
        return adding ? 1 : -1;
    }
    if (timeWindow < 0 && eventDate.isBefore(Instant.now()) && eventDifference.isShorterThan(timeBoundary)) {
        return adding ? 1 : -1;
    }
    return 0;
}
Also used : TimeDuration(password.pwm.util.java.TimeDuration)

Example 47 with TimeDuration

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

the class EmailService method init.

public void init(final PwmApplication pwmApplication) throws PwmException {
    status = STATUS.OPENING;
    this.pwmApplication = pwmApplication;
    servers.addAll(EmailServerUtil.makeEmailServersMap(pwmApplication.getConfig()));
    for (final EmailServer emailServer : servers) {
        serverErrors.put(emailServer, Optional.empty());
    }
    serverIncrementer = new AtomicLoopIntIncrementer(servers.size() - 1);
    if (pwmApplication.getLocalDB() == null || pwmApplication.getLocalDB().status() != LocalDB.Status.OPEN) {
        LOGGER.warn("localdb is not open, EmailService will remain closed");
        status = STATUS.CLOSED;
        return;
    }
    final WorkQueueProcessor.Settings settings = WorkQueueProcessor.Settings.builder().maxEvents(Integer.parseInt(pwmApplication.getConfig().readAppProperty(AppProperty.QUEUE_EMAIL_MAX_COUNT))).retryDiscardAge(new TimeDuration(pwmApplication.getConfig().readSettingAsLong(PwmSetting.EMAIL_MAX_QUEUE_AGE), TimeUnit.SECONDS)).retryInterval(new TimeDuration(Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.QUEUE_EMAIL_RETRY_TIMEOUT_MS)))).preThreads(Integer.parseInt(pwmApplication.getConfig().readAppProperty(AppProperty.QUEUE_EMAIL_MAX_THREADS))).build();
    final LocalDBStoredQueue localDBStoredQueue = LocalDBStoredQueue.createLocalDBStoredQueue(pwmApplication, pwmApplication.getLocalDB(), LocalDB.DB.EMAIL_QUEUE);
    workQueueProcessor = new WorkQueueProcessor<>(pwmApplication, localDBStoredQueue, settings, new EmailItemProcessor(), this.getClass());
    status = STATUS.OPEN;
}
Also used : AtomicLoopIntIncrementer(password.pwm.util.java.AtomicLoopIntIncrementer) LocalDBStoredQueue(password.pwm.util.localdb.LocalDBStoredQueue) WorkQueueProcessor(password.pwm.util.localdb.WorkQueueProcessor) TimeDuration(password.pwm.util.java.TimeDuration)

Example 48 with TimeDuration

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

the class RecordManagerImpl method markSubject.

public void markSubject(final String subject) {
    if (subject == null || subject.length() < 1) {
        throw new IllegalArgumentException("subject is required value");
    }
    IntruderRecord record = readIntruderRecord(subject);
    if (record == null) {
        record = new IntruderRecord(recordType, subject);
    }
    final TimeDuration age = TimeDuration.fromCurrent(record.getTimeStamp());
    if (age.isLongerThan(settings.getCheckDuration())) {
        LOGGER.debug("re-setting existing outdated record=" + JsonUtil.serialize(record) + " (" + age.asCompactString() + ")");
        record = new IntruderRecord(recordType, subject);
    }
    record.incrementAttemptCount();
    writeIntruderRecord(record);
}
Also used : TimeDuration(password.pwm.util.java.TimeDuration)

Example 49 with TimeDuration

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

the class PwNotifyService method close.

@Override
public void close() {
    status = STATUS.CLOSED;
    JavaHelper.closeAndWaitExecutor(executorService, new TimeDuration(5, TimeUnit.SECONDS));
}
Also used : TimeDuration(password.pwm.util.java.TimeDuration)

Example 50 with TimeDuration

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

the class PwNotifySettings method fromConfiguration.

static PwNotifySettings fromConfiguration(final Configuration configuration) {
    final PwNotifySettingsBuilder builder = PwNotifySettings.builder();
    {
        final List<Integer> timeDurations = new ArrayList<>();
        final List<String> stringValues = configuration.readSettingAsStringArray(PwmSetting.PW_EXPY_NOTIFY_INTERVAL);
        for (final String value : stringValues) {
            timeDurations.add(Integer.parseInt(value));
        }
        Collections.sort(timeDurations);
        builder.notificationIntervals(Collections.unmodifiableList(timeDurations));
    }
    builder.zuluOffset(new TimeDuration(configuration.readSettingAsLong(PwmSetting.PW_EXPY_NOTIFY_JOB_OFFSET), TimeUnit.SECONDS));
    builder.batchCount(Integer.parseInt(configuration.readAppProperty(AppProperty.PWNOTIFY_BATCH_COUNT)));
    builder.maxLdapSearchSize(Integer.parseInt(configuration.readAppProperty(AppProperty.PWNOTIFY_MAX_LDAP_SEARCH_SIZE)));
    builder.batchTimeMultiplier(new BigDecimal(configuration.readAppProperty(AppProperty.PWNOTIFY_BATCH_DELAY_TIME_MULTIPLIER)));
    builder.maximumSkipWindow(new TimeDuration(Long.parseLong(configuration.readAppProperty(AppProperty.PWNOTIFY_MAX_SKIP_RERUN_WINDOW_SECONDS)), TimeUnit.SECONDS));
    return builder.build();
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) TimeDuration(password.pwm.util.java.TimeDuration) BigDecimal(java.math.BigDecimal)

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