Search in sources :

Example 1 with NamedSecretValue

use of password.pwm.config.value.NamedSecretValue in project pwm by pwm-project.

the class StoredConfigurationImpl method writeSetting.

public void writeSetting(final PwmSetting setting, final String profileID, final StoredValue value, final UserIdentity userIdentity) throws PwmUnrecoverableException {
    if (profileID == null && setting.getCategory().hasProfiles()) {
        throw new IllegalArgumentException("reading of setting " + setting.getKey() + " requires a non-null profileID");
    }
    if (profileID != null && !setting.getCategory().hasProfiles()) {
        throw new IllegalArgumentException("cannot specify profile for non-profile setting");
    }
    preModifyActions();
    changeLog.updateChangeLog(setting, profileID, value);
    domModifyLock.writeLock().lock();
    try {
        final Element settingElement = createOrGetSettingElement(document, setting, profileID);
        settingElement.removeContent();
        settingElement.setAttribute(XML_ATTRIBUTE_SYNTAX, setting.getSyntax().toString());
        settingElement.setAttribute(XML_ATTRIBUTE_SYNTAX_VERSION, Integer.toString(value.currentSyntaxVersion()));
        if (setting_writeLabels) {
            final Element labelElement = new Element("label");
            labelElement.addContent(setting.getLabel(PwmConstants.DEFAULT_LOCALE));
            settingElement.addContent(labelElement);
        }
        if (setting.getSyntax() == PwmSettingSyntax.PASSWORD) {
            final List<Element> valueElements = ((PasswordValue) value).toXmlValues("value", getKey());
            settingElement.addContent(new Comment("Note: This value is encrypted and can not be edited directly."));
            settingElement.addContent(new Comment("Please use the Configuration Manager GUI to modify this value."));
            settingElement.addContent(valueElements);
        } else if (setting.getSyntax() == PwmSettingSyntax.PRIVATE_KEY) {
            final List<Element> valueElements = ((PrivateKeyValue) value).toXmlValues("value", getKey());
            settingElement.addContent(valueElements);
        } else if (setting.getSyntax() == PwmSettingSyntax.NAMED_SECRET) {
            final List<Element> valueElements = ((NamedSecretValue) value).toXmlValues("value", getKey());
            settingElement.addContent(valueElements);
        } else {
            settingElement.addContent(value.toXmlValues("value", getKey()));
        }
        updateMetaData(settingElement, userIdentity);
    } finally {
        domModifyLock.writeLock().unlock();
    }
}
Also used : Comment(org.jdom2.Comment) PasswordValue(password.pwm.config.value.PasswordValue) Element(org.jdom2.Element) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) NamedSecretValue(password.pwm.config.value.NamedSecretValue)

Aggregations

ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 Comment (org.jdom2.Comment)1 Element (org.jdom2.Element)1 NamedSecretValue (password.pwm.config.value.NamedSecretValue)1 PasswordValue (password.pwm.config.value.PasswordValue)1