Search in sources :

Example 6 with HealthData

use of password.pwm.ws.server.rest.bean.HealthData 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 7 with HealthData

use of password.pwm.ws.server.rest.bean.HealthData in project pwm by pwm-project.

the class ConfigEditorServlet method restLdapHealthCheck.

@ActionHandler(action = "ldapHealthCheck")
private ProcessStatus restLdapHealthCheck(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    LOGGER.debug(pwmRequest, "beginning restLdapHealthCheck");
    final String profileID = pwmRequest.readParameterAsString("profile");
    final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
    final HealthData healthData = LDAPStatusChecker.healthForNewConfiguration(pwmRequest.getPwmApplication(), config, pwmRequest.getLocale(), profileID, true, true);
    final RestResultBean restResultBean = RestResultBean.withData(healthData);
    pwmRequest.outputJsonResult(restResultBean);
    LOGGER.debug(pwmRequest, "completed restLdapHealthCheck in " + TimeDuration.fromCurrent(startTime).asCompactString());
    return ProcessStatus.Halt;
}
Also used : HealthData(password.pwm.ws.server.rest.bean.HealthData) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) Configuration(password.pwm.config.Configuration) Instant(java.time.Instant) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 8 with HealthData

use of password.pwm.ws.server.rest.bean.HealthData 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)

Example 9 with HealthData

use of password.pwm.ws.server.rest.bean.HealthData in project pwm by pwm-project.

the class ConfigEditorServlet method restDatabaseHealthCheck.

@ActionHandler(action = "databaseHealthCheck")
private ProcessStatus restDatabaseHealthCheck(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    LOGGER.debug(pwmRequest, "beginning restDatabaseHealthCheck");
    final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
    final List<HealthRecord> healthRecords = DatabaseStatusChecker.checkNewDatabaseStatus(pwmRequest.getPwmApplication(), config);
    final HealthData healthData = HealthRecord.asHealthDataBean(config, pwmRequest.getLocale(), healthRecords);
    final RestResultBean restResultBean = RestResultBean.withData(healthData);
    pwmRequest.outputJsonResult(restResultBean);
    LOGGER.debug(pwmRequest, "completed restDatabaseHealthCheck in " + TimeDuration.fromCurrent(startTime).asCompactString());
    return ProcessStatus.Halt;
}
Also used : HealthData(password.pwm.ws.server.rest.bean.HealthData) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) HealthRecord(password.pwm.health.HealthRecord) Configuration(password.pwm.config.Configuration) Instant(java.time.Instant) RestResultBean(password.pwm.ws.server.RestResultBean)

Aggregations

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