Unable to authenticate against Active Directory
I've been playing around for several weeks trying to get Spring Security 3.0.x authenticating against our corporate Active Directory server. The closest I've gotten were either errors around needing to do an authenticated bind before an actual user authentication and bad credentials. I took this to mean we needed to create a service account to bind to AD as and then perform an AD authorization. I will try this once I get that service account.
I then saw that 3.1 has native support for AD authentication so I've tried that but it's now failing because no results are being returned - I was following these instructions: http://static.springsource.org/sprin...tive-directory.
Looking at the debugging information, I'm not sure it's using the correct information and I am unsure as to how to provide it given our setup. Our employee user names are just an ID string, not our names. Our base DN is dc=corp,dc=foo,dc=com. Using an AD browser, our sAMAccountName is <username>@corp.foo.com whereas the value of userPrincipalName is <username>@foo.com.
Here is the code I am trying to execute that returns zero results:
Code:
ActiveDirectoryLdapAuthenticationProvider adlap =
new ActiveDirectoryLdapAuthenticationProvider("corp.foo.com", "ldap://xx.xx.xx.xx:389");
adlap.setConvertSubErrorCodesToExceptions(true);
UsernamePasswordAuthenticationToken auth =
new UsernamePasswordAuthenticationToken("<username>@corp.foo.com", "<username's password>");
adlap.authenticate(auth);
The debug output is:
Code:
DEBUG ActiveDirectoryLdapAuthenticationProvider - Processing authentication request for user: <username@corp.foo.com
DEBUG SpringSecurityLdapTemplate - Searching for entry under DN '', base = 'dc=corp,dc=foo,dc=com', filter = '(&(objectClass=user)(userPrincipalName={0}))'
INFO SpringSecurityLdapTemplate - Ignoring PartialResultException
org.springframework.dao.IncorrectResultSizeDataAccessException: Incorrect result size: expected 1, actual 0
at org.springframework.security.ldap.SpringSecurityLdapTemplate.searchForSingleEntryInternal(SpringSecurityLdapTemplate.java:239)
...
My division's users are nested down a few layers from the initial tree node of "dc=corp,dc=foo,dc=com" but I don't see a way to specify additional nodes - or know if I even need to.
Any help would be most welcome. Thanks.
re: Unable to authenticate against Active Directory
I ran into this recently as well using the ActiveDirectoryLdapAuthenticationProvider. I was baffled as this had worked fine for me when pointed it toward my companies domain controller during development.
However we then setup a test lab with a new domain controller and created a user account. I know little about active directory, so originally I got an error that the account was not enabled. After fixing that I ran into the same exception: "org.springframework.dao.IncorrectResultSizeDataAc cessException: Incorrect result size: expected 1, actual 0".
It turns out when creating the account I did not supply a login name. Once I did the exception went away and everything worked. I haven't delved into the details to understand why this happened (particularly as I originally got an exception the account was disabled, so the underlying code seemed to at least partially find the user...).
Hope this helps