diff options
author | James Moger <james.moger@gitblit.com> | 2014-03-31 12:20:58 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-03-31 12:20:58 -0400 |
commit | e5c982fa61f9f1b289d7454bdb92ee3167ee784d (patch) | |
tree | f5437f769337f59875221f347ddb951dfeb7341a | |
parent | beb021472d034617e1ce216aee38d918ae7f1a67 (diff) | |
parent | c30c2b332cf498efef9a01609ff4aa5bd7f8cc14 (diff) | |
download | gitblit-e5c982fa61f9f1b289d7454bdb92ee3167ee784d.tar.gz gitblit-e5c982fa61f9f1b289d7454bdb92ee3167ee784d.zip |
Merge pull request #164 from jaa127/ldap-bind-escape
Ldap bind escape
-rw-r--r-- | src/main/java/com/gitblit/auth/LdapAuthProvider.java | 2 | ||||
-rw-r--r-- | src/test/java/com/gitblit/tests/LdapAuthenticationTest.java | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/src/main/java/com/gitblit/auth/LdapAuthProvider.java b/src/main/java/com/gitblit/auth/LdapAuthProvider.java index 892f30ba..83f24669 100644 --- a/src/main/java/com/gitblit/auth/LdapAuthProvider.java +++ b/src/main/java/com/gitblit/auth/LdapAuthProvider.java @@ -299,7 +299,7 @@ public class LdapAuthProvider extends UsernamePasswordAuthenticationProvider { String bindPattern = settings.getString(Keys.realm.ldap.bindpattern, ""); if (!StringUtils.isEmpty(bindPattern)) { try { - String bindUser = StringUtils.replace(bindPattern, "${username}", simpleUsername); + String bindUser = StringUtils.replace(bindPattern, "${username}", escapeLDAPSearchFilter(simpleUsername)); ldapConnection.bind(bindUser, new String(password)); alreadyAuthenticated = true; diff --git a/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java b/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java index b037754c..21063d58 100644 --- a/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java +++ b/src/test/java/com/gitblit/tests/LdapAuthenticationTest.java @@ -258,6 +258,19 @@ public class LdapAuthenticationTest extends GitblitUnitTest { assertNull(userThreeModel.getTeam("git_admins")); assertTrue(userThreeModel.canAdmin); } + + @Test + public void testBindWithUser() { + settings.put(Keys.realm.ldap.bindpattern, "CN=${username},OU=US,OU=Users,OU=UserControl,OU=MyOrganization,DC=MyDomain"); + settings.put(Keys.realm.ldap.username, ""); + settings.put(Keys.realm.ldap.password, ""); + + UserModel userOneModel = auth.authenticate("UserOne", "userOnePassword".toCharArray()); + assertNotNull(userOneModel); + + UserModel userOneModelFailedAuth = auth.authenticate("UserOne", "userTwoPassword".toCharArray()); + assertNull(userOneModelFailedAuth); + } private int countLdapUsersInUserManager() { int ldapAccountCount = 0; |