Skip to content

Commit a790c7e

Browse files
committed
SEC-1670: Take account of JNDI CompositeName escaping in value of SearchResult.getName() when performing a search for a user entry in SpringSecurityLdapTemplate.
1 parent 4e34990 commit a790c7e

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

ldap/slapd.conf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ access to dn.subtree="ou=users,dc=qbe,dc=com"
4444
by * read
4545

4646

47-
overlay ppolicy
48-
ppolicy_default "cn=default,ou=policies,dc=springsource,dc=com"
49-
ppolicy_use_lockout
50-
ppolicy_hash_cleartext
47+
#overlay ppolicy
48+
#ppolicy_default "cn=default,ou=policies,dc=springsource,dc=com"
49+
#ppolicy_use_lockout
50+
#ppolicy_hash_cleartext
5151

ldap/src/main/java/org/springframework/security/ldap/SpringSecurityLdapTemplate.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.HashSet;
2121
import java.util.Set;
2222

23+
import javax.naming.CompositeName;
2324
import javax.naming.NamingEnumeration;
2425
import javax.naming.NamingException;
2526
import javax.naming.PartialResultException;
@@ -208,7 +209,7 @@ public Object executeWithContext(DirContext ctx) throws NamingException {
208209
while (resultsEnum.hasMore()) {
209210
SearchResult searchResult = resultsEnum.next();
210211
// Work out the DN of the matched entry
211-
DistinguishedName dn = new DistinguishedName(searchResult.getName());
212+
DistinguishedName dn = new DistinguishedName(new CompositeName(searchResult.getName()));
212213

213214
if (base.length() > 0) {
214215
dn.prepend(searchBaseDn);

ldap/src/main/java/org/springframework/security/ldap/authentication/BindAuthenticator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ private DirContextOperations bindWithDn(String userDnStr, String username, Strin
113113
// Check for password policy control
114114
PasswordPolicyControl ppolicy = PasswordPolicyControlExtractor.extractControl(ctx);
115115

116+
logger.debug("Retrieving attributes...");
117+
116118
Attributes attrs = ctx.getAttributes(userDn, getUserAttributes());
117119

118120
DirContextAdapter result = new DirContextAdapter(attrs, userDn, ctxSource.getBaseLdapPath());

ldap/src/test/java/org/springframework/security/ldap/AbstractLdapIntegrationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected AbstractLdapIntegrationTests() {
4848
@BeforeClass
4949
public static void startServer() throws Exception {
5050
contextSource = new DefaultSpringSecurityContextSource("ldap://127.0.0.1:53389/dc=springframework,dc=org");
51-
// OpenLDAP option
51+
// OpenLDAP configuration
5252
// contextSource = new DefaultSpringSecurityContextSource("ldap://127.0.0.1:22389/dc=springsource,dc=com");
5353
// contextSource.setUserDn("cn=admin,dc=springsource,dc=com");
5454
// contextSource.setPassword("password");

ldap/src/test/java/org/springframework/security/ldap/authentication/BindAuthenticatorTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ public void testAuthenticationWithUserSearch() throws Exception {
8282
authenticator.authenticate(new UsernamePasswordAuthenticationToken("slash/guy", "slashguyspassword"));
8383
// SEC-1661
8484
authenticator.setUserSearch(new FilterBasedLdapUserSearch("ou=\\\"quoted people\\\"", "(cn={0})", getContextSource()));
85-
authenticator.authenticate(new UsernamePasswordAuthenticationToken("quoteguy", "quoteguyspassword"));
85+
authenticator.authenticate(new UsernamePasswordAuthenticationToken("quote\"guy", "quoteguyspassword"));
86+
authenticator.setUserSearch(new FilterBasedLdapUserSearch("", "(cn={0})", getContextSource()));
87+
authenticator.authenticate(new UsernamePasswordAuthenticationToken("quote\"guy", "quoteguyspassword"));
8688
}
8789
/*
8890
@Test

ldap/src/test/resources/test-server.ldif

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,12 @@ sn: Slash
7373
uid: slashguy
7474
userPassword: slashguyspassword
7575

76-
dn: cn=quoteguy,ou=\"quoted people\",dc=springframework,dc=org
76+
dn: cn=quote\"guy,ou=\"quoted people\",dc=springframework,dc=org
7777
objectclass: top
7878
objectclass: person
7979
objectclass: organizationalPerson
8080
objectclass: inetOrgPerson
81-
cn: quoteguy
81+
cn: quote\"guy
8282
sn: Quote
8383
uid: quoteguy
8484
userPassword: quoteguyspassword

0 commit comments

Comments
 (0)