use of password.pwm.config.stored.StoredConfigurationImpl 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.config.stored.StoredConfigurationImpl 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.config.stored.StoredConfigurationImpl 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.config.stored.StoredConfigurationImpl in project pwm by pwm-project.
the class ConfigGuideUtils method writeConfig.
static void writeConfig(final ContextManager contextManager, final ConfigGuideBean configGuideBean) throws PwmOperationalException, PwmUnrecoverableException {
final StoredConfigurationImpl storedConfiguration = ConfigGuideForm.generateStoredConfig(configGuideBean);
final String configPassword = configGuideBean.getFormData().get(ConfigGuideFormField.PARAM_CONFIG_PASSWORD);
if (configPassword != null && configPassword.length() > 0) {
storedConfiguration.setPassword(configPassword);
} else {
storedConfiguration.writeConfigProperty(ConfigurationProperty.PASSWORD_HASH, null);
}
storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE, "false");
ConfigGuideUtils.writeConfig(contextManager, storedConfiguration);
}
use of password.pwm.config.stored.StoredConfigurationImpl in project pwm by pwm-project.
the class ConfigGuideUtils method restUploadConfig.
public static void restUploadConfig(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final HttpServletRequest req = pwmRequest.getHttpServletRequest();
if (pwmApplication.getApplicationMode() == PwmApplicationMode.RUNNING) {
final String errorMsg = "config upload is not permitted when in running mode";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_UPLOAD_FAILURE, errorMsg, new String[] { errorMsg });
pwmRequest.respondWithError(errorInformation, true);
}
if (ServletFileUpload.isMultipartContent(req)) {
final InputStream uploadedFile = pwmRequest.readFileUploadStream(PwmConstants.PARAM_FILE_UPLOAD);
if (uploadedFile != null) {
try {
final StoredConfigurationImpl storedConfig = StoredConfigurationImpl.fromXml(uploadedFile);
final List<String> configErrors = storedConfig.validateValues();
if (configErrors != null && !configErrors.isEmpty()) {
throw new PwmOperationalException(new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, configErrors.get(0)));
}
ConfigGuideUtils.writeConfig(ContextManager.getContextManager(req.getSession()), storedConfig);
LOGGER.trace(pwmSession, "read config from file: " + storedConfig.toString());
final RestResultBean restResultBean = RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown);
pwmRequest.getPwmResponse().outputJsonResult(restResultBean);
req.getSession().invalidate();
} catch (PwmException e) {
final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
pwmRequest.getPwmResponse().outputJsonResult(restResultBean);
LOGGER.error(pwmSession, e.getErrorInformation().toDebugStr());
}
} else {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_UPLOAD_FAILURE, "error reading config file: no file present in upload");
final RestResultBean restResultBean = RestResultBean.fromError(errorInformation, pwmRequest);
pwmRequest.getPwmResponse().outputJsonResult(restResultBean);
LOGGER.error(pwmSession, errorInformation.toDebugStr());
}
}
}
Aggregations