Search in sources :

Example 16 with TimeDuration

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

the class LocalDBLoggerSettings method fromConfiguration.

public static LocalDBLoggerSettings fromConfiguration(final Configuration configuration) {
    final Set<Flag> flags = new HashSet<>();
    if (configuration.isDevDebugMode()) {
        flags.add(Flag.DevDebug);
    }
    final int maxEvents = (int) configuration.readSettingAsLong(PwmSetting.EVENTS_PWMDB_MAX_EVENTS);
    final long maxAgeMS = 1000 * configuration.readSettingAsLong(PwmSetting.EVENTS_PWMDB_MAX_AGE);
    final TimeDuration maxAge = new TimeDuration(maxAgeMS);
    final int maxBufferSize = Integer.parseInt(configuration.readAppProperty(AppProperty.LOCALDB_LOGWRITER_BUFFER_SIZE));
    final TimeDuration maxBufferWaitTime = new TimeDuration(Long.parseLong(configuration.readAppProperty(AppProperty.LOCALDB_LOGWRITER_MAX_BUFFER_WAIT_MS)));
    final int maxTrimSize = Integer.parseInt(configuration.readAppProperty(AppProperty.LOCALDB_LOGWRITER_MAX_TRIM_SIZE));
    return new Builder().setMaxEvents(maxEvents).setMaxAge(maxAge).setFlags(flags).setMaxBufferSize(maxBufferSize).setMaxBufferWaitTime(maxBufferWaitTime).setMaxTrimSize(maxTrimSize).createLocalDBLoggerSettings();
}
Also used : TimeDuration(password.pwm.util.java.TimeDuration) HashSet(java.util.HashSet)

Example 17 with TimeDuration

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

the class LocalDBLogger method healthCheck.

public List<HealthRecord> healthCheck() {
    final List<HealthRecord> healthRecords = new ArrayList<>();
    if (status != STATUS.OPEN) {
        healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDBLogger_NOTOPEN, status.toString()));
        return healthRecords;
    }
    final int eventCount = getStoredEventCount();
    if (eventCount > settings.getMaxEvents() + 5000) {
        final PwmNumberFormat numberFormat = PwmNumberFormat.forDefaultLocale();
        healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDBLogger_HighRecordCount, numberFormat.format(eventCount), numberFormat.format(settings.getMaxEvents())));
    }
    final Instant tailDate = getTailDate();
    if (tailDate != null) {
        final TimeDuration timeDuration = TimeDuration.fromCurrent(tailDate);
        final TimeDuration maxTimeDuration = settings.getMaxAge().add(TimeDuration.HOUR);
        if (timeDuration.isLongerThan(maxTimeDuration)) {
            // older than max age + 1h
            healthRecords.add(HealthRecord.forMessage(HealthMessage.LocalDBLogger_OldRecordPresent, timeDuration.asCompactString(), maxTimeDuration.asCompactString()));
        }
    }
    return healthRecords;
}
Also used : HealthRecord(password.pwm.health.HealthRecord) PwmNumberFormat(password.pwm.util.java.PwmNumberFormat) Instant(java.time.Instant) ArrayList(java.util.ArrayList) TimeDuration(password.pwm.util.java.TimeDuration)

Example 18 with TimeDuration

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

the class LocalDBLogger method determineTailRemovalCount.

private int determineTailRemovalCount() {
    final int maxTrailSize = settings.getMaxTrimSize();
    final int currentItemCount = localDBListQueue.size();
    // must keep at least one position populated
    if (currentItemCount <= LocalDBLoggerSettings.MINIMUM_MAXIMUM_EVENTS) {
        return 0;
    }
    // purge excess events by count
    if (currentItemCount > settings.getMaxEvents()) {
        return Math.min(maxTrailSize, currentItemCount - settings.getMaxEvents());
    }
    // purge the tail if it is missing or has invalid timestamp
    final Instant tailTimestamp = getTailDate();
    if (tailTimestamp == null) {
        return 1;
    }
    // purge excess events by age;
    final TimeDuration tailAge = TimeDuration.fromCurrent(tailTimestamp);
    if (tailAge.isLongerThan(settings.getMaxAge())) {
        final long maxRemovalPercentageOfSize = getStoredEventCount() / maxTrailSize;
        if (maxRemovalPercentageOfSize > 100) {
            return maxTrailSize;
        } else {
            return 1;
        }
    }
    return 0;
}
Also used : Instant(java.time.Instant) TimeDuration(password.pwm.util.java.TimeDuration)

Example 19 with TimeDuration

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

the class WorkQueueProcessor method logAndStatUpdateForSuccess.

private void logAndStatUpdateForSuccess(final ItemWrapper<W> itemWrapper) throws PwmOperationalException {
    final TimeDuration lagTime = TimeDuration.fromCurrent(itemWrapper.getDate());
    avgLagTime.update(lagTime.getTotalMilliseconds());
    sendRate.markEvents(1);
    logger.trace("successfully processed item=" + makeDebugText(itemWrapper) + "; lagTime=" + lagTime.asCompactString() + "; " + StringUtil.mapToString(debugInfo()));
}
Also used : TimeDuration(password.pwm.util.java.TimeDuration)

Example 20 with TimeDuration

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

the class HelpdeskDetailInfoBean method makeHelpdeskDetailInfo.

