use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class ConfigEditorServlet method restSearchSettings.
@ActionHandler(action = "search")
private ProcessStatus restSearchSettings(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
final Instant startTime = Instant.now();
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
final String bodyData = pwmRequest.readRequestBodyAsString();
final Map<String, String> valueMap = JsonUtil.deserializeStringMap(bodyData);
final Locale locale = pwmRequest.getLocale();
final RestResultBean restResultBean;
final String searchTerm = valueMap.get("search");
final StoredConfigurationImpl storedConfiguration = configManagerBean.getStoredConfiguration();
if (searchTerm != null && !searchTerm.isEmpty()) {
final ArrayList<StoredConfigurationImpl.ConfigRecordID> searchResults = new ArrayList<>(configManagerBean.getStoredConfiguration().search(searchTerm, locale));
final ConcurrentHashMap<String, Map<String, SearchResultItem>> returnData = new ConcurrentHashMap<>();
searchResults.parallelStream().filter(recordID -> recordID.getRecordType() == StoredConfigurationImpl.ConfigRecordID.RecordType.SETTING).forEach(recordID -> {
final PwmSetting setting = (PwmSetting) recordID.getRecordID();
final SearchResultItem item = new SearchResultItem(setting.getCategory().toString(), storedConfiguration.readSetting(setting, recordID.getProfileID()).toDebugString(locale), setting.getCategory().toMenuLocationDebug(recordID.getProfileID(), locale), storedConfiguration.isDefaultValue(setting, recordID.getProfileID()), recordID.getProfileID());
final String returnCategory = item.getNavigation();
returnData.putIfAbsent(returnCategory, new ConcurrentHashMap<>());
returnData.get(returnCategory).put(setting.getKey(), item);
});
final TreeMap<String, Map<String, SearchResultItem>> outputMap = new TreeMap<>();
for (final String key : returnData.keySet()) {
outputMap.put(key, new TreeMap<>(returnData.get(key)));
}
restResultBean = RestResultBean.withData(outputMap);
LOGGER.trace(pwmRequest, "finished search operation with " + returnData.size() + " results in " + TimeDuration.fromCurrent(startTime).asCompactString());
} else {
restResultBean = RestResultBean.withData(new ArrayList<StoredConfigurationImpl.ConfigRecordID>());
}
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
use of password.pwm.ws.server.RestResultBean 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;
}
use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class ConfigEditorServlet method restExecuteSettingFunction.
@ActionHandler(action = "executeSettingFunction")
private ProcessStatus restExecuteSettingFunction(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
final String bodyString = pwmRequest.readRequestBodyAsString();
final Map<String, String> requestMap = JsonUtil.deserializeStringMap(bodyString);
final PwmSetting pwmSetting = PwmSetting.forKey(requestMap.get("setting"));
final String functionName = requestMap.get("function");
final String profileID = pwmSetting.getCategory().hasProfiles() ? pwmRequest.readParameterAsString("profile") : null;
final String extraData = requestMap.get("extraData");
try {
final Class implementingClass = Class.forName(functionName);
final SettingUIFunction function = (SettingUIFunction) implementingClass.newInstance();
final Serializable result = function.provideFunction(pwmRequest, configManagerBean.getStoredConfiguration(), pwmSetting, profileID, extraData);
final RestResultBean restResultBean = RestResultBean.forSuccessMessage(result, pwmRequest, Message.Success_Unknown);
pwmRequest.outputJsonResult(restResultBean);
} catch (Exception e) {
final RestResultBean restResultBean;
if (e instanceof PwmException) {
restResultBean = RestResultBean.fromError(((PwmException) e).getErrorInformation(), pwmRequest, true);
} else {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "error performing user search: " + e.getMessage());
restResultBean = RestResultBean.fromError(errorInformation, pwmRequest);
}
pwmRequest.outputJsonResult(restResultBean);
}
return ProcessStatus.Halt;
}
use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class AdminServlet method processReportCommand.
@ActionHandler(action = "reportCommand")
private ProcessStatus processReportCommand(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
final ReportService.ReportCommand reportCommand = JavaHelper.readEnumFromString(ReportService.ReportCommand.class, null, pwmRequest.readParameterAsString("command"));
LOGGER.trace(pwmRequest, "issuing command '" + reportCommand + "' to report engine");
pwmRequest.getPwmApplication().getReportService().executeCommand(reportCommand);
final RestResultBean restResultBean = RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown);
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class AdminServlet method restStatisticsHandler.
@ActionHandler(action = "statistics")
private ProcessStatus restStatisticsHandler(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException {
final String statKey = pwmRequest.readParameterAsString("statKey");
final String statName = pwmRequest.readParameterAsString("statName");
final String days = pwmRequest.readParameterAsString("days");
final StatisticsManager statisticsManager = pwmRequest.getPwmApplication().getStatisticsManager();
final RestStatisticsServer.JsonOutput jsonOutput = new RestStatisticsServer.JsonOutput();
jsonOutput.EPS = RestStatisticsServer.addEpsStats(statisticsManager);
if (statName != null && statName.length() > 0) {
jsonOutput.nameData = RestStatisticsServer.doNameStat(statisticsManager, statName, days);
} else {
jsonOutput.keyData = RestStatisticsServer.doKeyStat(statisticsManager, statKey);
}
final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
Aggregations