Search in sources :

Example 1 with PwmLocaleBundle

use of password.pwm.i18n.PwmLocaleBundle 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;
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) Instant(java.time.Instant) ArrayList(java.util.ArrayList) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) TreeSet(java.util.TreeSet) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with PwmLocaleBundle

use of password.pwm.i18n.PwmLocaleBundle 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 3 with PwmLocaleBundle

use of password.pwm.i18n.PwmLocaleBundle 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 4 with PwmLocaleBundle

use of password.pwm.i18n.PwmLocaleBundle in project pwm by pwm-project.

the class LocaleHelper method getModifiedKeysInConfig.

public static Map<PwmLocaleBundle, Map<String, List<Locale>>> getModifiedKeysInConfig(final Configuration configuration) {
    final Map<PwmLocaleBundle, Map<String, List<Locale>>> returnObj = new LinkedHashMap<>();
    for (final PwmLocaleBundle pwmLocaleBundle : PwmLocaleBundle.values()) {
        for (final String key : pwmLocaleBundle.getKeys()) {
            for (final Locale locale : configuration.getKnownLocales()) {
                final String defaultValue = LocaleHelper.getLocalizedMessage(locale, key, null, pwmLocaleBundle.getTheClass());
                final String customizedValue = LocaleHelper.getLocalizedMessage(locale, key, configuration, pwmLocaleBundle.getTheClass());
                if (defaultValue != null && !defaultValue.equals(customizedValue)) {
                    if (!returnObj.containsKey(pwmLocaleBundle)) {
                        returnObj.put(pwmLocaleBundle, new LinkedHashMap<String, List<Locale>>());
                    }
                    if (!returnObj.get(pwmLocaleBundle).containsKey(key)) {
                        returnObj.get(pwmLocaleBundle).put(key, new ArrayList<Locale>());
                    }
                    returnObj.get(pwmLocaleBundle).get(key).add(locale);
                }
            }
        }
    }
    return returnObj;
}
Also used : Locale(java.util.Locale) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap)

Example 5 with PwmLocaleBundle

use of password.pwm.i18n.PwmLocaleBundle in project pwm by pwm-project.

the class StoredConfigurationImpl method writeLocaleBundleMap.

public void writeLocaleBundleMap(final String bundleName, final String keyName, final Map<String, String> localeMap) {
    ResourceBundle theBundle = null;
    for (final PwmLocaleBundle bundle : PwmLocaleBundle.values()) {
        if (bundle.getTheClass().getName().equals(bundleName)) {
            theBundle = ResourceBundle.getBundle(bundleName);
        }
    }
    if (theBundle == null) {
        LOGGER.info("ignoring unknown locale bundle for bundle=" + bundleName + ", key=" + keyName);
        return;
    }
    if (theBundle.getString(keyName) == null) {
        LOGGER.info("ignoring unknown key for bundle=" + bundleName + ", key=" + keyName);
        return;
    }
    resetLocaleBundleMap(bundleName, keyName);
    if (localeMap == null || localeMap.isEmpty()) {
        LOGGER.info("cleared locale bundle map for bundle=" + bundleName + ", key=" + keyName);
        return;
    }
    preModifyActions();
    changeLog.updateChangeLog(bundleName, keyName, localeMap);
    try {
        domModifyLock.writeLock().lock();
        final Element localeBundleElement = new Element("localeBundle");
        localeBundleElement.setAttribute("bundle", bundleName);
        localeBundleElement.setAttribute("key", keyName);
        for (final Map.Entry<String, String> entry : localeMap.entrySet()) {
            final String locale = entry.getKey();
            final String value = entry.getValue();
            final Element valueElement = new Element("value");
            if (locale != null && locale.length() > 0) {
                valueElement.setAttribute("locale", locale);
            }
            valueElement.setContent(new CDATA(value));
            localeBundleElement.addContent(valueElement);
        }
        localeBundleElement.setAttribute(XML_ATTRIBUTE_MODIFY_TIME, JavaHelper.toIsoDate(Instant.now()));
        document.getRootElement().addContent(localeBundleElement);
    } finally {
        domModifyLock.writeLock().unlock();
    }
}
Also used : PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) Element(org.jdom2.Element) ResourceBundle(java.util.ResourceBundle) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) CDATA(org.jdom2.CDATA)

Aggregations

PwmLocaleBundle (password.pwm.i18n.PwmLocaleBundle)7 LinkedHashMap (java.util.LinkedHashMap)5 PwmSetting (password.pwm.config.PwmSetting)4 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)4 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)4 StringTokenizer (java.util.StringTokenizer)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2 ResourceBundle (java.util.ResourceBundle)2 TreeMap (java.util.TreeMap)2 UserIdentity (password.pwm.bean.UserIdentity)2 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 IOException (java.io.IOException)1 Instant (java.time.Instant)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 ServletException (javax.servlet.ServletException)1 CDATA (org.jdom2.CDATA)1