static HelpdeskDetailInfoBean makeHelpdeskDetailInfo(final PwmRequest pwmRequest, final HelpdeskProfile helpdeskProfile, final UserIdentity userIdentity) throws PwmUnrecoverableException, ChaiUnavailableException {
    final HelpdeskDetailInfoBeanBuilder builder = HelpdeskDetailInfoBean.builder();
    final Instant startTime = Instant.now();
    LOGGER.trace(pwmRequest, "beginning to assemble detail data report for user " + userIdentity);
    final Locale actorLocale = pwmRequest.getLocale();
    final ChaiUser theUser = HelpdeskServlet.getChaiUser(pwmRequest, helpdeskProfile, userIdentity);
    if (!theUser.exists()) {
        return null;
    }
    final UserInfo userInfo = UserInfoFactory.newUserInfo(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), actorLocale, userIdentity, theUser.getChaiProvider());
    final MacroMachine macroMachine = MacroMachine.forUser(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), userInfo, null);
    try {
        final List<AccountInformationBean.ActivityRecord> userHistory = AccountInformationBean.makeAuditInfo(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel(), userInfo, pwmRequest.getLocale());
        builder.userHistory(userHistory);
    } catch (Exception e) {
        LOGGER.error(pwmRequest, "unexpected error reading userHistory for user '" + userIdentity + "', " + e.getMessage());
    }
    builder.userKey(userIdentity.toObfuscatedKey(pwmRequest.getPwmApplication()));
    builder.profileData(getProfileData(helpdeskProfile, userInfo, pwmRequest.getSessionLabel(), pwmRequest.getLocale()));
    builder.passwordPolicyRules(makePasswordPolicyRules(userInfo, pwmRequest.getLocale(), pwmRequest.getConfig()));
    {
        final List<String> requirementLines = PasswordRequirementsTag.getPasswordRequirementsStrings(userInfo.getPasswordPolicy(), pwmRequest.getConfig(), pwmRequest.getLocale(), macroMachine);
        builder.passwordRequirements(Collections.unmodifiableList(requirementLines));
    }
    if ((userInfo.getPasswordPolicy() != null) && (userInfo.getPasswordPolicy().getChaiPasswordPolicy() != null) && (userInfo.getPasswordPolicy().getChaiPasswordPolicy().getPolicyEntry() != null) && (userInfo.getPasswordPolicy().getChaiPasswordPolicy().getPolicyEntry().getEntryDN() != null)) {
        builder.passwordPolicyDN(userInfo.getPasswordPolicy().getChaiPasswordPolicy().getPolicyEntry().getEntryDN());
    } else {
        builder.passwordPolicyDN(LocaleHelper.getLocalizedMessage(Display.Value_NotApplicable, pwmRequest));
    }
    if ((userInfo.getPasswordPolicy() != null) && userInfo.getPasswordPolicy().getIdentifier() != null) {
        builder.passwordPolicyID(userInfo.getPasswordPolicy().getIdentifier());
    } else {
        builder.passwordPolicyID(LocaleHelper.getLocalizedMessage(Display.Value_NotApplicable, pwmRequest));
    }
    {
        final ResponseInfoBean responseInfoBean = userInfo.getResponseInfoBean();
        if (responseInfoBean != null && responseInfoBean.getHelpdeskCrMap() != null) {
            final List<DisplayElement> responseDisplay = new ArrayList<>();
            int counter = 0;
            for (final Map.Entry<Challenge, String> entry : responseInfoBean.getHelpdeskCrMap().entrySet()) {
                counter++;
                responseDisplay.add(new DisplayElement("item_" + counter, DisplayElement.Type.string, entry.getKey().getChallengeText(), entry.getValue()));
            }
            builder.helpdeskResponses = responseDisplay;
        }
    }
    builder.userDisplayName(HelpdeskCardInfoBean.figureDisplayName(helpdeskProfile, macroMachine));
    final TimeDuration timeDuration = TimeDuration.fromCurrent(startTime);
    {
        final Set<ViewStatusFields> viewStatusFields = helpdeskProfile.readSettingAsOptionList(PwmSetting.HELPDESK_VIEW_STATUS_VALUES, ViewStatusFields.class);
        builder.statusData(ViewableUserInfoDisplayReader.makeDisplayData(viewStatusFields, pwmRequest.getConfig(), userInfo, null, pwmRequest.getLocale()));
    }
    {
        final Set<HelpdeskDetailInfoBean.StandardButton> visibleButtons = determineVisibleButtons(helpdeskProfile);
        builder.visibleButtons(visibleButtons);
        builder.enabledButtons(determineEnabledButtons(visibleButtons, userInfo));
        builder.customButtons(determineCustomButtons(helpdeskProfile));
    }
    final HelpdeskDetailInfoBean helpdeskDetailInfoBean = builder.build();
    if (pwmRequest.getConfig().isDevDebugMode()) {
        LOGGER.trace(pwmRequest, "completed assembly of detail data report for user " + userIdentity + " in " + timeDuration.asCompactString() + ", contents: " + JsonUtil.serialize(helpdeskDetailInfoBean));
    }
    return builder.build();
}
Also used : Locale(java.util.Locale) LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) Instant(java.time.Instant) ViewStatusFields(password.pwm.config.option.ViewStatusFields) UserInfo(password.pwm.ldap.UserInfo) ResponseInfoBean(password.pwm.bean.ResponseInfoBean) DisplayElement(password.pwm.http.bean.DisplayElement) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiUser(com.novell.ldapchai.ChaiUser) MacroMachine(password.pwm.util.macro.MacroMachine) ArrayList(java.util.ArrayList) List(java.util.List) 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