Search in sources :

Example 11 with PwmSetting

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;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) Serializable(java.io.Serializable) StoredValue(password.pwm.config.StoredValue) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap)

Example 12 with PwmSetting

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);
}
Also used : PwmSetting(password.pwm.config.PwmSetting) PwmSettingCategory(password.pwm.config.PwmSettingCategory) PwmSettingTemplateSet(password.pwm.config.PwmSettingTemplateSet) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) MacroMachine(password.pwm.util.macro.MacroMachine) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with PwmSetting

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;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) StringTokenizer(java.util.StringTokenizer) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) UserIdentity(password.pwm.bean.UserIdentity)

Example 14 with PwmSetting

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);
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) ArrayList(java.util.ArrayList) StoredValue(password.pwm.config.StoredValue) X509Certificate(java.security.cert.X509Certificate) StoredConfigReference(password.pwm.config.stored.StoredConfigReference) PwmSetting(password.pwm.config.PwmSetting) ArrayList(java.util.ArrayList) List(java.util.List) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration)

Example 15 with PwmSetting

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);
}
Also used : PwmSetting(password.pwm.config.PwmSetting) Permission(password.pwm.Permission) UserPermission(password.pwm.config.value.data.UserPermission) TreeMap(java.util.TreeMap) UserPermission(password.pwm.config.value.data.UserPermission)

Aggregations

PwmSetting (password.pwm.config.PwmSetting)32 ArrayList (java.util.ArrayList)15 StoredValue (password.pwm.config.StoredValue)12 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)11 LinkedHashMap (java.util.LinkedHashMap)9 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)9 PwmSettingCategory (password.pwm.config.PwmSettingCategory)8 PwmException (password.pwm.error.PwmException)8 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)7 IOException (java.io.IOException)6 TreeMap (java.util.TreeMap)6 PwmOperationalException (password.pwm.error.PwmOperationalException)5 PwmLocaleBundle (password.pwm.i18n.PwmLocaleBundle)5 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)4 List (java.util.List)4 StringTokenizer (java.util.StringTokenizer)4 ServletException (javax.servlet.ServletException)4 UserIdentity (password.pwm.bean.UserIdentity)4 Configuration (password.pwm.config.Configuration)4 ErrorInformation (password.pwm.error.ErrorInformation)4