Search in sources :

Example 21 with RestResultBean

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

the class AdminServlet method restIntruderDataHandler.

@ActionHandler(action = "intruderData")
private ProcessStatus restIntruderDataHandler(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException {
    final int max = readMaxParameter(pwmRequest, 1000, 10 * 1000);
    final TreeMap<String, Object> returnData = new TreeMap<>();
    try {
        for (final RecordType recordType : RecordType.values()) {
            returnData.put(recordType.toString(), pwmRequest.getPwmApplication().getIntruderManager().getRecords(recordType, max));
        }
    } catch (PwmException e) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
        LOGGER.debug(pwmRequest, errorInfo);
        pwmRequest.outputJsonResult(RestResultBean.fromError(errorInfo));
    }
    final RestResultBean restResultBean = RestResultBean.withData(returnData);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) RecordType(password.pwm.svc.intruder.RecordType) TreeMap(java.util.TreeMap) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 22 with RestResultBean

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

the class AdminServlet method processReportSummary.

@ActionHandler(action = "reportSummary")
private ProcessStatus processReportSummary(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
    returnMap.put("raw", pwmApplication.getReportService().getSummaryData());
    returnMap.put("presentable", pwmApplication.getReportService().getSummaryData().asPresentableCollection(pwmApplication.getConfig(), pwmRequest.getPwmSession().getSessionStateBean().getLocale()));
    final RestResultBean restResultBean = RestResultBean.withData(returnMap);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : PwmApplication(password.pwm.PwmApplication) LinkedHashMap(java.util.LinkedHashMap) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 23 with RestResultBean

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

the class ChangePasswordServlet method processCheckPasswordAction.

@ActionHandler(action = "checkPassword")
private ProcessStatus processCheckPasswordAction(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException, ChaiUnavailableException {
    final RestCheckPasswordServer.JsonInput jsonInput = JsonUtil.deserialize(pwmRequest.readRequestBodyAsString(), RestCheckPasswordServer.JsonInput.class);
    final UserInfo userInfo = pwmRequest.getPwmSession().getUserInfo();
    final PasswordUtility.PasswordCheckInfo passwordCheckInfo = PasswordUtility.checkEnteredPassword(pwmRequest.getPwmApplication(), pwmRequest.getLocale(), pwmRequest.getPwmSession().getSessionManager().getActor(pwmRequest.getPwmApplication()), userInfo, pwmRequest.getPwmSession().getLoginInfoBean(), PasswordData.forStringValue(jsonInput.getPassword1()), PasswordData.forStringValue(jsonInput.getPassword2()));
    final RestCheckPasswordServer.JsonOutput checkResult = RestCheckPasswordServer.JsonOutput.fromPasswordCheckInfo(passwordCheckInfo);
    final RestResultBean restResultBean = RestResultBean.withData(checkResult);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : PasswordUtility(password.pwm.util.operations.PasswordUtility) UserInfo(password.pwm.ldap.UserInfo) RestCheckPasswordServer(password.pwm.ws.server.rest.RestCheckPasswordServer) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 24 with RestResultBean

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

the class ConfigEditorServlet method restSmsHealthCheck.

@ActionHandler(action = "smsHealthCheck")
private ProcessStatus restSmsHealthCheck(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    LOGGER.debug(pwmRequest, "beginning restSmsHealthCheck");
    final List<HealthRecord> returnRecords = new ArrayList<>();
    final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
    if (!SmsQueueManager.smsIsConfigured(config)) {
        returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "SMS not configured"));
    } else {
        final Map<String, String> testParams = pwmRequest.readBodyAsJsonStringMap();
        final SmsItemBean testSmsItem = new SmsItemBean(testParams.get("to"), testParams.get("message"), pwmRequest.getSessionLabel());
        try {
            final String responseBody = SmsQueueManager.sendDirectMessage(pwmRequest.getPwmApplication(), config, pwmRequest.getSessionLabel(), testSmsItem);
            returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "message sent"));
            returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "response body: \n" + StringUtil.escapeHtml(responseBody)));
        } catch (PwmException e) {
            returnRecords.add(new HealthRecord(HealthStatus.WARN, HealthTopic.SMS, "unable to send message: " + e.getMessage()));
        }
    }
    final HealthData healthData = HealthRecord.asHealthDataBean(config, pwmRequest.getLocale(), returnRecords);
    final RestResultBean restResultBean = RestResultBean.withData(healthData);
    pwmRequest.outputJsonResult(restResultBean);
    LOGGER.debug(pwmRequest, "completed restSmsHealthCheck in " + TimeDuration.fromCurrent(startTime).asCompactString());
    return ProcessStatus.Halt;
}
Also used : PwmException(password.pwm.error.PwmException) HealthData(password.pwm.ws.server.rest.bean.HealthData) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) HealthRecord(password.pwm.health.HealthRecord) Configuration(password.pwm.config.Configuration) SmsItemBean(password.pwm.bean.SmsItemBean) Instant(java.time.Instant) ArrayList(java.util.ArrayList) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 25 with RestResultBean

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

the class RestProfileServer method doGetProfileDataImpl.

private static RestResultBean doGetProfileDataImpl(final RestRequest restRequest, final String username) throws PwmUnrecoverableException, ChaiUnavailableException {
    final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, username);
    final String updateProfileID = ProfileUtility.discoverProfileIDforUser(restRequest.getPwmApplication(), restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity(), ProfileType.UpdateAttributes);
    if (StringUtil.isEmpty(updateProfileID)) {
        throw new PwmUnrecoverableException(PwmError.ERROR_NO_PROFILE_ASSIGNED);
    }
    final UpdateProfileProfile updateProfileProfile = restRequest.getPwmApplication().getConfig().getUpdateAttributesProfile().get(updateProfileID);
    final Map<String, String> profileData = new HashMap<>();
    {
        final Map<FormConfiguration, String> formData = new HashMap<>();
        for (final FormConfiguration formConfiguration : updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM)) {
            formData.put(formConfiguration, "");
        }
        final List<FormConfiguration> formFields = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
        final UserInfo userInfo = UserInfoFactory.newUserInfo(restRequest.getPwmApplication(), restRequest.getSessionLabel(), restRequest.getLocale(), targetUserIdentity.getUserIdentity(), targetUserIdentity.getChaiProvider());
        FormUtility.populateFormMapFromLdap(formFields, restRequest.getSessionLabel(), formData, userInfo);
        for (final Map.Entry<FormConfiguration, String> entry : formData.entrySet()) {
            final FormConfiguration formConfig = entry.getKey();
            profileData.put(formConfig.getName(), entry.getValue());
        }
    }
    final JsonProfileData outputData = new JsonProfileData();
    outputData.profile = profileData;
    outputData.formDefinition = updateProfileProfile.readSettingAsForm(PwmSetting.UPDATE_PROFILE_FORM);
    final RestResultBean restResultBean = RestResultBean.withData(outputData);
    StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_PROFILE);
    return restResultBean;
}
Also used : HashMap(java.util.HashMap) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) UserInfo(password.pwm.ldap.UserInfo) UpdateProfileProfile(password.pwm.config.profile.UpdateProfileProfile) FormConfiguration(password.pwm.config.value.data.FormConfiguration) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) FormMap(password.pwm.util.FormMap) 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