Search in sources :

Example 6 with HealthRecord

use of password.pwm.health.HealthRecord in project pwm by pwm-project.

the class TokenService method healthCheck.

public List<HealthRecord> healthCheck() {
    final List<HealthRecord> returnRecords = new ArrayList<>();
    if (tokensAreUsedInConfig(configuration)) {
        if (errorInformation != null) {
            returnRecords.add(HealthRecord.forMessage(HealthMessage.CryptoTokenWithNewUserVerification, errorInformation.toDebugStr()));
        }
    }
    if (storageMethod == TokenStorageMethod.STORE_LDAP) {
        if (configuration.readSettingAsBoolean(PwmSetting.NEWUSER_ENABLE)) {
            for (final NewUserProfile newUserProfile : configuration.getNewUserProfiles().values()) {
                if (newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_EMAIL_VERIFICATION)) {
                    final String label = PwmSetting.NEWUSER_EMAIL_VERIFICATION.toMenuLocationDebug(newUserProfile.getIdentifier(), PwmConstants.DEFAULT_LOCALE);
                    final String label2 = PwmSetting.TOKEN_STORAGEMETHOD.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE);
                    returnRecords.add(HealthRecord.forMessage(HealthMessage.CryptoTokenWithNewUserVerification, label, label2));
                }
                if (newUserProfile.readSettingAsBoolean(PwmSetting.NEWUSER_SMS_VERIFICATION)) {
                    final String label = PwmSetting.NEWUSER_SMS_VERIFICATION.toMenuLocationDebug(newUserProfile.getIdentifier(), PwmConstants.DEFAULT_LOCALE);
                    final String label2 = PwmSetting.TOKEN_STORAGEMETHOD.toMenuLocationDebug(null, PwmConstants.DEFAULT_LOCALE);
                    returnRecords.add(HealthRecord.forMessage(HealthMessage.CryptoTokenWithNewUserVerification, label, label2));
                }
            }
        }
    }
    return returnRecords;
}
Also used : HealthRecord(password.pwm.health.HealthRecord) ArrayList(java.util.ArrayList) NewUserProfile(password.pwm.config.profile.NewUserProfile)

Example 7 with HealthRecord

use of password.pwm.health.HealthRecord in project pwm by pwm-project.

the class DatabaseService method healthCheck.

public List<HealthRecord> healthCheck() {
    if (status == PwmService.STATUS.CLOSED) {
        return Collections.emptyList();
    }
    final List<HealthRecord> returnRecords = new ArrayList<>();
    if (!initialized) {
        returnRecords.add(new HealthRecord(HealthStatus.WARN, HealthTopic.Database, makeUninitializedError().getDetailedErrorMsg()));
        return returnRecords;
    }
    try {
        final Map<String, String> tempMap = new HashMap<>();
        tempMap.put("date", JavaHelper.toIsoDate(Instant.now()));
        final DatabaseAccessor accessor = getAccessor();
        accessor.put(DatabaseTable.PWM_META, KEY_TEST, JsonUtil.serializeMap(tempMap));
    } catch (PwmException e) {
        returnRecords.add(new HealthRecord(HealthStatus.WARN, HealthTopic.Database, "Error writing to database: " + e.getErrorInformation().toDebugStr()));
        return returnRecords;
    }
    if (lastError != null) {
        final TimeDuration errorAge = TimeDuration.fromCurrent(lastError.getDate());
        if (errorAge.isShorterThan(TimeDuration.HOUR)) {
            final String msg = "Database server was recently unavailable (" + errorAge.asLongString(PwmConstants.DEFAULT_LOCALE) + " ago at " + lastError.getDate().toString() + "): " + lastError.toDebugStr();
            returnRecords.add(new HealthRecord(HealthStatus.CAUTION, HealthTopic.Database, msg));
        }
    }
    if (returnRecords.isEmpty()) {
        returnRecords.add(new HealthRecord(HealthStatus.GOOD, HealthTopic.Database, "Database connection to " + this.dbConfiguration.getConnectionString() + " okay"));
    }
    return returnRecords;
}
Also used : PwmException(password.pwm.error.PwmException) HealthRecord(password.pwm.health.HealthRecord) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) TimeDuration(password.pwm.util.java.TimeDuration)

Example 8 with HealthRecord

use of password.pwm.health.HealthRecord in project pwm by pwm-project.

the class PwmPasswordPolicy method health.

