diff --git a/src/main/java/org/codelibs/fess/ldap/LdapManager.java b/src/main/java/org/codelibs/fess/ldap/LdapManager.java index 25953be20..5f4493487 100644 --- a/src/main/java/org/codelibs/fess/ldap/LdapManager.java +++ b/src/main/java/org/codelibs/fess/ldap/LdapManager.java @@ -295,11 +295,15 @@ public class LdapManager { start += 3; final int end = entryDn.indexOf(',', start); - if (end == -1) { - return entryDn.substring(start); - } else { - return entryDn.substring(start, end); + final String value = end == -1 ? entryDn.substring(start) : entryDn.substring(start, end); + if (fessConfig.isLdapGroupNameWithUnderscores()) { + return replaceWithUnderscores(value); } + return value; + } + + protected String replaceWithUnderscores(final String value) { + return value.replaceAll("[/\\\\\\[\\]:;|=,+\\*?<>]", "_"); } protected void setAttributeValue(final List result, final String name, final Consumer consumer) { diff --git a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java index 057f7285e..d6cf01558 100644 --- a/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java +++ b/src/main/java/org/codelibs/fess/mylasta/direction/FessConfig.java @@ -1433,6 +1433,9 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction /** The key of the configuration. e.g. true */ String LDAP_IGNORE_NETBIOS_NAME = "ldap.ignore.netbios.name"; + /** The key of the configuration. e.g. false */ + String LDAP_GROUP_NAME_WITH_UNDERSCORES = "ldap.group.name.with.underscores"; + /** The key of the configuration. e.g. true */ String LDAP_ROLE_SEARCH_USER_ENABLED = "ldap.role.search.user.enabled"; @@ -6047,6 +6050,20 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction */ boolean isLdapIgnoreNetbiosName(); + /** + * Get the value for the key 'ldap.group.name.with.underscores'.
+ * The value is, e.g. false
+ * @return The value of found property. (NotNull: if not found, exception but basically no way) + */ + String getLdapGroupNameWithUnderscores(); + + /** + * Is the property for the key 'ldap.group.name.with.underscores' true?
+ * The value is, e.g. false
+ * @return The determination, true or false. (if not found, exception but basically no way) + */ + boolean isLdapGroupNameWithUnderscores(); + /** * Get the value for the key 'ldap.role.search.user.enabled'.
* The value is, e.g. true
@@ -8688,6 +8705,14 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction return is(FessConfig.LDAP_IGNORE_NETBIOS_NAME); } + public String getLdapGroupNameWithUnderscores() { + return get(FessConfig.LDAP_GROUP_NAME_WITH_UNDERSCORES); + } + + public boolean isLdapGroupNameWithUnderscores() { + return is(FessConfig.LDAP_GROUP_NAME_WITH_UNDERSCORES); + } + public String getLdapRoleSearchUserEnabled() { return get(FessConfig.LDAP_ROLE_SEARCH_USER_ENABLED); } @@ -9291,6 +9316,7 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction defaultMap.put(FessConfig.LDAP_AUTH_VALIDATION, "true"); defaultMap.put(FessConfig.LDAP_MAX_USERNAME_LENGTH, "-1"); defaultMap.put(FessConfig.LDAP_IGNORE_NETBIOS_NAME, "true"); + defaultMap.put(FessConfig.LDAP_GROUP_NAME_WITH_UNDERSCORES, "false"); defaultMap.put(FessConfig.LDAP_ROLE_SEARCH_USER_ENABLED, "true"); defaultMap.put(FessConfig.LDAP_ROLE_SEARCH_GROUP_ENABLED, "true"); defaultMap.put(FessConfig.LDAP_ROLE_SEARCH_ROLE_ENABLED, "true"); diff --git a/src/main/resources/fess_config.properties b/src/main/resources/fess_config.properties index a65a9fb6e..e42bf4232 100644 --- a/src/main/resources/fess_config.properties +++ b/src/main/resources/fess_config.properties @@ -762,6 +762,7 @@ ldap.admin.sync.password=true ldap.auth.validation=true ldap.max.username.length=-1 ldap.ignore.netbios.name=true +ldap.group.name.with.underscores=false ldap.role.search.user.enabled=true ldap.role.search.group.enabled=true diff --git a/src/test/java/org/codelibs/fess/ldap/LdapManagerTest.java b/src/test/java/org/codelibs/fess/ldap/LdapManagerTest.java index bc72b9964..af97cd292 100644 --- a/src/test/java/org/codelibs/fess/ldap/LdapManagerTest.java +++ b/src/test/java/org/codelibs/fess/ldap/LdapManagerTest.java @@ -27,6 +27,10 @@ public class LdapManagerTest extends UnitFessTestCase { public boolean isLdapIgnoreNetbiosName() { return true; } + + public boolean isLdapGroupNameWithUnderscores() { + return false; + } }); LdapManager ldapManager = new LdapManager(); ldapManager.init(); @@ -45,4 +49,27 @@ public class LdapManagerTest extends UnitFessTestCase { assertNull(ldapManager.getSearchRoleName("aaa")); } + public void test_replaceWithUnderscores() { + LdapManager ldapManager = new LdapManager(); + ldapManager.init(); + + assertEquals("_", ldapManager.replaceWithUnderscores("/")); + assertEquals("_", ldapManager.replaceWithUnderscores("\\")); + assertEquals("_", ldapManager.replaceWithUnderscores("[")); + assertEquals("_", ldapManager.replaceWithUnderscores("]")); + assertEquals("_", ldapManager.replaceWithUnderscores(":")); + assertEquals("_", ldapManager.replaceWithUnderscores(";")); + assertEquals("_", ldapManager.replaceWithUnderscores("|")); + assertEquals("_", ldapManager.replaceWithUnderscores("=")); + assertEquals("_", ldapManager.replaceWithUnderscores(",")); + assertEquals("_", ldapManager.replaceWithUnderscores("+")); + assertEquals("_", ldapManager.replaceWithUnderscores("*")); + assertEquals("_", ldapManager.replaceWithUnderscores("?")); + assertEquals("_", ldapManager.replaceWithUnderscores("<")); + assertEquals("_", ldapManager.replaceWithUnderscores(">")); + + assertEquals("_a_", ldapManager.replaceWithUnderscores("/a/")); + assertEquals("___", ldapManager.replaceWithUnderscores("///")); + assertEquals("a_a", ldapManager.replaceWithUnderscores("a/a")); + } }