Tuesday, 17 September 2013

Ldap based authentication throws NPE

Ldap based authentication throws NPE

I've configured my webapp to use ldap/AD as the
authentication/authorisation provider.
My configuration worked fine for a while but it recently out of the blue
started throwing the follwing exception:
java.lang.NullPointerException
at
org.springframework.security.ldap.userdetails.LdapUserDetailsImpl$Essence.hasAuthority(LdapUserDetailsImpl.java:195)
at
org.springframework.security.ldap.userdetails.LdapUserDetailsImpl$Essence.addAuthority(LdapUserDetailsImpl.java:188)
at
org.springframework.security.ldap.userdetails.LdapUserDetailsMapper.mapUserFromContext(LdapUserDetailsMapper.java:85)
at
org.mule.galaxy.security.ldap.LdapAuthenticationProvider.authenticate(LdapAuthenticationProvider.java:265)
at
org.springframework.security.authentication.ProviderManager.authenticate(ProviderManager.java:156)
at
org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter.attemptAuthentication(UsernamePasswordAuthenticationFilter.java:94)
at
org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:195)
at
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at
org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
at
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at
org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
at
org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
at
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
at
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
at
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
and here is my spring configuration:
<bean id="propertiesLDAP"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName"
value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <!-- Existing system
properties override local ones -->
<property name="location" value="classpath:META-INF/ldap.properties" />
<property name="ignoreResourceNotFound" value="false" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="properties">
<props>
<prop key="providerURL">ldap:/localhost:389</prop>
<prop key="userDn">uid=admin,ou=system</prop>
<prop key="password">secret</prop>
<prop key="userSearchBaseContext">ou=system</prop>
<prop key="userSearchFilterExpression">(uid={0})</prop>
<prop key="userSearchBase">ou=system</prop>
<prop key="userSearchAttributeKey">objectclass</prop>
<prop key="userSearchAttributeValue">person</prop>
<prop key="roleDn">ou=groups,ou=system</prop>
<prop key="groupSearchFilter">uniqueMember={0}</prop>
<prop key="usernameAttribute">uid</prop>
</props>
</property>
</bean>
<bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="${providerURL}" />
<property name="userDn">
<value>${userDn}</value>
</property>
<property name="password">
<value>${password}</value>
</property>
</bean>
<bean id="userSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch"
depends-on="propertiesLDAP">
<constructor-arg value="${userSearchBaseContext}" />
<constructor-arg value="${userSearchFilterExpression}" />
<constructor-arg ref="contextSource" />
<property name="searchSubtree" value="true" />
</bean>

No comments:

Post a Comment