Bläddra i källkod

fix #438 : add ldap.max.username.length

Shinsuke Sugaya 9 år sedan
förälder
incheckning
04e28f2d32

+ 26 - 0
src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java

@@ -744,6 +744,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
     /** The key of the configuration. e.g. true */
     String LDAP_ADMIN_SYNC_PASSWORD = "ldap.admin.sync.password";
 
+    /** The key of the configuration. e.g. -1 */
+    String LDAP_MAX_USERNAME_LENGTH = "ldap.max.username.length";
+
     /** The key of the configuration. e.g. memberOf */
     String LDAP_MEMBEROF_ATTRIBUTE = "ldap.memberof.attribute";
 
@@ -3042,6 +3045,21 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
      */
     boolean isLdapAdminSyncPassword();
 
+    /**
+     * Get the value for the key 'ldap.max.username.length'. <br>
+     * The value is, e.g. -1 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     */
+    String getLdapMaxUsernameLength();
+
+    /**
+     * Get the value for the key 'ldap.max.username.length' as {@link Integer}. <br>
+     * The value is, e.g. -1 <br>
+     * @return The value of found property. (NotNull: if not found, exception but basically no way)
+     * @throws NumberFormatException When the property is not integer.
+     */
+    Integer getLdapMaxUsernameLengthAsInteger();
+
     /**
      * Get the value for the key 'ldap.memberof.attribute'. <br>
      * The value is, e.g. memberOf <br>
@@ -4321,6 +4339,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
             return is(FessConfig.LDAP_ADMIN_SYNC_PASSWORD);
         }
 
+        public String getLdapMaxUsernameLength() {
+            return get(FessConfig.LDAP_MAX_USERNAME_LENGTH);
+        }
+
+        public Integer getLdapMaxUsernameLengthAsInteger() {
+            return getAsInteger(FessConfig.LDAP_MAX_USERNAME_LENGTH);
+        }
+
         public String getLdapMemberofAttribute() {
             return get(FessConfig.LDAP_MEMBEROF_ATTRIBUTE);
         }

+ 12 - 1
src/main/java/org/codelibs/fess/mylasta/direction/FessProp.java

@@ -404,8 +404,19 @@ public interface FessProp {
         setSystemProperty(Constants.LDAP_SECURITY_PRINCIPAL, value);
     }
 
+    Integer getLdapMaxUsernameLengthAsInteger();
+
     public default String getLdapSecurityPrincipal(final String username) {
-        return String.format(getSystemProperty(Constants.LDAP_SECURITY_PRINCIPAL, StringUtil.EMPTY), username);
+        final String value;
+        final int maxLength = getLdapMaxUsernameLengthAsInteger().intValue();
+        if (username == null) {
+            value = StringUtil.EMPTY;
+        } else if (maxLength >= 0 && username.length() > maxLength) {
+            value = username.substring(0, maxLength);
+        } else {
+            value = username;
+        }
+        return String.format(getSystemProperty(Constants.LDAP_SECURITY_PRINCIPAL, StringUtil.EMPTY), value);
     }
 
     public default String getLdapSecurityPrincipal() {

+ 1 - 0
src/main/resources/fess_config.properties

@@ -399,6 +399,7 @@ ldap.admin.group.base.dn=ou\=Group,dc\=fess,dc\=codelibs,dc\=org
 ldap.admin.group.object.classes=groupOfNames
 ldap.admin.sync.password=true
 
+ldap.max.username.length=-1
 ldap.memberof.attribute=memberOf
 #ldap.memberof.attribute=isMemberOf