Explorar el Código

add directory_server_389 ldap template to settings xml.

Jason Rivard hace 3 años
padre
commit
1c756672fa

+ 22 - 3
server/src/main/java/password/pwm/config/PwmSettingTemplate.java

@@ -26,6 +26,7 @@ import password.pwm.util.java.JavaHelper;
 import java.util.EnumMap;
 import java.util.Map;
 import java.util.Optional;
+import java.util.Set;
 
 public enum PwmSettingTemplate
 {
@@ -34,6 +35,7 @@ public enum PwmSettingTemplate
     ORACLE_DS( Type.LDAP_VENDOR ),
     DEFAULT( Type.LDAP_VENDOR ),
     NOVL_IDM( Type.LDAP_VENDOR ),
+    DIRECTORY_SERVER_389( Type.LDAP_VENDOR ),
     OPEN_LDAP( Type.LDAP_VENDOR ),
 
     LOCALDB( Type.STORAGE ),
@@ -78,11 +80,28 @@ public enum PwmSettingTemplate
         return element;
     }
 
+    public static Set<PwmSettingTemplate> valuesForType( final Type type )
+    {
+        return JavaHelper.readEnumsFromPredicate( PwmSettingTemplate.class, t -> t.getType() == type );
+    }
+
     public enum Type
     {
-        LDAP_VENDOR,
-        STORAGE,
-        DB_VENDOR,;
+        LDAP_VENDOR( PwmSetting.TEMPLATE_LDAP ),
+        STORAGE( PwmSetting.TEMPLATE_STORAGE ),
+        DB_VENDOR( PwmSetting.DB_VENDOR_TEMPLATE ),;
+
+        private final PwmSetting pwmSetting;
+
+        Type( final PwmSetting pwmSetting )
+        {
+            this.pwmSetting = pwmSetting;
+        }
+
+        public PwmSetting getPwmSetting()
+        {
+            return pwmSetting;
+        }
 
         // done using map instead of static values to avoid initialization circularity bug
         public PwmSettingTemplate getDefaultValue( )

+ 1 - 1
server/src/main/java/password/pwm/config/stored/StoredConfigurationModifier.java

@@ -187,7 +187,7 @@ public class StoredConfigurationModifier
         } );
     }
 
-    public int modifications()
+    public int modificationCount()
     {
         return modifications.get();
     }

+ 1 - 1
server/src/main/java/password/pwm/config/stored/StoredConfigurationUtil.java

@@ -495,7 +495,7 @@ public abstract class StoredConfigurationUtil
             modifier.writeSetting( key, value, userIdentity );
         }
 
