use of password.pwm.error.PwmException in project pwm by pwm-project.
the class StoredConfigurationImpl method readSetting.
public StoredValue readSetting(final PwmSetting setting, final String profileID) {
if (profileID == null && setting.getCategory().hasProfiles()) {
final IllegalArgumentException e = new IllegalArgumentException("reading of setting " + setting.getKey() + " requires a non-null profileID");
LOGGER.error("error", e);
throw e;
}
if (profileID != null && !setting.getCategory().hasProfiles()) {
throw new IllegalStateException("cannot read setting key " + setting.getKey() + " with non-null profileID");
}
domModifyLock.readLock().lock();
try {
final XPathExpression xp = XPathBuilder.xpathForSetting(setting, profileID);
final Element settingElement = (Element) xp.evaluateFirst(document);
if (settingElement == null) {
return defaultValue(setting, getTemplateSet());
}
if (settingElement.getChild(XML_ELEMENT_DEFAULT) != null) {
return defaultValue(setting, getTemplateSet());
}
try {
return ValueFactory.fromXmlValues(setting, settingElement, getKey());
} catch (PwmException e) {
final String errorMsg = "unexpected error reading setting '" + setting.getKey() + "' profile '" + profileID + "', error: " + e.getMessage();
throw new IllegalStateException(errorMsg);
}
} finally {
domModifyLock.readLock().unlock();
}
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class DatabaseStatusChecker method checkDatabaseStatus.
private static List<HealthRecord> checkDatabaseStatus(final PwmApplication pwmApplication, final Configuration config) {
if (!config.hasDbConfigured()) {
return Collections.singletonList(new HealthRecord(HealthStatus.INFO, HealthTopic.Database, "Database not configured"));
}
PwmApplication runtimeInstance = null;
try {
final PwmEnvironment runtimeEnvironment = pwmApplication.getPwmEnvironment().makeRuntimeInstance(config);
runtimeInstance = new PwmApplication(runtimeEnvironment);
final DatabaseAccessor accessor = runtimeInstance.getDatabaseService().getAccessor();
accessor.get(DatabaseTable.PWM_META, "test");
return runtimeInstance.getDatabaseService().healthCheck();
} catch (PwmException e) {
LOGGER.error("error during healthcheck: " + e.getMessage());
e.printStackTrace();
return runtimeInstance.getDatabaseService().healthCheck();
} finally {
if (runtimeInstance != null) {
runtimeInstance.shutdown();
}
}
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class ConfigurationChecker method passwordStrengthChecks.
private List<HealthRecord> passwordStrengthChecks(final Configuration config, final Locale locale) {
final List<HealthRecord> records = new ArrayList<>();
for (final PwmSetting setting : PwmSetting.values()) {
if (setting.getSyntax() == PwmSettingSyntax.PASSWORD) {
if (!setting.getCategory().hasProfiles()) {
if (!config.isDefaultValue(setting)) {
try {
final PasswordData passwordValue = config.readSettingAsPassword(setting);
final int strength = PasswordUtility.judgePasswordStrength(config, passwordValue.getStringValue());
if (strength < 50) {
records.add(HealthRecord.forMessage(HealthMessage.Config_WeakPassword, setting.toMenuLocationDebug(null, locale), String.valueOf(strength)));
}
} catch (Exception e) {
LOGGER.error(SessionLabel.HEALTH_SESSION_LABEL, "error while inspecting setting " + setting.toMenuLocationDebug(null, locale) + ", error: " + e.getMessage());
}
}
}
}
}
for (final LdapProfile profile : config.getLdapProfiles().values()) {
final PwmSetting setting = PwmSetting.LDAP_PROXY_USER_PASSWORD;
try {
final PasswordData passwordValue = profile.readSettingAsPassword(setting);
final int strength = PasswordUtility.judgePasswordStrength(config, passwordValue == null ? null : passwordValue.getStringValue());
if (strength < 50) {
records.add(HealthRecord.forMessage(HealthMessage.Config_WeakPassword, setting.toMenuLocationDebug(profile.getIdentifier(), locale), String.valueOf(strength)));
}
} catch (PwmException e) {
LOGGER.error(SessionLabel.HEALTH_SESSION_LABEL, "error while inspecting setting " + setting.toMenuLocationDebug(profile.getIdentifier(), locale) + ", error: " + e.getMessage());
}
}
return records;
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class PwmServiceManager method initService.
private PwmService initService(final Class<? extends PwmService> serviceClass) throws PwmUnrecoverableException {
final Instant startTime = Instant.now();
final PwmService newServiceInstance;
final String serviceName = serviceClass.getName();
try {
final Object newInstance = serviceClass.newInstance();
newServiceInstance = (PwmService) newInstance;
} catch (Exception e) {
final String errorMsg = "unexpected error instantiating service class '" + serviceName + "', error: " + e.toString();
LOGGER.fatal(errorMsg, e);
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, errorMsg));
}
try {
LOGGER.debug("initializing service " + serviceName);
newServiceInstance.init(pwmApplication);
final TimeDuration startupDuration = TimeDuration.fromCurrent(startTime);
LOGGER.debug("completed initialization of service " + serviceName + " in " + startupDuration.asCompactString() + ", status=" + newServiceInstance.status());
} catch (PwmException e) {
LOGGER.warn("error instantiating service class '" + serviceName + "', service will remain unavailable, error: " + e.getMessage());
} catch (Exception e) {
String errorMsg = "unexpected error instantiating service class '" + serviceName + "', cannot load, error: " + e.getMessage();
if (e.getCause() != null) {
errorMsg += ", cause: " + e.getCause();
}
LOGGER.fatal(errorMsg);
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_STARTUP_ERROR, errorMsg));
}
return newServiceInstance;
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class DataStoreRecordStore method cleanup.
@Override
public void cleanup(final TimeDuration maxRecordAge) {
if (TimeDuration.fromCurrent(eldestRecord).isShorterThan(maxRecordAge)) {
return;
}
eldestRecord = Instant.now();
final long startTime = System.currentTimeMillis();
final int recordsExamined = 0;
int recordsRemoved = 0;
boolean complete = false;
while (!complete && intruderManager.status() == PwmService.STATUS.OPEN) {
final List<String> recordsToRemove = discoverPurgableKeys(maxRecordAge);
if (recordsToRemove.isEmpty()) {
complete = true;
}
try {
for (final String key : recordsToRemove) {
dataStore.remove(key);
}
} catch (PwmException e) {
LOGGER.error("unable to perform removal of identified stale records: " + e.getMessage());
}
recordsRemoved += recordsToRemove.size();
recordsToRemove.clear();
}
final TimeDuration totalDuration = TimeDuration.fromCurrent(startTime);
LOGGER.trace("completed cleanup of intruder table in " + totalDuration.asCompactString() + ", recordsExamined=" + recordsExamined + ", recordsRemoved=" + recordsRemoved);
}
Aggregations