|
@@ -20,11 +20,13 @@
|
|
|
|
|
|
package password.pwm.config;
|
|
|
|
|
|
+import lombok.Value;
|
|
|
import password.pwm.config.value.PasswordValue;
|
|
|
import password.pwm.config.value.ValueFactory;
|
|
|
import password.pwm.i18n.Config;
|
|
|
import password.pwm.util.i18n.LocaleHelper;
|
|
|
import password.pwm.util.java.JavaHelper;
|
|
|
+import password.pwm.util.java.LazySupplier;
|
|
|
import password.pwm.util.java.StringUtil;
|
|
|
import password.pwm.util.java.XmlElement;
|
|
|
import password.pwm.util.logging.PwmLogger;
|
|
@@ -1269,9 +1271,6 @@ public enum PwmSetting
|
|
|
"helpdesk.otp.verify", PwmSettingSyntax.BOOLEAN, PwmSettingCategory.HELPDESK_BASE ),;
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
private static final PwmLogger LOGGER = PwmLogger.forClass( PwmSetting.class );
|
|
|
|
|
|
private final String key;
|
|
@@ -1279,16 +1278,16 @@ public enum PwmSetting
|
|
|
private final PwmSettingCategory category;
|
|
|
|
|
|
// cached values read from XML file
|
|
|
- private transient Supplier<List<TemplateSetAssociation>> defaultValues;
|
|
|
- private transient Supplier<List<TemplateSetAssociation>> examples;
|
|
|
- private transient Supplier<Map<String, String>> options;
|
|
|
- private transient Supplier<Collection<PwmSettingFlag>> flags;
|
|
|
- private transient Supplier<Map<PwmSettingProperty, String>> properties;
|
|
|
- private transient Supplier<Collection<LDAPPermissionInfo>> ldapPermissionInfo;
|
|
|
- private transient Supplier<Boolean> required;
|
|
|
- private transient Supplier<Boolean> hidden;
|
|
|
- private transient Supplier<Integer> level;
|
|
|
- private transient Supplier<Pattern> pattern;
|
|
|
+ private final Supplier<List<TemplateSetAssociation>> defaultValues = new LazySupplier<>( () -> PwmSettingReader.readDefaultValue( PwmSetting.this ) );
|
|
|
+ private final Supplier<List<TemplateSetAssociation>> examples = new LazySupplier<>( () -> PwmSettingReader.readExamples( PwmSetting.this ) );
|
|
|
+ private final Supplier<Map<String, String>> options = new LazySupplier<>( () -> PwmSettingReader.readOptions( PwmSetting.this ) );
|
|
|
+ private final Supplier<Collection<PwmSettingFlag>> flags = new LazySupplier<>( () -> PwmSettingReader.readFlags( PwmSetting.this ) );
|
|
|
+ private final Supplier<Map<PwmSettingProperty, String>> properties = new LazySupplier<>( () -> PwmSettingReader.readProperties( PwmSetting.this ) );
|
|
|
+ private final Supplier<Collection<LDAPPermissionInfo>> ldapPermissionInfo = new LazySupplier<>( () -> PwmSettingReader.readLdapPermissionInfo( PwmSetting.this ) );
|
|
|
+ private final Supplier<Boolean> required = new LazySupplier<>( () -> PwmSettingReader.readRequired( PwmSetting.this ) );
|
|
|
+ private final Supplier<Boolean> hidden = new LazySupplier<>( () -> PwmSettingReader.readHidden( PwmSetting.this ) );
|
|
|
+ private final Supplier<Integer> level = new LazySupplier<>( () -> PwmSettingReader.readLevel( PwmSetting.this ) );
|
|
|
+ private final Supplier<Pattern> pattern = new LazySupplier<>( () -> PwmSettingReader.readPattern( PwmSetting.this ) );
|
|
|
|
|
|
PwmSetting(
|
|
|
final String key,
|
|
@@ -1323,31 +1322,6 @@ public enum PwmSetting
|
|
|
|
|
|
private List<TemplateSetAssociation> getDefaultValue()
|
|
|
{
|
|
|
- if ( defaultValues == null )
|
|
|
- {
|
|
|
- final List<TemplateSetAssociation> returnObj = new ArrayList<>();
|
|
|
- final XmlElement settingElement = PwmSettingXml.readSettingXml( this );
|
|
|
- final List<XmlElement> defaultElements = settingElement.getChildren( PwmSettingXml.XML_ELEMENT_DEFAULT );
|
|
|
- if ( this.getSyntax() == PwmSettingSyntax.PASSWORD )
|
|
|
- {
|
|
|
- returnObj.add( new TemplateSetAssociation( new PasswordValue( null ), Collections.emptySet() ) );
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- for ( final XmlElement defaultElement : defaultElements )
|
|
|
- {
|
|
|
- final Set<PwmSettingTemplate> definedTemplates = PwmSettingXml.parseTemplateAttribute( defaultElement );
|
|
|
- final StoredValue storedValue = ValueFactory.fromXmlValues( this, defaultElement, null );
|
|
|
- returnObj.add( new TemplateSetAssociation( storedValue, definedTemplates ) );
|
|
|
- }
|
|
|
- }
|
|
|
- if ( returnObj.isEmpty() )
|
|
|
- {
|
|
|
- throw new IllegalStateException( "no default value for setting " + this.getKey() );
|
|
|
- }
|
|
|
- final List<TemplateSetAssociation> finalObj = Collections.unmodifiableList( returnObj );
|
|
|
- defaultValues = ( ) -> finalObj;
|
|
|
- }
|
|
|
return defaultValues.get();
|
|
|
}
|
|
|
|
|
@@ -1370,132 +1344,22 @@ public enum PwmSetting
|
|
|
return Collections.unmodifiableMap( returnObj );
|
|
|
}
|
|
|
|
|
|
- public Map<String, String> getOptions( )
|
|
|
- {
|
|
|
- if ( options == null )
|
|
|
- {
|
|
|
- final Map<String, String> returnList = new LinkedHashMap<>();
|
|
|
- final XmlElement settingElement = PwmSettingXml.readSettingXml( this );
|
|
|
- final XmlElement optionsElement = settingElement.getChild( "options" );
|
|
|
- if ( optionsElement != null )
|
|
|
- {
|
|
|
- final List<XmlElement> optionElements = optionsElement.getChildren( "option" );
|
|
|
- if ( optionElements != null )
|
|
|
- {
|
|
|
- for ( final XmlElement optionElement : optionElements )
|
|
|
- {
|
|
|
- if ( optionElement.getAttributeValue( "value" ) == null )
|
|
|
- {
|
|
|
- throw new IllegalStateException( "option element is missing 'value' attribute for key " + this.getKey() );
|
|
|
- }
|
|
|
- returnList.put( optionElement.getAttributeValue( "value" ), optionElement.getText() );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- final Map<String, String> finalList = Collections.unmodifiableMap( returnList );
|
|
|
- options = ( ) -> Collections.unmodifiableMap( finalList );
|
|
|
- }
|
|
|
-
|
|
|
- return options.get( );
|
|
|
- }
|
|
|
-
|
|
|
public Map<PwmSettingProperty, String> getProperties( )
|
|
|
{
|
|
|
- if ( properties == null )
|
|
|
- {
|
|
|
- final Map<PwmSettingProperty, String> newProps = new LinkedHashMap<>();
|
|
|
- final XmlElement settingElement = PwmSettingXml.readSettingXml( this );
|
|
|
- final XmlElement propertiesElement = settingElement.getChild( "properties" );
|
|
|
- if ( propertiesElement != null )
|
|
|
- {
|
|
|
- final List<XmlElement> propertyElements = propertiesElement.getChildren( "property" );
|
|
|
- if ( propertyElements != null )
|
|
|
- {
|
|
|
- for ( final XmlElement propertyElement : propertyElements )
|
|
|
- {
|
|
|
- if ( propertyElement.getAttributeValue( "key" ) == null )
|
|
|
- {
|
|
|
- throw new IllegalStateException( "property element is missing 'key' attribute for value " + this.getKey() );
|
|
|
- }
|
|
|
- final PwmSettingProperty property = JavaHelper.readEnumFromString( PwmSettingProperty.class, null, propertyElement.getAttributeValue( "key" ) );
|
|
|
- if ( property == null )
|
|
|
- {
|
|
|
- throw new IllegalStateException( "property element has unknown 'key' attribute for value " + this.getKey() );
|
|
|
- }
|
|
|
- newProps.put( property, propertyElement.getText() );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- final Map<PwmSettingProperty, String> finalProps = Collections.unmodifiableMap( newProps );
|
|
|
- properties = ( ) -> finalProps;
|
|
|
- }
|
|
|
-
|
|
|
return properties.get();
|
|
|
}
|
|
|
|
|
|
public Collection<PwmSettingFlag> getFlags( )
|
|
|
{
|
|
|
- if ( flags == null )
|
|
|
- {
|
|
|
- final Collection<PwmSettingFlag> returnObj = new ArrayList<>();
|
|
|
- final XmlElement settingElement = PwmSettingXml.readSettingXml( this );
|
|
|
- final List<XmlElement> flagElements = settingElement.getChildren( "flag" );
|
|
|
- for ( final XmlElement flagElement : flagElements )
|
|
|
- {
|
|
|
- final String value = flagElement.getTextTrim();
|
|
|
-
|
|
|
- try
|
|
|
- {
|
|
|
- final PwmSettingFlag flag = PwmSettingFlag.valueOf( value );
|
|
|
- returnObj.add( flag );
|
|
|
- }
|
|
|
- catch ( IllegalArgumentException e )
|
|
|
- {
|
|
|
- LOGGER.error( "unknown flag for setting " + this.getKey() + ", error: unknown flag value: " + value );
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- final Collection<PwmSettingFlag> finalObj = Collections.unmodifiableCollection( returnObj );
|
|
|
- flags = ( ) -> finalObj;
|
|
|
- }
|
|
|
return flags.get();
|
|
|
}
|
|
|
|
|
|
- public Collection<LDAPPermissionInfo> getLDAPPermissionInfo( )
|
|
|
+ public Map<String, String> getOptions()
|
|
|
{
|
|
|
- if ( ldapPermissionInfo == null )
|
|
|
- {
|
|
|
- final XmlElement settingElement = PwmSettingXml.readSettingXml( this );
|
|
|
- final List<XmlElement> permissionElements = settingElement.getChildren( PwmSettingXml.XML_ELEMENT_LDAP_PERMISSION );
|
|
|
- final List<LDAPPermissionInfo> returnObj = new ArrayList<>();
|
|
|
- if ( permissionElements != null )
|
|
|
- {
|
|
|
- for ( final XmlElement permissionElement : permissionElements )
|
|
|
- {
|
|
|
- final LDAPPermissionInfo.Actor actor = JavaHelper.readEnumFromString(
|
|
|
- LDAPPermissionInfo.Actor.class,
|
|
|
- null,
|
|
|
- permissionElement.getAttributeValue( PwmSettingXml.XML_ATTRIBUTE_PERMISSION_ACTOR )
|
|
|
- );
|
|
|
- final LDAPPermissionInfo.Access type = JavaHelper.readEnumFromString(
|
|
|
- LDAPPermissionInfo.Access.class,
|
|
|
- null,
|
|
|
- permissionElement.getAttributeValue( PwmSettingXml.XML_ATTRIBUTE_PERMISSION_ACCESS )
|
|
|
- );
|
|
|
- if ( actor != null && type != null )
|
|
|
- {
|
|
|
- final LDAPPermissionInfo permissionInfo = new LDAPPermissionInfo( type, actor );
|
|
|
- returnObj.add( permissionInfo );
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- final List<LDAPPermissionInfo> finalObj = Collections.unmodifiableList( returnObj );
|
|
|
- ldapPermissionInfo = ( ) -> finalObj;
|
|
|
- }
|
|
|
-
|
|
|
- return ldapPermissionInfo.get();
|
|
|
+ return options.get();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public String getLabel( final Locale locale )
|
|
|
{
|
|
|
final String propertyKey = password.pwm.i18n.PwmSetting.SETTING_LABEL_PREFIX + this.getKey();
|
|
@@ -1512,94 +1376,27 @@ public enum PwmSetting
|
|
|
|
|
|
public String getExample( final PwmSettingTemplateSet template )
|
|
|
{
|
|
|
- if ( examples == null )
|
|
|
- {
|
|
|
- final List<TemplateSetAssociation> returnObj = new ArrayList<>();
|
|
|
- final MacroMachine macroMachine = MacroMachine.forStatic();
|
|
|
- final XmlElement settingElement = PwmSettingXml.readSettingXml( this );
|
|
|
- final List<XmlElement> exampleElements = settingElement.getChildren( PwmSettingXml.XML_ELEMENT_EXAMPLE );
|
|
|
- for ( final XmlElement exampleElement : exampleElements )
|
|
|
- {
|
|
|
- final Set<PwmSettingTemplate> definedTemplates = PwmSettingXml.parseTemplateAttribute( exampleElement );
|
|
|
- final String exampleString = macroMachine.expandMacros( exampleElement.getText() );
|
|
|
- returnObj.add( new TemplateSetAssociation( exampleString, Collections.unmodifiableSet( definedTemplates ) ) );
|
|
|
- }
|
|
|
- if ( returnObj.isEmpty() )
|
|
|
- {
|
|
|
- returnObj.add( new TemplateSetAssociation( "", Collections.emptySet() ) );
|
|
|
- }
|
|
|
- final List<TemplateSetAssociation> exampleOutput = Collections.unmodifiableList( returnObj );
|
|
|
- examples = ( ) -> exampleOutput;
|
|
|
- }
|
|
|
-
|
|
|
return ( String ) associationForTempleSet( examples.get(), template ).getObject();
|
|
|
}
|
|
|
|
|
|
public boolean isRequired( )
|
|
|
{
|
|
|
- if ( required == null )
|
|
|
- {
|
|
|
- final XmlElement settingElement = PwmSettingXml.readSettingXml( this );
|
|
|
- final String requiredAttribute = settingElement.getAttributeValue( "required" );
|
|
|
- final boolean requiredOutput = requiredAttribute != null && "true".equalsIgnoreCase( requiredAttribute );
|
|
|
- required = ( ) -> requiredOutput;
|
|
|
- }
|
|
|
return required.get();
|
|
|
}
|
|
|
|
|
|
public boolean isHidden( )
|
|
|
{
|
|
|
- if ( hidden == null )
|
|
|
- {
|
|
|
- final XmlElement settingElement = PwmSettingXml.readSettingXml( this );
|
|
|
- final String requiredAttribute = settingElement.getAttributeValue( "hidden" );
|
|
|
- final boolean outputHidden = requiredAttribute != null && "true".equalsIgnoreCase( requiredAttribute ) || this.getCategory().isHidden();
|
|
|
- hidden = ( ) -> outputHidden;
|
|
|
- }
|
|
|
return hidden.get();
|
|
|
}
|
|
|
|
|
|
public int getLevel( )
|
|
|
{
|
|
|
- if ( level == null )
|
|
|
- {
|
|
|
- final XmlElement settingElement = PwmSettingXml.readSettingXml( this );
|
|
|
- final String levelAttribute = settingElement.getAttributeValue( "level" );
|
|
|
- final int outputLevel = levelAttribute != null ? Integer.parseInt( levelAttribute ) : 0;
|
|
|
- level = ( ) -> outputLevel;
|
|
|
- }
|
|
|
return level.get();
|
|
|
}
|
|
|
|
|
|
public Pattern getRegExPattern( )
|
|
|
{
|
|
|
- if ( pattern == null )
|
|
|
- {
|
|
|
- final XmlElement settingNode = PwmSettingXml.readSettingXml( this );
|
|
|
- final XmlElement regexNode = settingNode.getChild( "regex" );
|
|
|
- if ( regexNode != null )
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- final Pattern output = Pattern.compile( regexNode.getText() );
|
|
|
- pattern = ( ) -> output;
|
|
|
- }
|
|
|
- catch ( PatternSyntaxException e )
|
|
|
- {
|
|
|
- final String errorMsg = "error compiling regex constraints for setting " + this.toString() + ", error: " + e.getMessage();
|
|
|
- LOGGER.error( errorMsg, e );
|
|
|
- throw new IllegalStateException( errorMsg, e );
|
|
|
- }
|
|
|
- }
|
|
|
- if ( pattern == null )
|
|
|
- {
|
|
|
- final Pattern output = Pattern.compile( ".*", Pattern.DOTALL );
|
|
|
- pattern = ( ) -> output;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
return pattern.get();
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public static PwmSetting forKey( final String key )
|
|
@@ -1619,6 +1416,11 @@ public enum PwmSetting
|
|
|
return this.getCategory().toMenuLocationDebug( profileID, locale ) + separator + this.getLabel( locale );
|
|
|
}
|
|
|
|
|
|
+ public Collection<LDAPPermissionInfo> getLDAPPermissionInfo()
|
|
|
+ {
|
|
|
+ return ldapPermissionInfo.get();
|
|
|
+ }
|
|
|
+
|
|
|
public enum SettingStat
|
|
|
{
|
|
|
Total,
|
|
@@ -1658,26 +1460,11 @@ public enum PwmSetting
|
|
|
return returnObj;
|
|
|
}
|
|
|
|
|
|
+ @Value
|
|
|
public static class TemplateSetAssociation
|
|
|
{
|
|
|
private final Object object;
|
|
|
private final Set<PwmSettingTemplate> settingTemplates;
|
|
|
-
|
|
|
- TemplateSetAssociation( final Object association, final Set<PwmSettingTemplate> settingTemplates )
|
|
|
- {
|
|
|
- this.object = association;
|
|
|
- this.settingTemplates = settingTemplates;
|
|
|
- }
|
|
|
-
|
|
|
- public Object getObject( )
|
|
|
- {
|
|
|
- return object;
|
|
|
- }
|
|
|
-
|
|
|
- Set<PwmSettingTemplate> getSettingTemplates( )
|
|
|
- {
|
|
|
- return settingTemplates;
|
|
|
- }
|
|
|
}
|
|
|
|
|
|
private static TemplateSetAssociation associationForTempleSet(
|
|
@@ -1711,5 +1498,201 @@ public enum PwmSetting
|
|
|
|
|
|
return associationSets.iterator().next();
|
|
|
}
|
|
|
-}
|
|
|
|
|
|
+ static class PwmSettingReader
|
|
|
+ {
|
|
|
+
|
|
|
+ private static Collection<PwmSettingFlag> readFlags( final PwmSetting pwmSetting )
|
|
|
+ {
|
|
|
+ final Collection<PwmSettingFlag> returnObj = new ArrayList<>();
|
|
|
+ final XmlElement settingElement = PwmSettingXml.readSettingXml( pwmSetting );
|
|
|
+ final List<XmlElement> flagElements = settingElement.getChildren( "flag" );
|
|
|
+ for ( final XmlElement flagElement : flagElements )
|
|
|
+ {
|
|
|
+ final String value = flagElement.getTextTrim();
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ final PwmSettingFlag flag = PwmSettingFlag.valueOf( value );
|
|
|
+ returnObj.add( flag );
|
|
|
+ }
|
|
|
+ catch ( final IllegalArgumentException e )
|
|
|
+ {
|
|
|
+ LOGGER.error( "unknown flag for setting " + pwmSetting.getKey() + ", error: unknown flag value: " + value );
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ return Collections.unmodifiableCollection( returnObj );
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<String, String> readOptions( final PwmSetting pwmSetting )
|
|
|
+ {
|
|
|
+ final Map<String, String> returnList = new LinkedHashMap<>();
|
|
|
+ final XmlElement settingElement = PwmSettingXml.readSettingXml( pwmSetting );
|
|
|
+ final XmlElement optionsElement = settingElement.getChild( PwmSettingXml.XML_ELEMENT_OPTIONS );
|
|
|
+ if ( optionsElement != null )
|
|
|
+ {
|
|
|
+ final List<XmlElement> optionElements = optionsElement.getChildren( PwmSettingXml.XML_ELEMENT_OPTION );
|
|
|
+ if ( optionElements != null )
|
|
|
+ {
|
|
|
+ for ( final XmlElement optionElement : optionElements )
|
|
|
+ {
|
|
|
+ if ( optionElement.getAttributeValue( PwmSettingXml.XML_ELEMENT_VALUE ) == null )
|
|
|
+ {
|
|
|
+ throw new IllegalStateException( "option element is missing 'value' attribute for key " + pwmSetting.getKey() );
|
|
|
+ }
|
|
|
+ returnList.put( optionElement.getAttributeValue( PwmSettingXml.XML_ELEMENT_VALUE ), optionElement.getText() );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ final Map<String, String> finalList = Collections.unmodifiableMap( returnList );
|
|
|
+ return Collections.unmodifiableMap( finalList );
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Collection<LDAPPermissionInfo> readLdapPermissionInfo( final PwmSetting pwmSetting )
|
|
|
+ {
|
|
|
+ final XmlElement settingElement = PwmSettingXml.readSettingXml( pwmSetting );
|
|
|
+ final List<XmlElement> permissionElements = settingElement.getChildren( PwmSettingXml.XML_ELEMENT_LDAP_PERMISSION );
|
|
|
+ final List<LDAPPermissionInfo> returnObj = new ArrayList<>();
|
|
|
+ if ( permissionElements != null )
|
|
|
+ {
|
|
|
+ for ( final XmlElement permissionElement : permissionElements )
|
|
|
+ {
|
|
|
+ final LDAPPermissionInfo.Actor actor = JavaHelper.readEnumFromString(
|
|
|
+ LDAPPermissionInfo.Actor.class,
|
|
|
+ null,
|
|
|
+ permissionElement.getAttributeValue( PwmSettingXml.XML_ATTRIBUTE_PERMISSION_ACTOR )
|
|
|
+ );
|
|
|
+ final LDAPPermissionInfo.Access type = JavaHelper.readEnumFromString(
|
|
|
+ LDAPPermissionInfo.Access.class,
|
|
|
+ null,
|
|
|
+ permissionElement.getAttributeValue( PwmSettingXml.XML_ATTRIBUTE_PERMISSION_ACCESS )
|
|
|
+ );
|
|
|
+ if ( actor != null && type != null )
|
|
|
+ {
|
|
|
+ final LDAPPermissionInfo permissionInfo = new LDAPPermissionInfo( type, actor );
|
|
|
+ returnObj.add( permissionInfo );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Collections.unmodifiableList( returnObj );
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<TemplateSetAssociation> readExamples( final PwmSetting pwmSetting )
|
|
|
+ {
|
|
|
+ final List<TemplateSetAssociation> returnObj = new ArrayList<>();
|
|
|
+ final MacroMachine macroMachine = MacroMachine.forStatic();
|
|
|
+ final XmlElement settingElement = PwmSettingXml.readSettingXml( pwmSetting );
|
|
|
+ final List<XmlElement> exampleElements = settingElement.getChildren( PwmSettingXml.XML_ELEMENT_EXAMPLE );
|
|
|
+ for ( final XmlElement exampleElement : exampleElements )
|
|
|
+ {
|
|
|
+ final Set<PwmSettingTemplate> definedTemplates = PwmSettingXml.parseTemplateAttribute( exampleElement );
|
|
|
+ final String exampleString = macroMachine.expandMacros( exampleElement.getText() );
|
|
|
+ returnObj.add( new TemplateSetAssociation( exampleString, Collections.unmodifiableSet( definedTemplates ) ) );
|
|
|
+ }
|
|
|
+ if ( returnObj.isEmpty() )
|
|
|
+ {
|
|
|
+ returnObj.add( new TemplateSetAssociation( "", Collections.emptySet() ) );
|
|
|
+ }
|
|
|
+ return Collections.unmodifiableList( returnObj );
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Map<PwmSettingProperty, String> readProperties( final PwmSetting pwmSetting )
|
|
|
+ {
|
|
|
+ final Map<PwmSettingProperty, String> newProps = new LinkedHashMap<>();
|
|
|
+ final XmlElement settingElement = PwmSettingXml.readSettingXml( pwmSetting );
|
|
|
+ final XmlElement propertiesElement = settingElement.getChild( PwmSettingXml.XML_ELEMENT_PROPERTIES );
|
|
|
+ if ( propertiesElement != null )
|
|
|
+ {
|
|
|
+ final List<XmlElement> propertyElements = propertiesElement.getChildren( PwmSettingXml.XML_ELEMENT_PROPERTY );
|
|
|
+ if ( propertyElements != null )
|
|
|
+ {
|
|
|
+ for ( final XmlElement propertyElement : propertyElements )
|
|
|
+ {
|
|
|
+ if ( propertyElement.getAttributeValue( PwmSettingXml.XML_ATTRIBUTE_KEY ) == null )
|
|
|
+ {
|
|
|
+ throw new IllegalStateException( "property element is missing 'key' attribute for value " + pwmSetting.getKey() );
|
|
|
+ }
|
|
|
+ final PwmSettingProperty property = JavaHelper.readEnumFromString(
|
|
|
+ PwmSettingProperty.class,
|
|
|
+ null,
|
|
|
+ propertyElement.getAttributeValue( PwmSettingXml.XML_ATTRIBUTE_KEY ) );
|
|
|
+ if ( property == null )
|
|
|
+ {
|
|
|
+ throw new IllegalStateException( "property element has unknown 'key' attribute for value " + pwmSetting.getKey() );
|
|
|
+ }
|
|
|
+ newProps.put( property, propertyElement.getText() );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Collections.unmodifiableMap( newProps );
|
|
|
+ }
|
|
|
+
|
|
|
+ private static List<TemplateSetAssociation> readDefaultValue( final PwmSetting pwmSetting )
|
|
|
+ {
|
|
|
+ final List<TemplateSetAssociation> returnObj = new ArrayList<>();
|
|
|
+ final XmlElement settingElement = PwmSettingXml.readSettingXml( pwmSetting );
|
|
|
+ final List<XmlElement> defaultElements = settingElement.getChildren( PwmSettingXml.XML_ELEMENT_DEFAULT );
|
|
|
+ if ( pwmSetting.getSyntax() == PwmSettingSyntax.PASSWORD )
|
|
|
+ {
|
|
|
+ returnObj.add( new TemplateSetAssociation( new PasswordValue( null ), Collections.emptySet() ) );
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ for ( final XmlElement defaultElement : defaultElements )
|
|
|
+ {
|
|
|
+ final Set<PwmSettingTemplate> definedTemplates = PwmSettingXml.parseTemplateAttribute( defaultElement );
|
|
|
+ final StoredValue storedValue = ValueFactory.fromXmlValues( pwmSetting, defaultElement, null );
|
|
|
+ returnObj.add( new TemplateSetAssociation( storedValue, definedTemplates ) );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ( returnObj.isEmpty() )
|
|
|
+ {
|
|
|
+ throw new IllegalStateException( "no default value for setting " + pwmSetting.getKey() );
|
|
|
+ }
|
|
|
+ return Collections.unmodifiableList( returnObj );
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private static boolean readRequired( final PwmSetting pwmSetting )
|
|
|
+ {
|
|
|
+ final XmlElement settingElement = PwmSettingXml.readSettingXml( pwmSetting );
|
|
|
+ final String requiredAttribute = settingElement.getAttributeValue( PwmSettingXml.XML_ELEMENT_REQUIRED );
|
|
|
+ return "true".equalsIgnoreCase( requiredAttribute );
|
|
|
+ }
|
|
|
+
|
|
|
+ private static boolean readHidden( final PwmSetting pwmSetting )
|
|
|
+ {
|
|
|
+ final XmlElement settingElement = PwmSettingXml.readSettingXml( pwmSetting );
|
|
|
+ final String requiredAttribute = settingElement.getAttributeValue( PwmSettingXml.XML_ELEMENT_HIDDEN );
|
|
|
+ return "true".equalsIgnoreCase( requiredAttribute ) || pwmSetting.getCategory().isHidden();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static int readLevel( final PwmSetting pwmSetting )
|
|
|
+ {
|
|
|
+ final XmlElement settingElement = PwmSettingXml.readSettingXml( pwmSetting );
|
|
|
+ final String levelAttribute = settingElement.getAttributeValue( PwmSettingXml.XML_ELEMENT_LEVEL );
|
|
|
+ return JavaHelper.silentParseInt( levelAttribute, 0 );
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Pattern readPattern( final PwmSetting pwmSetting )
|
|
|
+ {
|
|
|
+ final XmlElement settingNode = PwmSettingXml.readSettingXml( pwmSetting );
|
|
|
+ final XmlElement regexNode = settingNode.getChild( PwmSettingXml.XML_ELEMENT_REGEX );
|
|
|
+ if ( regexNode != null )
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ return Pattern.compile( regexNode.getText() );
|
|
|
+ }
|
|
|
+ catch ( final PatternSyntaxException e )
|
|
|
+ {
|
|
|
+ final String errorMsg = "error compiling regex constraints for setting " + pwmSetting.toString() + ", error: " + e.getMessage();
|
|
|
+ LOGGER.error( errorMsg, e );
|
|
|
+ throw new IllegalStateException( errorMsg, e );
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return Pattern.compile( ".*", Pattern.DOTALL );
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|