I get the following ldap.core.TokenMgrError when I try to do an ldap bind on a domain with "xyz\first.last" as the username. The bind itself works properly via ldp.exe and JXPlorer. Our Active Directory doesn't allow anonymous binds, so we have to use the user's login credentials on every ldap call (in this case authentication). I'm using Spring LDAP 1.3 with Spring Security 3.0.2. Below is my config (obfuscated to protect).
Ideally I don't even want to have to parse the DN to bind. I want to bind with the domain\username. But I can't find any method on LdapTemplate or DirContextOperations to do that directly. If this needs to be posted in the spring security forum I'll do that, but the exception I'm getting comes from spring ldap so I figured here's the right place to post.
Error: Your login attempt was not successful, try again.
Reason: Failed to parse DN; nested exception is org.springframework.ldap.core.TokenMgrError: Lexical error at line 1, column 9. Encountered: "." (46), after : "".
Reason: Failed to parse DN; nested exception is org.springframework.ldap.core.TokenMgrError: Lexical error at line 1, column 4. Encountered: "\\" (92), after : "".
Code:2010-03-23 17:28:12,179 [http-8080-2] DEBUG authentication.UsernamePasswordAuthenticationFilter - Authentication request failed: org.springframework.security.authentication.AuthenticationServiceException: Failed to parse DN; nested exception is org.springframework.ldap.core.TokenMgrError: Lexical error at line 1, column 9. Encountered: "." (46), after : ""
Here's the applicationContext-security.xml:
Code:<?xml version="1.0" encoding="UTF-8"?> <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd"> <global-method-security pre-post-annotations="enabled"> <!-- AspectJ pointcut expression that locates our "post" method and applies security that way <protect-pointcut expression="execution(* bigbank.*Service.post*(..))" access="ROLE_TELLER"/> --> </global-method-security> <http use-expressions="true"> <!-- intercept-url pattern="/secure/extreme/**" access="hasRole('ROLE_SUPERVISOR')"/ --> <intercept-url pattern="/phase/**" access="hasRole('ROLE_ADMIN')"/> <intercept-url pattern="/summary/**" access="isAuthenticated()" /> <intercept-url pattern="/login**" access="permitAll"/> <intercept-url pattern="/spring_security_login" access="permitAll"/> <intercept-url pattern="/images/**" access="permitAll"/> <intercept-url pattern="/js/**" access="permitAll"/> <intercept-url pattern="/css/**" access="permitAll"/> <intercept-url pattern="/yaml/**" access="permitAll"/> <intercept-url pattern="/**" access="isAuthenticated()" /> <form-login login-page="/login.jsp" login-processing-url="/j_spring_security_check" authentication-failure-url="/login.jsp?login_error=1" always-use-default-target="true" default-target-url="/" /> <logout logout-success-url="/"/> </http> <authentication-manager> <authentication-provider ref='ldapProvider'/> </authentication-manager> <beans:bean id="ldapProvider" class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider"> <beans:constructor-arg ref="bindAuthenticator"></beans:constructor-arg> <beans:constructor-arg ref="authoritiesPopulator"></beans:constructor-arg> </beans:bean> <beans:bean id="bindAuthenticator" class="my.security.ldap.authentication.BindAuthenticator"> <!-- consider this to be the same exact thing as spring security's BindAuthenticator, haven't modified the authenticate or bindWithDn methods --> <beans:constructor-arg ref="contextSource" /> <beans:property name="userDnPatterns"> <beans:list> <beans:value>cn={0},OU=DevTest Users,DC=xyz,DC=com</beans:value> <!-- Both of these next two fail before even going into the BindAuthenticator --> <beans:value>{0}</beans:value> <beans:value>xyz\{0}</beans:value> <beans:value>cn={0},OU=group,OU=mail,DC=xyz,DC=com</beans:value> </beans:list> </beans:property> </beans:bean> <!-- Modified based on Example 8.1 of section 8.1.3.2. Custom Principal and Credentials Management in the Spring LDAP Reference doc --> <beans:bean id="contextSource" class="org.springframework.security.ldap.DefaultSpringSecurityContextSource"> <beans:constructor-arg value="ldap://activedirectoryhostname:9389/DC=xyz,DC=com"/> <beans:property name="authenticationSource" ref="springSecurityAuthenticationSource" /> </beans:bean> <beans:bean id="springSecurityAuthenticationSource" class="org.springframework.security.ldap.authentication.SpringSecurityAuthenticationSource" /> <beans:bean id="authoritiesPopulator" class="my.security.ldap.userdetails.myAuthoritiesPopulator"> <beans:constructor-arg index="0" ref="contextSource" /> <beans:constructor-arg index="1" value="ou=groups" /> <beans:constructor-arg index="2" ref="gmsTemplate"/> <beans:property name="groupSearchFilter" value="(member={0})"/> <beans:property name="rolePrefix" value="ROLE_"/> <beans:property name="searchSubtree" value="true"/> <beans:property name="convertToUpperCase" value="true"/> </beans:bean> <beans:bean id="gmsTemplate" class="my.security.gms.GmsTemplate"> <beans:property name="baseUrl" value="http://localhost/GMS/Gms.svc"/> <beans:property name="messageConverters"> <beans:list> <beans:bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"/> </beans:list> </beans:property> </beans:bean> </beans:beans>


Reply With Quote
