use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.
the class ConfigManagerServlet method restLockConfiguration.
private void restLockConfiguration(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
if (PwmConstants.TRIAL_MODE) {
final String msg = LocaleHelper.getLocalizedMessage(Admin.Notice_TrialRestrictConfig, pwmRequest);
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_TRIAL_VIOLATION, msg);
final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
LOGGER.debug(pwmSession, errorInfo);
pwmRequest.outputJsonResult(restResultBean);
return;
}
if (!pwmSession.isAuthenticated()) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_AUTHENTICATION_REQUIRED, "You must be authenticated before restricting the configuration");
final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
LOGGER.debug(pwmSession, errorInfo);
pwmRequest.outputJsonResult(restResultBean);
return;
}
if (!pwmSession.getSessionManager().checkPermission(pwmApplication, Permission.PWMADMIN)) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_UNAUTHORIZED, "You must be authenticated with admin privileges before restricting the configuration");
final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
LOGGER.debug(pwmSession, errorInfo);
pwmRequest.outputJsonResult(restResultBean);
return;
}
try {
final StoredConfigurationImpl storedConfiguration = readCurrentConfiguration(pwmRequest);
if (!storedConfiguration.hasPassword()) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { "Please set a configuration password before restricting the configuration" });
final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
LOGGER.debug(pwmSession, errorInfo);
pwmRequest.outputJsonResult(restResultBean);
return;
}
storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE, "false");
saveConfiguration(pwmRequest, storedConfiguration);
final ConfigManagerBean configManagerBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ConfigManagerBean.class);
configManagerBean.setConfiguration(null);
} catch (PwmException e) {
final ErrorInformation errorInfo = e.getErrorInformation();
final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
LOGGER.debug(pwmSession, errorInfo.toDebugStr());
pwmRequest.outputJsonResult(restResultBean);
return;
} catch (Exception e) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
LOGGER.debug(pwmSession, errorInfo.toDebugStr());
pwmRequest.outputJsonResult(restResultBean);
return;
}
final HashMap<String, String> resultData = new HashMap<>();
LOGGER.info(pwmSession, "Configuration Locked");
pwmRequest.outputJsonResult(RestResultBean.withData(resultData));
}
use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.
the class ConfigEditorServlet method restSetConfigurationPassword.
@ActionHandler(action = "setConfigurationPassword")
private ProcessStatus restSetConfigurationPassword(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
try {
final Map<String, String> postData = pwmRequest.readBodyAsJsonStringMap();
final String password = postData.get("password");
configManagerBean.getStoredConfiguration().setPassword(password);
configManagerBean.setPasswordVerified(true);
LOGGER.debug(pwmRequest, "config password updated");
final RestResultBean restResultBean = RestResultBean.forConfirmMessage(pwmRequest, Config.Confirm_ConfigPasswordStored);
pwmRequest.outputJsonResult(restResultBean);
} catch (PwmOperationalException e) {
final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
pwmRequest.outputJsonResult(restResultBean);
}
return ProcessStatus.Halt;
}
use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.
the class ConfigEditorServlet method restMenuTreeData.
@ActionHandler(action = "menuTreeData")
private ProcessStatus restMenuTreeData(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
final Instant startTime = Instant.now();
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
final ArrayList<NavTreeItem> navigationData = new ArrayList<>();
final Map<String, Object> inputParameters = pwmRequest.readBodyAsJsonMap(PwmHttpRequestWrapper.Flag.BypassValidation);
final boolean modifiedSettingsOnly = (boolean) inputParameters.get("modifiedSettingsOnly");
final double level = (double) inputParameters.get("level");
final String filterText = (String) inputParameters.get("text");
{
// root node
final NavTreeItem categoryInfo = new NavTreeItem();
categoryInfo.setId("ROOT");
categoryInfo.setName("ROOT");
navigationData.add(categoryInfo);
}
{
final StoredConfigurationImpl storedConfiguration = configManagerBean.getStoredConfiguration();
final List<PwmSettingCategory> categories = NavTreeHelper.filteredCategories(pwmRequest.getPwmApplication(), storedConfiguration, pwmRequest.getLocale(), modifiedSettingsOnly, level, filterText);
navigationData.addAll(NavTreeHelper.makeSettingNavItems(categories, storedConfiguration, pwmRequest.getLocale()));
}
boolean includeDisplayText = true;
if (level >= 1) {
for (final PwmLocaleBundle localeBundle : PwmLocaleBundle.values()) {
if (!localeBundle.isAdminOnly()) {
final Set<String> modifiedKeys = new TreeSet<>();
if (modifiedSettingsOnly) {
modifiedKeys.addAll(NavTreeHelper.determineModifiedKeysSettings(localeBundle, pwmRequest.getConfig(), configManagerBean.getStoredConfiguration()));
}
if (!modifiedSettingsOnly || !modifiedKeys.isEmpty()) {
final NavTreeItem categoryInfo = new NavTreeItem();
categoryInfo.setId(localeBundle.toString());
categoryInfo.setName(localeBundle.getTheClass().getSimpleName());
categoryInfo.setParent("DISPLAY_TEXT");
categoryInfo.setType(NavTreeHelper.NavItemType.displayText);
categoryInfo.setKeys(new TreeSet<>(modifiedSettingsOnly ? modifiedKeys : localeBundle.getKeys()));
navigationData.add(categoryInfo);
includeDisplayText = true;
}
}
}
}
if (includeDisplayText) {
final NavTreeItem categoryInfo = new NavTreeItem();
categoryInfo.setId("DISPLAY_TEXT");
categoryInfo.setName("Display Text");
categoryInfo.setType(NavTreeHelper.NavItemType.navigation);
categoryInfo.setParent("ROOT");
navigationData.add(categoryInfo);
}
NavTreeHelper.moveNavItemToTopOfList(PwmSettingCategory.NOTES.toString(), navigationData);
NavTreeHelper.moveNavItemToTopOfList(PwmSettingCategory.TEMPLATES.toString(), navigationData);
LOGGER.trace(pwmRequest, "completed navigation tree data request in " + TimeDuration.fromCurrent(startTime).asCompactString());
pwmRequest.outputJsonResult(RestResultBean.withData(navigationData));
return ProcessStatus.Halt;
}
use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.
the class ConfigEditorServlet method restResetSetting.
@ActionHandler(action = "resetSetting")
private ProcessStatus restResetSetting(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
final StoredConfigurationImpl storedConfig = configManagerBean.getStoredConfiguration();
final UserIdentity loggedInUser = pwmRequest.getUserInfoIfLoggedIn();
final String key = pwmRequest.readParameterAsString("key");
final PwmSetting setting = PwmSetting.forKey(key);
if (key.startsWith("localeBundle")) {
final StringTokenizer st = new StringTokenizer(key, "-");
st.nextToken();
final PwmLocaleBundle bundleName = PwmLocaleBundle.valueOf(st.nextToken());
final String keyName = st.nextToken();
storedConfig.resetLocaleBundleMap(bundleName.getTheClass().getName(), keyName);
} else {
final String profileID = setting.getCategory().hasProfiles() ? pwmRequest.readParameterAsString("profile") : null;
storedConfig.resetSetting(setting, profileID, loggedInUser);
}
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
return ProcessStatus.Halt;
}
use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.
the class ConfigEditorServlet method restCancelEditing.
@ActionHandler(action = "cancelEditing")
private ProcessStatus restCancelEditing(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
configManagerBean.setConfiguration(null);
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
return ProcessStatus.Halt;
}
Aggregations