Search in sources :

Example 6 with PwmSettingCategory

use of password.pwm.config.PwmSettingCategory in project pwm by pwm-project.

the class StoredConfigurationImpl method copyProfileID.

public void copyProfileID(final PwmSettingCategory category, final String sourceID, final String destinationID, final UserIdentity userIdentity) throws PwmUnrecoverableException {
    if (!category.hasProfiles()) {
        throw PwmUnrecoverableException.newException(PwmError.ERROR_INVALID_CONFIG, "can not copy profile ID for category " + category + ", category does not have profiles");
    }
    final List<String> existingProfiles = this.profilesForSetting(category.getProfileSetting());
    if (!existingProfiles.contains(sourceID)) {
        throw PwmUnrecoverableException.newException(PwmError.ERROR_INVALID_CONFIG, "can not copy profile ID for category, source profileID '" + sourceID + "' does not exist");
    }
    if (existingProfiles.contains(destinationID)) {
        throw PwmUnrecoverableException.newException(PwmError.ERROR_INVALID_CONFIG, "can not copy profile ID for category, destination profileID '" + destinationID + "' already exists");
    }
    {
        final Collection<PwmSettingCategory> interestedCategories = PwmSettingCategory.associatedProfileCategories(category);
        for (final PwmSettingCategory interestedCategory : interestedCategories) {
            for (final PwmSetting pwmSetting : interestedCategory.getSettings()) {
                if (!isDefaultValue(pwmSetting, sourceID)) {
                    final StoredValue value = readSetting(pwmSetting, sourceID);
                    writeSetting(pwmSetting, destinationID, value, userIdentity);
                }
            }
        }
    }
    final List<String> newProfileIDList = new ArrayList<>();
    newProfileIDList.addAll(existingProfiles);
    newProfileIDList.add(destinationID);
    writeSetting(category.getProfileSetting(), new StringArrayValue(newProfileIDList), userIdentity);
}
Also used : PwmSetting(password.pwm.config.PwmSetting) PwmSettingCategory(password.pwm.config.PwmSettingCategory) ArrayList(java.util.ArrayList) Collection(java.util.Collection) StoredValue(password.pwm.config.StoredValue) StringArrayValue(password.pwm.config.value.StringArrayValue)

Example 7 with PwmSettingCategory

use of password.pwm.config.PwmSettingCategory in project pwm by pwm-project.

the class ConfigEditorServlet method restCopyProfile.

@ActionHandler(action = "copyProfile")
private ProcessStatus restCopyProfile(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final Map<String, String> inputMap = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation);
    final String settingKey = inputMap.get("setting");
    final PwmSetting setting = PwmSetting.forKey(settingKey);
    PwmSettingCategory category = null;
    for (final PwmSettingCategory loopCategory : PwmSettingCategory.values()) {
        if (loopCategory.hasProfiles()) {
            if (loopCategory.getProfileSetting() == setting) {
                category = loopCategory;
            }
        }
    }
    final String sourceID = inputMap.get("sourceID");
    final String destinationID = inputMap.get("destinationID");
    try {
        configManagerBean.getStoredConfiguration().copyProfileID(category, sourceID, destinationID, pwmRequest.getUserInfoIfLoggedIn());
        pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
    } catch (PwmUnrecoverableException e) {
        pwmRequest.outputJsonResult(RestResultBean.fromError(e.getErrorInformation(), pwmRequest));
    }
    return ProcessStatus.Halt;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) PwmSettingCategory(password.pwm.config.PwmSettingCategory) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 8 with PwmSettingCategory

use of password.pwm.config.PwmSettingCategory in project pwm by pwm-project.

the class NavTreeHelper method makeSettingNavItems.

/**
 * Produces a collection of {@code NavTreeItem}.
 */
static List<NavTreeItem> makeSettingNavItems(final List<PwmSettingCategory> categories, final StoredConfigurationImpl storedConfiguration, final Locale locale) {
    final List<NavTreeItem> navigationData = new ArrayList<>();
    for (final PwmSettingCategory loopCategory : categories) {
        if (!loopCategory.hasProfiles()) {
            // regular category, so output a standard nav tree item
            navigationData.add(navTreeItemForCategory(loopCategory, locale, null));
        } else {
            final List<String> profiles = StoredConfigurationUtil.profilesForCategory(loopCategory, storedConfiguration);
            final boolean topLevelProfileParent = loopCategory.isTopLevelProfile();
            if (topLevelProfileParent) {
                // edit profile option
                navigationData.add(navTreeItemForCategory(loopCategory, locale, null));
                {
                    final NavTreeItem profileEditorInfo = new NavTreeItem();
                    profileEditorInfo.setId(loopCategory.getKey() + "-EDITOR");
                    final String editItemName = LocaleHelper.getLocalizedMessage(locale, Config.Label_ProfileListEditMenuItem, null);
                    profileEditorInfo.setName(editItemName);
                    profileEditorInfo.setType(NavTreeHelper.NavItemType.profileDefinition);
                    profileEditorInfo.setProfileSetting(loopCategory.getProfileSetting().getKey());
                    profileEditorInfo.setParent(loopCategory.getKey());
                    navigationData.add(profileEditorInfo);
                }
                for (final String profileId : profiles) {
                    final NavTreeItem profileInfo = navTreeItemForCategory(loopCategory, locale, profileId);
                    profileInfo.setName(profileId.isEmpty() ? "Default" : profileId);
                    profileInfo.setId("profile-" + loopCategory.getKey() + "-" + profileId);
                    profileInfo.setParent(loopCategory.getKey());
                    if (loopCategory.getChildCategories().isEmpty()) {
                        profileInfo.setType(NavItemType.category);
                    } else {
                        profileInfo.setType(NavItemType.navigation);
                    }
                    navigationData.add(profileInfo);
                }
            } else {
                for (final String profileId : profiles) {
                    navigationData.add(navTreeItemForCategory(loopCategory, locale, profileId));
                }
            }
        }
    }
    return navigationData;
}
Also used : PwmSettingCategory(password.pwm.config.PwmSettingCategory) ArrayList(java.util.ArrayList)

Aggregations

PwmSettingCategory (password.pwm.config.PwmSettingCategory)8 PwmSetting (password.pwm.config.PwmSetting)7 ArrayList (java.util.ArrayList)5 StoredValue (password.pwm.config.StoredValue)4 LinkedHashMap (java.util.LinkedHashMap)2 Collection (java.util.Collection)1 TreeMap (java.util.TreeMap)1 PwmSettingTemplateSet (password.pwm.config.PwmSettingTemplateSet)1 StringArrayValue (password.pwm.config.value.StringArrayValue)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)1 PwmLocaleBundle (password.pwm.i18n.PwmLocaleBundle)1 MacroMachine (password.pwm.util.macro.MacroMachine)1