-        LOGGER.trace( () -> "copied " + modifier.modifications() + " domain settings from '" + source + "' to '" + destination + "' domain",
+        LOGGER.trace( () -> "copied " + modifier.modificationCount() + " domain settings from '" + source + "' to '" + destination + "' domain",
                 () -> TimeDuration.fromCurrent( startTime ) );
 
         return modifier.newStoredConfiguration();

+ 10 - 1
server/src/main/resources/password/pwm/config/PwmSetting.xml

@@ -30,11 +30,12 @@
             <value>DEFAULT</value>
         </default>
         <options>
+            <option value="DIRECTORY_SERVER_389">389 Directory Server</option>
             <option value="AD">Microsoft Active Directory</option>
-            <option value="ORACLE_DS">Oracle Directory Server</option>
             <option value="NOVL">NetIQ eDirectory</option>
             <option value="NOVL_IDM">NetIQ IDM / OAuth Integration</option>
             <option value="OPEN_LDAP">OpenLDAP</option>
+            <option value="ORACLE_DS">Oracle Directory Server</option>
             <option value="DEFAULT">Others</option>
         </options>
         <properties>
@@ -550,6 +551,7 @@
         <example template="AD">CN=@PwmAppName@-Proxy,CN=Users,DC=ad,DC=site,DC=example,DC=com</example>
         <example template="ORACLE_DS">cn=@PwmAppName@-Proxy,cn=Administrators,cn=config</example>
         <example template="OPEN_LDAP">cn=@PwmAppName@-Proxy,dc=example,dc=com</example>
+        <example template="DIRECTORY_SERVER_389">cn=@PwmAppName@-Proxy,dc=example,dc=com</example>
         <default/>
     </setting>
     <setting hidden="false" key="ldap.proxy.password" level="0">
@@ -570,6 +572,7 @@
         <example template="AD">CN=@PwmAppName@-Testuser,CN=Users,DC=ad,DC=site,DC=example,DC=com</example>
         <example template="ORACLE_DS">cn=@PwmAppName@-Testuser,cn=Administrators,cn=config</example>
         <example template="OPEN_LDAP">cn=@PwmAppName@-Testuser,dc=example,dc=com</example>
+        <example template="DIRECTORY_SERVER_389">cn=@PwmAppName@-Testuser,dc=example,dc=com</example>
         <default>
             <value />
         </default>
@@ -640,6 +643,9 @@
         <default template="OPEN_LDAP">
             <value>memberof</value>
         </default>
+        <default template="DIRECTORY_SERVER_389">
+            <value>memberof</value>
+        </default>
     </setting>
     <setting hidden="true" key="ldap.group.label.attribute" level="2">
         <default>
@@ -666,6 +672,9 @@
         <default template="OPEN_LDAP">
             <value><![CDATA[entryuuid]]></value>
         </default>
+        <default template="DIRECTORY_SERVER_389">
+            <value><![CDATA[uidNumber]]></value>
+        </default>
     </setting>
     <setting hidden="false" key="ldap.namingAttribute" level="1" required="true">
         <ldapPermission actor="proxy" access="read"/>

+ 65 - 0
server/src/test/java/password/pwm/config/PwmSettingTemplateTest.java

@@ -0,0 +1,65 @@
+/*
+ * Password Management Servlets (PWM)
+ * http://www.pwm-project.org
+ *
+ * Copyright (c) 2006-2009 Novell, Inc.
+ * Copyright (c) 2009-2021 The PWM Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package password.pwm.config;
+
+import org.junit.Assert;
+import org.junit.Test;
+import password.pwm.util.java.JavaHelper;
+
+import java.util.EnumSet;
+import java.util.Set;
+
+public class PwmSettingTemplateTest
+{
+    @Test
+    public void testPwmSettingTemplateEnums() throws Exception
+    {
+        {
+            for ( final PwmSettingTemplate.Type type : PwmSettingTemplate.Type.values() )
+            {
+                final Set<PwmSettingTemplate> seenTemplatesOfType = EnumSet.noneOf( PwmSettingTemplate.class );
+                final PwmSetting associatedSetting = type.getPwmSetting();
+                final Set<String> xmlValues = associatedSetting.getOptions().keySet();
+                final Set<PwmSettingTemplate> enumValues = PwmSettingTemplate.valuesForType( type );
+
+                for ( final String xmlValue : xmlValues )
+                {
+                    final PwmSettingTemplate pwmSettingTemplate = JavaHelper.readEnumFromString( PwmSettingTemplate.class, xmlValue )
+                            .orElseThrow( () -> new IllegalStateException(
+                                    "PwmSetting.xml has option value '" + xmlValue
+                                            + "' for " + associatedSetting
+                                            + " not declared as PwmSettingTemplate enum value" ) );
+                    seenTemplatesOfType.add( pwmSettingTemplate );
+
+                }
+
+                for ( final PwmSettingTemplate enumValue : enumValues )
+                {
+                    if ( !seenTemplatesOfType.contains( enumValue ) )
+                    {
+                        Assert.fail( "PwmSettingTemplate enum value " + enumValue
+                                + " is missing corresponding option value in setting " + associatedSetting );
+                    }
+                }
+            }
+        }
+    }
+}