Search in sources :

Example 36 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class AbstractPwmServlet method outputUnrecoverableException.

private void outputUnrecoverableException(final PwmRequest pwmRequest, final PwmUnrecoverableException e) throws IOException, ServletException {
    if (pwmRequest.isJsonRequest()) {
        final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
        pwmRequest.outputJsonResult(restResultBean);
    } else {
        pwmRequest.respondWithError(e.getErrorInformation());
    }
}
Also used : RestResultBean(password.pwm.ws.server.RestResultBean)

Example 37 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class ConfigGuideServlet method restSettingData.

@ActionHandler(action = "settingData")
private ProcessStatus restSettingData(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfigurationImpl = ConfigGuideForm.generateStoredConfig(configGuideBean);
    final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>(ConfigEditorServlet.generateSettingData(pwmRequest.getPwmApplication(), storedConfigurationImpl, pwmRequest.getSessionLabel(), pwmRequest.getLocale()));
    final RestResultBean restResultBean = RestResultBean.withData(new LinkedHashMap<>(returnMap));
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) LinkedHashMap(java.util.LinkedHashMap) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 38 with RestResultBean

use of password.pwm.ws.server.RestResultBean 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 39 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class ConfigGuideServlet method restGotoStep.

@ActionHandler(action = "gotoStep")
private ProcessStatus restGotoStep(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    final String requestedStep = pwmRequest.readParameterAsString("step");
    GuideStep step = GuideStep.START;
    if (requestedStep != null && requestedStep.length() > 0) {
        try {
            step = GuideStep.valueOf(requestedStep);
        } catch (IllegalArgumentException e) {
            final String errorMsg = "unknown goto step request: " + requestedStep;
            LOGGER.error(pwmRequest, errorMsg);
        }
    }
    if (step == GuideStep.START) {
        configGuideBean.getFormData().clear();
        configGuideBean.getFormData().putAll(ConfigGuideForm.defaultForm());
    } else if (step == GuideStep.NEXT) {
        step = configGuideBean.getStep().next();
        while (step != GuideStep.FINISH && !step.visible(configGuideBean)) {
            step = step.next();
        }
    } else if (step == GuideStep.PREVIOUS) {
        step = configGuideBean.getStep().previous();
        while (step != GuideStep.START && !step.visible(configGuideBean)) {
            step = step.previous();
        }
    }
    if (step == GuideStep.FINISH) {
        final ContextManager contextManager = ContextManager.getContextManager(pwmRequest);
        try {
            ConfigGuideUtils.writeConfig(contextManager, configGuideBean);
            pwmRequest.getPwmSession().getSessionStateBean().setTheme(null);
        } catch (PwmException e) {
            final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
            pwmRequest.outputJsonResult(restResultBean);
            return ProcessStatus.Halt;
        } catch (Exception e) {
            final RestResultBean restResultBean = RestResultBean.fromError(new ErrorInformation(PwmError.ERROR_UNKNOWN, "error during save: " + e.getMessage()), pwmRequest);
            pwmRequest.outputJsonResult(restResultBean);
            return ProcessStatus.Halt;
        }
        final HashMap<String, String> resultData = new HashMap<>();
        resultData.put("serverRestart", "true");
        pwmRequest.outputJsonResult(RestResultBean.withData(resultData));
        pwmRequest.invalidateSession();
    } else {
        configGuideBean.setStep(step);
        pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
        LOGGER.trace("setting current step to: " + step);
    }
    return ProcessStatus.Continue;
}
Also used : PwmException(password.pwm.error.PwmException) ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) ErrorInformation(password.pwm.error.ErrorInformation) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ContextManager(password.pwm.http.ContextManager) 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) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 40 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class ConfigManagerWordlistServlet method restUploadWordlist.

void restUploadWordlist(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final HttpServletRequest req = pwmRequest.getHttpServletRequest();
    final String wordlistTypeParam = pwmRequest.readParameterAsString("wordlist");
    final WordlistType wordlistType = WordlistType.valueOf(wordlistTypeParam);
    if (wordlistType == null) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "unknown wordlist type: " + wordlistTypeParam);
        pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
        LOGGER.error(pwmRequest, "error during import: " + errorInformation.toDebugStr());
        return;
    }
    if (!ServletFileUpload.isMultipartContent(req)) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "no file found in upload");
        pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
        LOGGER.error(pwmRequest, "error during import: " + errorInformation.toDebugStr());
        return;
    }
    final InputStream inputStream = pwmRequest.readFileUploadStream(PwmConstants.PARAM_FILE_UPLOAD);
    try {
        wordlistType.forType(pwmApplication).populate(inputStream);
    } catch (PwmUnrecoverableException e) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmRequest, errorInfo.toDebugStr());
        pwmRequest.outputJsonResult(restResultBean);
        return;
    }
    pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) InputStream(java.io.InputStream) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) WordlistType(password.pwm.svc.wordlist.WordlistType) RestResultBean(password.pwm.ws.server.RestResultBean)

Aggregations

RestResultBean (password.pwm.ws.server.RestResultBean)63 ErrorInformation (password.pwm.error.ErrorInformation)27 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)21 UserIdentity (password.pwm.bean.UserIdentity)16 PwmException (password.pwm.error.PwmException)16 HelpdeskProfile (password.pwm.config.profile.HelpdeskProfile)15 Instant (java.time.Instant)14 PwmOperationalException (password.pwm.error.PwmOperationalException)14 HashMap (java.util.HashMap)11 LinkedHashMap (java.util.LinkedHashMap)11 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)10 IOException (java.io.IOException)10 PwmApplication (password.pwm.PwmApplication)10 PwmSession (password.pwm.http.PwmSession)10 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)9 ArrayList (java.util.ArrayList)8 ServletException (javax.servlet.ServletException)8 UserInfo (password.pwm.ldap.UserInfo)8 AuditRecordFactory (password.pwm.svc.event.AuditRecordFactory)8 HelpdeskAuditRecord (password.pwm.svc.event.HelpdeskAuditRecord)8