فهرست منبع

generify ldap vendor enums

Jason Rivard 7 سال پیش
والد
کامیت
fba5dbc8f5

+ 2 - 2
server/src/main/java/password/pwm/bean/TelemetryPublishBean.java

@@ -22,9 +22,9 @@
 
 package password.pwm.bean;
 
-import com.novell.ldapchai.provider.DirectoryVendor;
 import lombok.Builder;
 import lombok.Getter;
+import password.pwm.ldap.PwmLdapVendor;
 
 import java.io.Serializable;
 import java.time.Instant;
@@ -39,7 +39,7 @@ public class TelemetryPublishBean implements Serializable {
     private final String instanceHash;
     private final String siteDescription;
     private final Instant installTime;
-    private final List<DirectoryVendor> ldapVendor;
+    private final List<PwmLdapVendor> ldapVendor;
     private final Map<String,String> statistics;
     private final List<String> configuredSettings;
     private final String versionBuild;

+ 53 - 0
server/src/main/java/password/pwm/ldap/PwmLdapVendor.java

@@ -0,0 +1,53 @@
+package password.pwm.ldap;
+
+import com.novell.ldapchai.provider.DirectoryVendor;
+
+public enum PwmLdapVendor {
+    ACTIVE_DIRECTORY(DirectoryVendor.ACTIVE_DIRECTORY, "MICROSOFT_ACTIVE_DIRECTORY"),
+    EDIRECTORY(DirectoryVendor.EDIRECTORY, "NOVELL_EDIRECTORY"),
+    OPEN_LDAP(DirectoryVendor.OPEN_LDAP),
+    DIRECTORY_SERVER_389(DirectoryVendor.DIRECTORY_SERVER_389),
+    ORACLE_DS(DirectoryVendor.ORACLE_DS),
+    GENERIC(DirectoryVendor.GENERIC),
+
+    ;
+
+    private final DirectoryVendor chaiVendor;
+    private final String[] otherNames;
+
+    PwmLdapVendor( final DirectoryVendor directoryVendor, final String... otherNames ) {
+        this.chaiVendor = directoryVendor;
+        this.otherNames = otherNames;
+    }
+
+    public static PwmLdapVendor fromString(final String input) {
+        if (input == null) {
+            return null;
+        }
+
+        for (PwmLdapVendor vendor : PwmLdapVendor.values()) {
+            if ( vendor.name().equals( input ) ) {
+                return vendor;
+            }
+
+            if (vendor.otherNames != null) {
+                for (final String otherName : vendor.otherNames) {
+                    if (otherName.equals( input )) {
+                        return vendor;
+                    }
+                }
+            }
+        }
+
+        return null;
+    }
+
+    public static PwmLdapVendor fromChaiVendor(final DirectoryVendor directoryVendor) {
+        for (PwmLdapVendor vendor : PwmLdapVendor.values()) {
+            if (vendor.chaiVendor == directoryVendor) {
+                return vendor;
+            }
+        }
+        return null;
+    }
+}

+ 5 - 2
server/src/main/java/password/pwm/svc/telemetry/TelemetryService.java

@@ -40,6 +40,7 @@ import password.pwm.error.PwmError;
 import password.pwm.error.PwmException;
 import password.pwm.error.PwmUnrecoverableException;
 import password.pwm.health.HealthRecord;
+import password.pwm.ldap.PwmLdapVendor;
 import password.pwm.svc.PwmService;
 import password.pwm.svc.stats.Statistic;
 import password.pwm.svc.stats.StatisticsBundle;
@@ -258,10 +259,12 @@ public class TelemetryService implements PwmService {
             }
         }
 
-        final Set<DirectoryVendor> ldapVendors = new LinkedHashSet<>();
+        final Set<PwmLdapVendor> ldapVendors = new LinkedHashSet<>();
         for (final LdapProfile ldapProfile : config.getLdapProfiles().values()) {
             try {
-                ldapVendors.add(ldapProfile.getProxyChaiProvider(pwmApplication).getDirectoryVendor());
+                final DirectoryVendor directoryVendor = ldapProfile.getProxyChaiProvider(pwmApplication).getDirectoryVendor();
+                final PwmLdapVendor pwmLdapVendor = PwmLdapVendor.fromChaiVendor(directoryVendor);
+                ldapVendors.add(pwmLdapVendor);
             } catch (Exception e) {
                 LOGGER.trace(SessionLabel.TELEMETRY_SESSION_LABEL, "unable to read ldap vendor type for stats publication: " + e.getMessage());
             }

+ 11 - 0
server/src/main/java/password/pwm/util/java/JsonUtil.java

@@ -33,6 +33,7 @@ import com.google.gson.JsonSerializationContext;
 import com.google.gson.JsonSerializer;
 import com.google.gson.reflect.TypeToken;
 import password.pwm.error.PwmUnrecoverableException;
+import password.pwm.ldap.PwmLdapVendor;
 import password.pwm.util.PasswordData;
 import password.pwm.util.logging.PwmLogger;
 
@@ -259,6 +260,16 @@ public class JsonUtil {
 
     }
 
+    private static class PwmLdapVendorTypeAdaptor implements JsonSerializer<PwmLdapVendor>, JsonDeserializer<PwmLdapVendor> {
+        public PwmLdapVendor deserialize(final JsonElement json, final Type typeOfT, final JsonDeserializationContext context) throws JsonParseException {
+                return PwmLdapVendor.fromString( json.getAsString() );
+        }
+
+        public JsonElement serialize(final PwmLdapVendor src, final Type typeOfSrc, final JsonSerializationContext context) {
+                return new JsonPrimitive(src.name());
+        }
+    }
+
     private static GsonBuilder registerTypeAdapters(final GsonBuilder gsonBuilder) {
         gsonBuilder.registerTypeAdapter(Date.class, new DateTypeAdapter());
         gsonBuilder.registerTypeAdapter(Instant.class, new InstantTypeAdapter());