use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class PwmEnvironment method waitForFileLock.
public void waitForFileLock() throws PwmUnrecoverableException {
final int maxWaitSeconds = this.getFlags().contains(ApplicationFlag.CommandLineInstance) ? 1 : Integer.parseInt(getConfig().readAppProperty(AppProperty.APPLICATION_FILELOCK_WAIT_SECONDS));
final Instant startTime = Instant.now();
final TimeDuration attemptInterval = new TimeDuration(5021, TimeUnit.MILLISECONDS);
while (!this.isFileLocked() && TimeDuration.fromCurrent(startTime).isShorterThan(maxWaitSeconds, TimeUnit.SECONDS)) {
attemptFileLock();
if (!isFileLocked()) {
LOGGER.debug("can't establish application file lock after " + TimeDuration.fromCurrent(startTime).asCompactString() + ", will retry;");
attemptInterval.pause();
}
}
if (!isFileLocked()) {
final String errorMsg = "unable to obtain application path file lock";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, errorMsg);
throw new PwmUnrecoverableException(errorInformation);
}
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class CertificateChecker method checkCertificate.
public static void checkCertificate(final X509Certificate certificate, final long warnDurationMs) throws PwmOperationalException {
if (certificate == null) {
return;
}
try {
certificate.checkValidity();
} catch (CertificateException e) {
final StringBuilder errorMsg = new StringBuilder();
errorMsg.append("certificate for subject ");
errorMsg.append(certificate.getSubjectDN().getName());
errorMsg.append(" is not valid: ");
errorMsg.append(e.getMessage());
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_CERTIFICATE_ERROR, errorMsg.toString(), new String[] { errorMsg.toString() });
throw new PwmOperationalException(errorInformation);
}
final Date expireDate = certificate.getNotAfter();
final TimeDuration durationUntilExpire = TimeDuration.fromCurrent(expireDate);
if (durationUntilExpire.isShorterThan(warnDurationMs)) {
final StringBuilder errorMsg = new StringBuilder();
errorMsg.append("certificate for subject ");
errorMsg.append(certificate.getSubjectDN().getName());
errorMsg.append(" will expire on: ");
errorMsg.append(JavaHelper.toIsoDate(expireDate));
errorMsg.append(" (").append(durationUntilExpire.asCompactString()).append(" from now)");
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_CERTIFICATE_ERROR, errorMsg.toString(), new String[] { errorMsg.toString() });
throw new PwmOperationalException(errorInformation);
}
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class HelpdeskVerificationStateBean method purgeOldRecords.
void purgeOldRecords() {
for (final Iterator<HelpdeskValidationRecord> iterator = records.iterator(); iterator.hasNext(); ) {
final HelpdeskValidationRecord record = iterator.next();
final Date timestamp = record.getTimestamp();
final TimeDuration age = TimeDuration.fromCurrent(timestamp);
if (age.isLongerThan(maximumAge)) {
iterator.remove();
}
}
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class PeopleSearchDataReader method makeSearchResultsImpl.
private SearchResultBean makeSearchResultsImpl(final PwmRequest pwmRequest, final String username, final boolean includeDisplayName) throws ChaiUnavailableException, PwmUnrecoverableException {
final Instant startTime = Instant.now();
if (username == null || username.length() < 1) {
return new SearchResultBean();
}
final boolean useProxy = useProxy();
final UserSearchEngine userSearchEngine = pwmRequest.getPwmApplication().getUserSearchEngine();
final SearchConfiguration searchConfiguration;
{
final SearchConfiguration.SearchConfigurationBuilder builder = SearchConfiguration.builder();
builder.contexts(pwmRequest.getConfig().readSettingAsStringArray(PwmSetting.PEOPLE_SEARCH_SEARCH_BASE));
builder.enableContextValidation(false);
builder.username(username);
builder.enableValueEscaping(false);
builder.filter(getSearchFilter(pwmRequest.getConfig()));
builder.enableSplitWhitespace(true);
if (!useProxy) {
builder.ldapProfile(pwmRequest.getPwmSession().getUserInfo().getUserIdentity().getLdapProfileID());
builder.chaiProvider(pwmRequest.getPwmSession().getSessionManager().getChaiProvider());
}
searchConfiguration = builder.build();
}
final UserSearchResults results;
final boolean sizeExceeded;
try {
final List<FormConfiguration> searchForm = pwmRequest.getConfig().readSettingAsForm(PwmSetting.PEOPLE_SEARCH_RESULT_FORM);
final int maxResults = (int) pwmRequest.getConfig().readSettingAsLong(PwmSetting.PEOPLE_SEARCH_RESULT_LIMIT);
final Locale locale = pwmRequest.getLocale();
results = userSearchEngine.performMultiUserSearchFromForm(locale, searchConfiguration, maxResults, searchForm, pwmRequest.getSessionLabel());
sizeExceeded = results.isSizeExceeded();
} catch (PwmOperationalException e) {
final ErrorInformation errorInformation = e.getErrorInformation();
LOGGER.error(pwmRequest.getSessionLabel(), errorInformation.toDebugStr());
throw new PwmUnrecoverableException(errorInformation);
}
final List<Map<String, Object>> resultOutput = new ArrayList<>(results.resultsAsJsonOutput(pwmRequest.getPwmApplication(), null));
if (includeDisplayName) {
for (final Map<String, Object> map : resultOutput) {
final String userKey = (String) map.get("userKey");
if (userKey != null) {
final UserIdentity userIdentity = UserIdentity.fromKey(userKey, pwmRequest.getPwmApplication());
final String displayValue = figureDisplaynameValue(pwmRequest, userIdentity);
map.put("_displayName", displayValue);
}
}
}
final TimeDuration searchDuration = TimeDuration.fromCurrent(startTime);
LOGGER.trace(pwmRequest.getPwmSession(), "finished rest peoplesearch search in " + searchDuration.asCompactString() + " not using cache, size=" + results.getResults().size());
final SearchResultBean searchResultBean = new SearchResultBean();
searchResultBean.setSearchResults(resultOutput);
searchResultBean.setSizeExceeded(sizeExceeded);
final String aboutMessage = LocaleHelper.getLocalizedMessage(pwmRequest.getLocale(), Display.Display_SearchResultsInfo.getKey(), pwmRequest.getConfig(), Display.class, new String[] { String.valueOf(results.getResults().size()), searchDuration.asLongString(pwmRequest.getLocale()) });
searchResultBean.setAboutResultMessage(aboutMessage);
return searchResultBean;
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class UpdateProfileUtil method checkForTokenVerificationProgress.
static ProcessStatus checkForTokenVerificationProgress(final PwmRequest pwmRequest, final UpdateProfileBean updateProfileBean, final UpdateProfileProfile updateProfileProfile) throws PwmUnrecoverableException, ServletException, IOException {
final Map<String, TokenDestinationItem.Type> requiredTokenValidations = determineTokenValidationsRequired(pwmRequest, updateProfileBean, updateProfileProfile);
if (!requiredTokenValidations.isEmpty()) {
final Set<String> remainingValidations = new HashSet<>(requiredTokenValidations.keySet());
remainingValidations.removeAll(updateProfileBean.getCompletedTokenFields());
if (!remainingValidations.isEmpty()) {
if (StringUtil.isEmpty(updateProfileBean.getCurrentTokenField())) {
updateProfileBean.setCurrentTokenField(remainingValidations.iterator().next());
updateProfileBean.setTokenSent(false);
}
if (!updateProfileBean.isTokenSent()) {
final TokenDestinationItem tokenDestinationItem = tokenDestinationItemForCurrentValidation(pwmRequest, updateProfileBean, updateProfileProfile);
final TimeDuration tokenLifetime = tokenDestinationItem.getType() == TokenDestinationItem.Type.email ? updateProfileProfile.getTokenDurationEmail(pwmRequest.getConfig()) : updateProfileProfile.getTokenDurationSMS(pwmRequest.getConfig());
TokenUtil.initializeAndSendToken(pwmRequest, TokenUtil.TokenInitAndSendRequest.builder().userInfo(pwmRequest.getPwmSession().getUserInfo()).tokenDestinationItem(tokenDestinationItem).emailToSend(PwmSetting.EMAIL_UPDATEPROFILE_VERIFICATION).tokenType(TokenType.UPDATE).smsToSend(PwmSetting.SMS_UPDATE_PROFILE_TOKEN_TEXT).tokenLifetime(tokenLifetime).build());
updateProfileBean.setTokenSent(true);
}
forwardToEnterCode(pwmRequest, updateProfileProfile, updateProfileBean);
return ProcessStatus.Halt;
}
}
return ProcessStatus.Continue;
}
Aggregations