public List<HealthRecord> health(final Locale locale) {
    final RuleHelper ruleHelper = this.getRuleHelper();
    final List<HealthRecord> returnList = new ArrayList<>();
    final Map<PwmPasswordRule, PwmPasswordRule> rulePairs = new LinkedHashMap<>();
    rulePairs.put(PwmPasswordRule.MinimumLength, PwmPasswordRule.MaximumLength);
    rulePairs.put(PwmPasswordRule.MinimumLowerCase, PwmPasswordRule.MaximumLowerCase);
    rulePairs.put(PwmPasswordRule.MinimumUpperCase, PwmPasswordRule.MaximumUpperCase);
    rulePairs.put(PwmPasswordRule.MinimumNumeric, PwmPasswordRule.MaximumNumeric);
    rulePairs.put(PwmPasswordRule.MinimumSpecial, PwmPasswordRule.MaximumSpecial);
    rulePairs.put(PwmPasswordRule.MinimumAlpha, PwmPasswordRule.MaximumAlpha);
    rulePairs.put(PwmPasswordRule.MinimumNonAlpha, PwmPasswordRule.MaximumNonAlpha);
    rulePairs.put(PwmPasswordRule.MinimumUnique, PwmPasswordRule.MaximumUnique);
    for (final Map.Entry<PwmPasswordRule, PwmPasswordRule> entry : rulePairs.entrySet()) {
        final PwmPasswordRule minRule = entry.getKey();
        final PwmPasswordRule maxRule = entry.getValue();
        final int minValue = ruleHelper.readIntValue(minRule);
        final int maxValue = ruleHelper.readIntValue(maxRule);
        if (maxValue > 0 && minValue > maxValue) {
            final String detailMsg = minRule.getLabel(locale, null) + " (" + minValue + ")" + " > " + maxRule.getLabel(locale, null) + " (" + maxValue + ")";
            returnList.add(HealthRecord.forMessage(HealthMessage.Config_PasswordPolicyProblem, profileID, detailMsg));
        }
    }
    {
        final int minValue = ruleHelper.readIntValue(PwmPasswordRule.CharGroupsMinMatch);
        final List<Pattern> ruleGroups = ruleHelper.getCharGroupValues();
        final int maxValue = ruleGroups == null ? 0 : ruleGroups.size();
        if (maxValue > 0 && minValue > maxValue) {
            final String detailMsg = PwmPasswordRule.CharGroupsValues.getLabel(locale, null) + " (" + minValue + ")" + " > " + PwmPasswordRule.CharGroupsMinMatch.getLabel(locale, null) + " (" + maxValue + ")";
            returnList.add(HealthRecord.forMessage(HealthMessage.Config_PasswordPolicyProblem, profileID, detailMsg));
        }
    }
    return Collections.unmodifiableList(returnList);
}
Also used : HealthRecord(password.pwm.health.HealthRecord) ArrayList(java.util.ArrayList) PasswordRuleHelper(com.novell.ldapchai.util.PasswordRuleHelper) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with HealthRecord

use of password.pwm.health.HealthRecord in project pwm by pwm-project.

the class ConfigGuideServlet method restLdapHealth.

