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;
}
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;
}
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);
}
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;
}
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;
}
Aggregations