use of password.pwm.config.PwmSetting in project pwm by pwm-project.
the class ConfigGuideServlet method restWriteSetting.
@ActionHandler(action = "writeSetting")
private ProcessStatus restWriteSetting(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
final String profileID = "default";
final String key = pwmRequest.readParameterAsString("key");
final String bodyString = pwmRequest.readRequestBodyAsString();
final PwmSetting setting = PwmSetting.forKey(key);
final ConfigGuideBean configGuideBean = getBean(pwmRequest);
final StoredConfigurationImpl storedConfigurationImpl = ConfigGuideForm.generateStoredConfig(configGuideBean);
final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
try {
final StoredValue storedValue = ValueFactory.fromJson(setting, bodyString);
final List<String> errorMsgs = storedValue.validateValue(setting);
if (errorMsgs != null && !errorMsgs.isEmpty()) {
returnMap.put("errorMessage", setting.getLabel(pwmRequest.getLocale()) + ": " + errorMsgs.get(0));
}
if (setting == PwmSetting.CHALLENGE_RANDOM_CHALLENGES) {
configGuideBean.getFormData().put(ConfigGuideFormField.CHALLENGE_RESPONSE_DATA, JsonUtil.serialize((Serializable) storedValue.toNativeObject()));
}
} catch (Exception e) {
final String errorMsg = "error writing default value for setting " + setting.toString() + ", error: " + e.getMessage();
LOGGER.error(errorMsg, e);
throw new IllegalStateException(errorMsg, e);
}
returnMap.put("key", key);
returnMap.put("category", setting.getCategory().toString());
returnMap.put("syntax", setting.getSyntax().toString());
returnMap.put("isDefault", storedConfigurationImpl.isDefaultValue(setting, profileID));
pwmRequest.outputJsonResult(RestResultBean.withData(returnMap));
return ProcessStatus.Halt;
}
use of password.pwm.config.PwmSetting in project pwm by pwm-project.
the class ConfigEditorServlet method generateSettingData.
public static Map<String, Object> generateSettingData(final PwmApplication pwmApplication, final StoredConfigurationImpl storedConfiguration, final SessionLabel sessionLabel, final Locale locale) throws PwmUnrecoverableException {
final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
final MacroMachine macroMachine = MacroMachine.forNonUserSpecific(pwmApplication, sessionLabel);
final PwmSettingTemplateSet template = storedConfiguration.getTemplateSet();
{
final LinkedHashMap<String, Object> settingMap = new LinkedHashMap<>();
for (final PwmSetting setting : PwmSetting.values()) {
settingMap.put(setting.getKey(), SettingInfo.forSetting(setting, template, macroMachine, locale));
}
returnMap.put("settings", settingMap);
}
{
final LinkedHashMap<String, Object> categoryMap = new LinkedHashMap<>();
for (final PwmSettingCategory category : PwmSettingCategory.values()) {
categoryMap.put(category.getKey(), CategoryInfo.forCategory(category, macroMachine, locale));
}
returnMap.put("categories", categoryMap);
}
{
final LinkedHashMap<String, Object> labelMap = new LinkedHashMap<>();
for (final PwmLocaleBundle localeBundle : PwmLocaleBundle.values()) {
final LocaleInfo localeInfo = new LocaleInfo();
localeInfo.description = localeBundle.getTheClass().getSimpleName();
localeInfo.key = localeBundle.toString();
localeInfo.adminOnly = localeBundle.isAdminOnly();
labelMap.put(localeBundle.getTheClass().getSimpleName(), localeInfo);
}
returnMap.put("locales", labelMap);
}
{
final LinkedHashMap<String, Object> varMap = new LinkedHashMap<>();
varMap.put("ldapProfileIds", storedConfiguration.readSetting(PwmSetting.LDAP_PROFILE_LIST).toNativeObject());
varMap.put("currentTemplate", storedConfiguration.getTemplateSet());
varMap.put("configurationNotes", storedConfiguration.readConfigProperty(ConfigurationProperty.NOTES));
returnMap.put("var", varMap);
}
return Collections.unmodifiableMap(returnMap);
}
use of password.pwm.config.PwmSetting 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.PwmSetting in project pwm by pwm-project.
the class ConfigManagerCertificatesServlet method makeCertificateDebugData.
List<CertificateDebugDataItem> makeCertificateDebugData(final Configuration configuration) throws PwmUnrecoverableException {
final StoredConfigurationImpl storedConfiguration = configuration.getStoredConfiguration();
final List<StoredConfigReference> modifiedSettings = StoredConfigurationUtil.modifiedSettings(storedConfiguration);
final List<CertificateDebugDataItem> certificateDebugDataItems = new ArrayList<>();
for (final StoredConfigReference ref : modifiedSettings) {
if (ref.getRecordType() == StoredConfigReference.RecordType.SETTING) {
final PwmSetting pwmSetting = PwmSetting.forKey(ref.getRecordID());
if (pwmSetting.getSyntax() == PwmSettingSyntax.X509CERT) {
final StoredValue storedValue;
if (pwmSetting.getCategory().hasProfiles()) {
storedValue = storedConfiguration.readSetting(pwmSetting, ref.getProfileID());
} else {
storedValue = storedConfiguration.readSetting(pwmSetting);
}
final X509Certificate[] arrayCerts = (X509Certificate[]) storedValue.toNativeObject();
final List<X509Certificate> certificates = arrayCerts == null ? Collections.emptyList() : Arrays.asList(arrayCerts);
certificateDebugDataItems.addAll(makeItems(pwmSetting, ref.getProfileID(), certificates));
} else if (pwmSetting.getSyntax() == PwmSettingSyntax.ACTION) {
final StoredValue storedValue;
if (pwmSetting.getCategory().hasProfiles()) {
storedValue = storedConfiguration.readSetting(pwmSetting, ref.getProfileID());
} else {
storedValue = storedConfiguration.readSetting(pwmSetting);
}
final List<ActionConfiguration> actionConfigurations = (List) storedValue.toNativeObject();
for (final ActionConfiguration actionConfiguration : actionConfigurations) {
final List<X509Certificate> certificates = actionConfiguration.getCertificates();
certificateDebugDataItems.addAll(makeItems(pwmSetting, ref.getProfileID(), certificates));
}
}
}
}
Collections.sort(certificateDebugDataItems);
return Collections.unmodifiableList(certificateDebugDataItems);
}
use of password.pwm.config.PwmSetting in project pwm by pwm-project.
the class UserDebugDataReader method permissionMap.
private static Map<Permission, String> permissionMap(final PwmApplication pwmApplication, final SessionLabel sessionLabel, final UserIdentity userIdentity) throws PwmUnrecoverableException {
final Map<Permission, String> results = new TreeMap<>();
for (final Permission permission : Permission.values()) {
final PwmSetting setting = permission.getPwmSetting();
if (!setting.isHidden() && !setting.getCategory().isHidden() && !setting.getCategory().hasProfiles()) {
final List<UserPermission> userPermission = pwmApplication.getConfig().readSettingAsUserPermission(permission.getPwmSetting());
final boolean result = LdapPermissionTester.testUserPermissions(pwmApplication, sessionLabel, userIdentity, userPermission);
results.put(permission, result ? Permission.PermissionStatus.GRANTED.toString() : Permission.PermissionStatus.DENIED.toString());
}
}
return Collections.unmodifiableMap(results);
}
Aggregations