use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class RestCheckPasswordServer method doOperation.
public RestResultBean doOperation(final RestRequest restRequest, final JsonInput jsonInput) throws PwmUnrecoverableException {
final Instant startTime = Instant.now();
if (StringUtil.isEmpty(jsonInput.getPassword1())) {
final String errorMessage = "missing field '" + FIELD_PASSWORD_1 + "'";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_FIELD_REQUIRED, errorMessage, new String[] { FIELD_PASSWORD_1 });
return RestResultBean.fromError(restRequest, errorInformation);
}
try {
final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, jsonInput.getUsername());
final UserInfo userInfo = UserInfoFactory.newUserInfo(restRequest.getPwmApplication(), restRequest.getSessionLabel(), restRequest.getLocale(), targetUserIdentity.getUserIdentity(), targetUserIdentity.getChaiProvider());
final PasswordCheckRequest checkRequest = new PasswordCheckRequest(targetUserIdentity.getUserIdentity(), StringUtil.isEmpty(jsonInput.getPassword1()) ? null : new PasswordData(jsonInput.getPassword1()), StringUtil.isEmpty(jsonInput.getPassword2()) ? null : new PasswordData(jsonInput.getPassword2()), userInfo);
restRequest.getPwmApplication().getStatisticsManager().incrementValue(Statistic.REST_CHECKPASSWORD);
final PasswordUtility.PasswordCheckInfo passwordCheckInfo = PasswordUtility.checkEnteredPassword(restRequest.getPwmApplication(), restRequest.getLocale(), targetUserIdentity.getChaiUser(), checkRequest.getUserInfo(), null, checkRequest.getPassword1(), checkRequest.getPassword2());
final JsonOutput jsonOutput = JsonOutput.fromPasswordCheckInfo(passwordCheckInfo);
final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
final TimeDuration timeDuration = TimeDuration.fromCurrent(startTime);
LOGGER.trace(restRequest.getSessionLabel(), "REST /checkpassword response (" + timeDuration.asCompactString() + "): " + JsonUtil.serialize(jsonOutput));
return restResultBean;
} catch (PwmException e) {
LOGGER.debug(restRequest.getSessionLabel(), "REST /checkpassword error during execution: " + e.getMessage());
return RestResultBean.fromError(restRequest, e.getErrorInformation());
} catch (Exception e) {
final String errorMessage = "unexpected error executing web service: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMessage);
LOGGER.error(restRequest.getSessionLabel(), errorInformation.toDebugStr(), e);
return RestResultBean.fromError(restRequest, errorInformation);
}
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class LocalDBLoggerTest method setUp.
@Override
protected void setUp() throws Exception {
// To change body of overridden methods use File | Settings | File Templates.
super.setUp();
TestHelper.setupLogging();
final File localDBPath = new File(TestHelper.getParameter("localDBPath"));
final File configFile = new File(TestHelper.getParameter("configurationFile"));
final ConfigurationReader reader = new ConfigurationReader(configFile);
config = reader.getConfiguration();
localDB = LocalDBFactory.getInstance(localDBPath, false, null, config);
// localDB.truncate(LocalDB.DB.EVENTLOG_EVENTS);
// System.out.println(localDB.size(LocalDB.DB.EVENTLOG_EVENTS));
// new TimeDuration(1,TimeUnit.HOURS).pause();
{
// open localDBLogger based on configuration settings;
final int maxEvents = (int) reader.getConfiguration().readSettingAsLong(PwmSetting.EVENTS_PWMDB_MAX_EVENTS);
final long maxAgeMs = reader.getConfiguration().readSettingAsLong(PwmSetting.EVENTS_PWMDB_MAX_AGE) * (long) 1000;
final LocalDBLoggerSettings settings = new LocalDBLoggerSettings.Builder().setMaxEvents(maxEvents).setMaxAge(new TimeDuration(maxAgeMs)).setFlags(Collections.<LocalDBLoggerSettings.Flag>emptySet()).createLocalDBLoggerSettings();
localDBLogger = new LocalDBLogger(null, localDB, settings);
}
settings = new Settings();
settings.threads = 10;
settings.testDuration = new TimeDuration(3, TimeUnit.HOURS);
settings.valueLength = 5000;
settings.batchSize = 100;
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class RestFormSigningServer method readSignedFormValue.
public static Map<String, String> readSignedFormValue(final PwmApplication pwmApplication, final String input) throws PwmUnrecoverableException {
final Integer maxAgeSeconds = Integer.parseInt(pwmApplication.getConfig().readAppProperty(AppProperty.WS_REST_SERVER_SIGNING_FORM_TIMEOUT_SECONDS));
final TimeDuration maxAge = new TimeDuration(maxAgeSeconds, TimeUnit.SECONDS);
final SignedFormData signedFormData = pwmApplication.getSecureService().decryptObject(input, SignedFormData.class);
if (signedFormData != null) {
if (signedFormData.getTimestamp() != null) {
if (TimeDuration.fromCurrent(signedFormData.getTimestamp()).isLongerThan(maxAge)) {
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_SECURITY_VIOLATION, "signedForm data is too old"));
}
return signedFormData.getFormData();
}
}
return null;
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class LDAPStatusChecker method doHealthCheck.
public List<HealthRecord> doHealthCheck(final PwmApplication pwmApplication) {
final Configuration config = pwmApplication.getConfig();
final List<HealthRecord> returnRecords = new ArrayList<>();
final Map<String, LdapProfile> ldapProfiles = pwmApplication.getConfig().getLdapProfiles();
for (final Map.Entry<String, LdapProfile> entry : ldapProfiles.entrySet()) {
final String profileID = entry.getKey();
final List<HealthRecord> profileRecords = new ArrayList<>();
profileRecords.addAll(checkBasicLdapConnectivity(pwmApplication, config, entry.getValue(), true));
if (profileRecords.isEmpty()) {
profileRecords.addAll(checkLdapServerUrls(pwmApplication, config, ldapProfiles.get(profileID)));
}
if (profileRecords.isEmpty()) {
profileRecords.add(HealthRecord.forMessage(HealthMessage.LDAP_OK));
profileRecords.addAll(doLdapTestUserCheck(config, ldapProfiles.get(profileID), pwmApplication));
}
returnRecords.addAll(profileRecords);
}
for (final LdapProfile ldapProfile : pwmApplication.getLdapConnectionService().getLastLdapFailure().keySet()) {
final ErrorInformation errorInfo = pwmApplication.getLdapConnectionService().getLastLdapFailure().get(ldapProfile);
if (errorInfo != null) {
final TimeDuration errorAge = TimeDuration.fromCurrent(errorInfo.getDate());
final long cautionDurationMS = Long.parseLong(pwmApplication.getConfig().readAppProperty(AppProperty.HEALTH_LDAP_CAUTION_DURATION_MS));
if (errorAge.isShorterThan(cautionDurationMS)) {
final String ageString = errorAge.asLongString();
final String errorDate = JavaHelper.toIsoDate(errorInfo.getDate());
final String errorMsg = errorInfo.toDebugStr();
returnRecords.add(HealthRecord.forMessage(HealthMessage.LDAP_RecentlyUnreachable, ldapProfile.getDisplayName(PwmConstants.DEFAULT_LOCALE), ageString, errorDate, errorMsg));
}
}
}
if (config.getLdapProfiles() != null && !config.getLdapProfiles().isEmpty()) {
final List<String> urls = config.getLdapProfiles().values().iterator().next().readSettingAsStringArray(PwmSetting.LDAP_SERVER_URLS);
if (urls != null && !urls.isEmpty() && !StringUtil.isEmpty(urls.iterator().next())) {
returnRecords.addAll(checkVendorSameness(pwmApplication));
returnRecords.addAll(checkUserPermissionValues(pwmApplication));
returnRecords.addAll(checkLdapDNSyntaxValues(pwmApplication));
}
}
return returnRecords;
}
use of password.pwm.util.java.TimeDuration in project pwm by pwm-project.
the class IdleTimeoutCalculator method figureMaxAuthUserTimeout.
private static Set<MaxIdleTimeoutResult> figureMaxAuthUserTimeout(final Configuration configuration, final UserInfo userInfo, final boolean userIsAdmin) throws PwmUnrecoverableException {
final Set<MaxIdleTimeoutResult> results = new TreeSet<>();
{
final long idleSetting = configuration.readSettingAsLong(PwmSetting.IDLE_TIMEOUT_SECONDS);
results.add(new MaxIdleTimeoutResult(MaxIdleTimeoutResult.reasonFor(PwmSetting.IDLE_TIMEOUT_SECONDS, null), new TimeDuration(idleSetting, TimeUnit.SECONDS)));
}
if (configuration.readSettingAsBoolean(PwmSetting.HELPDESK_ENABLE)) {
final String helpdeskProfileID = userInfo.getProfileIDs().get(ProfileType.Helpdesk);
if (!StringUtil.isEmpty(helpdeskProfileID)) {
final HelpdeskProfile helpdeskProfile = configuration.getHelpdeskProfiles().get(helpdeskProfileID);
final long helpdeskIdleTimeout = helpdeskProfile.readSettingAsLong(PwmSetting.HELPDESK_IDLE_TIMEOUT_SECONDS);
results.add(new MaxIdleTimeoutResult(MaxIdleTimeoutResult.reasonFor(PwmSetting.HELPDESK_IDLE_TIMEOUT_SECONDS, helpdeskProfileID), new TimeDuration(helpdeskIdleTimeout, TimeUnit.SECONDS)));
}
}
if (configuration.readSettingAsBoolean(PwmSetting.PEOPLE_SEARCH_ENABLE)) {
final long peopleSearchIdleTimeout = configuration.readSettingAsLong(PwmSetting.PEOPLE_SEARCH_IDLE_TIMEOUT_SECONDS);
if (peopleSearchIdleTimeout > 0) {
results.add(new MaxIdleTimeoutResult(MaxIdleTimeoutResult.reasonFor(PwmSetting.PEOPLE_SEARCH_IDLE_TIMEOUT_SECONDS, null), new TimeDuration(peopleSearchIdleTimeout, TimeUnit.SECONDS)));
}
}
if (userIsAdmin) {
final long configEditorIdleTimeout = Long.parseLong(configuration.readAppProperty(AppProperty.CONFIG_EDITOR_IDLE_TIMEOUT));
results.add(new MaxIdleTimeoutResult("Config Editor Idle Timeout", new TimeDuration(configEditorIdleTimeout, TimeUnit.SECONDS)));
}
return Collections.unmodifiableSet(results);
}
Aggregations