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;
}
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;
}
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);
}
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));
}
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();
}
Aggregations