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