Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java LDAP search cant seem to handle spaces

Tags:

java

ldap

When calling javax.naming.ldap.InitialLdapContext's search() method, passing in the DN...

OU=User Structure, OU=Acecity(LTO), OU=AceCloud,OU=Hosting, DC=AceCloud,DC=local

The error is outputted is Authentication failed. failed to authenticate user:[LDAP: error code 32 - 0000208D: NameErr: DSID-0315270B, problem 2001 (NO_OBJECT), data 0.

LdapName baseDN = new LdapName(baseDN
NamingEnumeration results = ctx.search(baseDN, "("+ identity.getBindAttribute() + "=" + acctname + ")", sc);

The problem occurs due to the space in User Structure. When I placed the users in another OU that doesn't contain a space, I am able to authenticate fine. I’ve tried all of the following:

OU=User\ Structure, OU=Acecity(LTO), OU=AcecityCloud,OU=Hosting, DC=AcecityCloud,DC=local
OU=User\20Structure, OU=Acecity(LTO), OU=AcecityCloud,OU=Hosting, DC=AcecityCloud,DC=local
OU=User\\20Structure, OU=Acecity(LTO), OU=AcecityCloud,OU=Hosting, DC=AcecityCloud,DC=local
OU=User%Structure, OU=Acecity(LTO), OU=AcecityCloud,OU=Hosting, DC=AcecityCloud,DC=local
OU=User\ Structure, OU=Acecity(LTO), OU=AcecityCloud,OU=Hosting, DC=AcecityCloud,DC=local
OU=User\\ Structure, OU=Acecity(LTO), OU=AcecityCloud,OU=Hosting, DC=AcecityCloud,DC=local
OU=User\\\\ Structure, OU=Acecity(LTO), OU=AcecityCloud,OU=Hosting, DC=AcecityCloud,DC=local

None works. Any ideas?

like image 589
jamie Avatar asked Jan 15 '15 13:01

jamie


1 Answers

Spaces can cause issues with openldap if they are not escaped properly.

'OU="User Structure",OU=Acecity(LTO),OU=AceCloud,OU=Hosting,DC=AceCloud,DC=local'

To avoid issues, enclose the entire BINDDN with single quotes, and enclose the Common Name (CN), Organizational Unit (OU) or Domain Component (DC) containing a space character with double quotes.

like image 146
jare25 Avatar answered Oct 10 '22 16:10

jare25