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