浏览代码

SEC-1848: LDAP encode name when using user DN patterns in AbstractLdapAuthenticator.

Luke Taylor 14 年之前
父节点
当前提交
8e1d407e3e

+ 2 - 1
ldap/src/integration-test/java/org/springframework/security/ldap/authentication/BindAuthenticatorTests.java

@@ -55,10 +55,11 @@ public class BindAuthenticatorTests extends AbstractLdapIntegrationTests {
 
     @Test
     public void testAuthenticationWithCorrectPasswordSucceeds() {
-        authenticator.setUserDnPatterns(new String[] {"uid={0},ou=people"});
+        authenticator.setUserDnPatterns(new String[] {"uid={0},ou=people", "cn={0},ou=people"});
 
         DirContextOperations user = authenticator.authenticate(bob);
         assertEquals("bob", user.getStringAttribute("uid"));
+        authenticator.authenticate(new UsernamePasswordAuthenticationToken("mouse, jerry", "jerryspassword"));
     }
 
     @Test

+ 2 - 1
ldap/src/main/java/org/springframework/security/ldap/authentication/AbstractLdapAuthenticator.java

@@ -15,6 +15,7 @@
 
 package org.springframework.security.ldap.authentication;
 
+import org.springframework.ldap.core.LdapEncoder;
 import org.springframework.security.core.SpringSecurityMessageSource;
 import org.springframework.security.ldap.search.LdapUserSearch;
 import org.springframework.beans.factory.InitializingBean;
@@ -91,7 +92,7 @@ public abstract class AbstractLdapAuthenticator implements LdapAuthenticator, In
         }
 
         List<String> userDns = new ArrayList<String>(userDnFormat.length);
-        String[] args = new String[] {username};
+        String[] args = new String[] {LdapEncoder.nameEncode(username)};
 
         synchronized (userDnFormat) {
             for (MessageFormat formatter : userDnFormat) {