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);
}
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;
}
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;
}
Aggregations