Search in sources :

Example 1 with PwmException

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();
    }
}
Also used : XPathExpression(org.jdom2.xpath.XPathExpression) PwmException(password.pwm.error.PwmException) Element(org.jdom2.Element)

Example 2 with PwmException

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();
        }
    }
}
Also used : PwmException(password.pwm.error.PwmException) PwmApplication(password.pwm.PwmApplication) PwmEnvironment(password.pwm.PwmEnvironment) DatabaseAccessor(password.pwm.util.db.DatabaseAccessor)

Example 3 with PwmException

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;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) PwmException(password.pwm.error.PwmException) PasswordData(password.pwm.util.PasswordData) ArrayList(java.util.ArrayList) LdapProfile(password.pwm.config.profile.LdapProfile) URISyntaxException(java.net.URISyntaxException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException)

Example 4 with PwmException

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;
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) Instant(java.time.Instant) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) TimeDuration(password.pwm.util.java.TimeDuration) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException)

Example 5 with PwmException

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);
}
Also used : PwmException(password.pwm.error.PwmException) TimeDuration(password.pwm.util.java.TimeDuration)

Aggregations

PwmException (password.pwm.error.PwmException)63 ErrorInformation (password.pwm.error.ErrorInformation)42 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)38 IOException (java.io.IOException)19 PwmOperationalException (password.pwm.error.PwmOperationalException)19 PwmApplication (password.pwm.PwmApplication)16 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)13 UserIdentity (password.pwm.bean.UserIdentity)13 RestResultBean (password.pwm.ws.server.RestResultBean)13 ServletException (javax.servlet.ServletException)12 LinkedHashMap (java.util.LinkedHashMap)9 PwmSession (password.pwm.http.PwmSession)9 Instant (java.time.Instant)8 TimeDuration (password.pwm.util.java.TimeDuration)8 MacroMachine (password.pwm.util.macro.MacroMachine)8 Configuration (password.pwm.config.Configuration)7 PwmRequest (password.pwm.http.PwmRequest)7 UserInfo (password.pwm.ldap.UserInfo)7 PasswordData (password.pwm.util.PasswordData)7 ArrayList (java.util.ArrayList)6