use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.
the class ConfigEditorServlet method restFinishEditing.
@ActionHandler(action = "finishEditing")
private ProcessStatus restFinishEditing(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
final PwmSession pwmSession = pwmRequest.getPwmSession();
final List<String> validationErrors = configManagerBean.getStoredConfiguration().validateValues();
if (!validationErrors.isEmpty()) {
final String errorString = validationErrors.get(0);
final ErrorInformation errorInfo = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, errorString, new String[] { errorString });
pwmRequest.outputJsonResult(RestResultBean.fromError(errorInfo, pwmRequest));
LOGGER.error(pwmSession, errorInfo);
return ProcessStatus.Halt;
} else {
try {
ConfigManagerServlet.saveConfiguration(pwmRequest, configManagerBean.getStoredConfiguration());
configManagerBean.setConfiguration(null);
configManagerBean.setConfiguration(null);
LOGGER.debug(pwmSession, "save configuration operation completed");
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
} catch (PwmUnrecoverableException e) {
final ErrorInformation errorInfo = e.getErrorInformation();
pwmRequest.outputJsonResult(RestResultBean.fromError(errorInfo, pwmRequest));
LOGGER.error(pwmSession, errorInfo);
}
}
return ProcessStatus.Halt;
}
use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.
the class ConfigEditorServlet method setOptions.
@ActionHandler(action = "setOption")
private ProcessStatus setOptions(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
{
final String updateDescriptionTextCmd = pwmRequest.readParameterAsString("updateNotesText");
if (updateDescriptionTextCmd != null && "true".equalsIgnoreCase(updateDescriptionTextCmd)) {
try {
final String bodyString = pwmRequest.readRequestBodyAsString();
final String value = JsonUtil.deserialize(bodyString, String.class);
configManagerBean.getStoredConfiguration().writeConfigProperty(ConfigurationProperty.NOTES, value);
LOGGER.trace("updated notesText");
} catch (Exception e) {
LOGGER.error("error updating notesText: " + e.getMessage());
}
}
{
final String requestedTemplate = pwmRequest.readParameterAsString("template");
if (requestedTemplate != null && requestedTemplate.length() > 0) {
try {
final PwmSettingTemplate template = PwmSettingTemplate.valueOf(requestedTemplate);
configManagerBean.getStoredConfiguration().writeConfigProperty(ConfigurationProperty.LDAP_TEMPLATE, template.toString());
LOGGER.trace("setting template to: " + requestedTemplate);
} catch (IllegalArgumentException e) {
configManagerBean.getStoredConfiguration().writeConfigProperty(ConfigurationProperty.LDAP_TEMPLATE, PwmSettingTemplate.DEFAULT.toString());
LOGGER.error("unknown template set request: " + requestedTemplate);
}
}
}
}
return ProcessStatus.Halt;
}
use of password.pwm.http.bean.ConfigManagerBean 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.http.bean.ConfigManagerBean in project pwm by pwm-project.
the class ConfigAccessFilter method processFilter.
@Override
void processFilter(final PwmApplicationMode mode, final PwmRequest pwmRequest, final PwmFilterChain filterChain) throws PwmException, IOException, ServletException {
final PwmApplicationMode appMode = pwmRequest.getPwmApplication().getApplicationMode();
if (appMode == PwmApplicationMode.NEW) {
filterChain.doFilter();
return;
}
final boolean blockOldIE = Boolean.parseBoolean(pwmRequest.getPwmApplication().getConfig().readAppProperty(AppProperty.CONFIG_EDITOR_BLOCK_OLD_IE));
if (blockOldIE) {
try {
UserAgentUtils.checkIfPreIE11(pwmRequest);
} catch (PwmException e) {
pwmRequest.respondWithError(e.getErrorInformation());
return;
}
}
final ConfigManagerBean configManagerBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ConfigManagerBean.class);
if (checkAuthentication(pwmRequest, configManagerBean) == ProcessStatus.Continue) {
filterChain.doFilter();
}
}
use of password.pwm.http.bean.ConfigManagerBean 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;
}
Aggregations