@ActionHandler(action = "ldapHealth")
private ProcessStatus restLdapHealth(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfigurationImpl = ConfigGuideForm.generateStoredConfig(configGuideBean);
    final Configuration tempConfiguration = new Configuration(storedConfigurationImpl);
    final PwmApplication tempApplication = new PwmApplication(pwmRequest.getPwmApplication().getPwmEnvironment().makeRuntimeInstance(tempConfiguration));
    final LDAPStatusChecker ldapStatusChecker = new LDAPStatusChecker();
    final List<HealthRecord> records = new ArrayList<>();
    final LdapProfile ldapProfile = tempConfiguration.getDefaultLdapProfile();
    switch(configGuideBean.getStep()) {
        case LDAP_SERVER:
            {
                try {
                    ConfigGuideUtils.checkLdapServer(configGuideBean);
                    records.add(password.pwm.health.HealthRecord.forMessage(HealthMessage.LDAP_OK));
                } catch (Exception e) {
                    records.add(new HealthRecord(HealthStatus.WARN, HealthTopic.LDAP, "Can not connect to remote server: " + e.getMessage()));
                }
            }
            break;
        case LDAP_PROXY:
            {
                records.addAll(ldapStatusChecker.checkBasicLdapConnectivity(tempApplication, tempConfiguration, ldapProfile, false));
                if (records.isEmpty()) {
                    records.add(password.pwm.health.HealthRecord.forMessage(HealthMessage.LDAP_OK));
                }
            }
            break;
        case LDAP_CONTEXT:
            {
                records.addAll(ldapStatusChecker.checkBasicLdapConnectivity(tempApplication, tempConfiguration, ldapProfile, true));
                if (records.isEmpty()) {
                    records.add(new HealthRecord(HealthStatus.GOOD, HealthTopic.LDAP, "LDAP Contextless Login Root validated"));
                }
            }
            break;
        case LDAP_ADMINS:
            {
                try {
                    final UserMatchViewerFunction userMatchViewerFunction = new UserMatchViewerFunction();
                    final Collection<UserIdentity> results = userMatchViewerFunction.discoverMatchingUsers(pwmRequest.getPwmApplication(), 2, storedConfigurationImpl, PwmSetting.QUERY_MATCH_PWM_ADMIN, null);
                    if (results.isEmpty()) {
                        records.add(new HealthRecord(HealthStatus.WARN, HealthTopic.LDAP, "No matching admin users"));
                    } else {
                        records.add(new HealthRecord(HealthStatus.GOOD, HealthTopic.LDAP, "Admin group validated"));
                    }
                } catch (PwmException e) {
                    records.add(new HealthRecord(HealthStatus.WARN, HealthTopic.LDAP, "Error during admin group validation: " + e.getErrorInformation().toDebugStr()));
                } catch (Exception e) {
                    records.add(new HealthRecord(HealthStatus.WARN, HealthTopic.LDAP, "Error during admin group validation: " + e.getMessage()));
                }
            }
            break;
        case LDAP_TESTUSER:
            {
                final String testUserValue = configGuideBean.getFormData().get(ConfigGuideFormField.PARAM_LDAP_TEST_USER);
                if (testUserValue != null && !testUserValue.isEmpty()) {
                    records.addAll(ldapStatusChecker.checkBasicLdapConnectivity(tempApplication, tempConfiguration, ldapProfile, false));
                    records.addAll(ldapStatusChecker.doLdapTestUserCheck(tempConfiguration, ldapProfile, tempApplication));
                } else {
                    records.add(new HealthRecord(HealthStatus.CAUTION, HealthTopic.LDAP, "No test user specified"));
                }
            }
            break;
        case DATABASE:
            {
                records.addAll(DatabaseStatusChecker.checkNewDatabaseStatus(pwmRequest.getPwmApplication(), tempConfiguration));
            }
            break;
        default:
            JavaHelper.unhandledSwitchStatement(configGuideBean.getStep());
    }
    final HealthData jsonOutput = new HealthData();
    jsonOutput.records = password.pwm.ws.server.rest.bean.HealthRecord.fromHealthRecords(records, pwmRequest.getLocale(), tempConfiguration);
    jsonOutput.timestamp = Instant.now();
    jsonOutput.overall = HealthMonitor.getMostSevereHealthStatus(records).toString();
    final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : HealthData(password.pwm.ws.server.rest.bean.HealthData) ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration) UserMatchViewerFunction(password.pwm.config.function.UserMatchViewerFunction) ArrayList(java.util.ArrayList) LdapProfile(password.pwm.config.profile.LdapProfile) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) PwmException(password.pwm.error.PwmException) HealthRecord(password.pwm.health.HealthRecord) Collection(java.util.Collection) LDAPStatusChecker(password.pwm.health.LDAPStatusChecker) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 10 with HealthRecord

use of password.pwm.health.HealthRecord in project pwm by pwm-project.

the class ConfigEditorServlet method restReadChangeLog.

@ActionHandler(action = "readChangeLog")
private ProcessStatus restReadChangeLog(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final Locale locale = pwmRequest.getLocale();
    final HashMap<String, Object> returnObj = new HashMap<>();
    returnObj.put("html", configManagerBean.getStoredConfiguration().changeLogAsDebugString(locale, true));
    returnObj.put("modified", configManagerBean.getStoredConfiguration().isModified());
    try {
        final ConfigurationChecker configurationChecker = new ConfigurationChecker();
        final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
        final List<HealthRecord> healthRecords = configurationChecker.doHealthCheck(config, pwmRequest.getLocale());
        final HealthData healthData = new HealthData();
        healthData.setOverall("CONFIG");
        healthData.setRecords(password.pwm.ws.server.rest.bean.HealthRecord.fromHealthRecords(healthRecords, locale, config));
        returnObj.put("health", healthData);
    } catch (Exception e) {
        LOGGER.error(pwmRequest, "error generating health records: " + e.getMessage());
    }
    final RestResultBean restResultBean = RestResultBean.withData(returnObj);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : Locale(java.util.Locale) ConfigurationChecker(password.pwm.health.ConfigurationChecker) HealthData(password.pwm.ws.server.rest.bean.HealthData) Configuration(password.pwm.config.Configuration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) HealthRecord(password.pwm.health.HealthRecord) RestResultBean(password.pwm.ws.server.RestResultBean)

Aggregations

HealthRecord (password.pwm.health.HealthRecord)11 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Configuration (password.pwm.config.Configuration)4 PwmException (password.pwm.error.PwmException)4 RestResultBean (password.pwm.ws.server.RestResultBean)4 HealthData (password.pwm.ws.server.rest.bean.HealthData)4 IOException (java.io.IOException)3 Instant (java.time.Instant)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)3 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)2 Map (java.util.Map)2 ServletException (javax.servlet.ServletException)2 PwmApplication (password.pwm.PwmApplication)2 PwmOperationalException (password.pwm.error.PwmOperationalException)2 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)2 TimeDuration (password.pwm.util.java.TimeDuration)2 PasswordRuleHelper (com.novell.ldapchai.util.PasswordRuleHelper)1