views:

331

answers:

1

I have a web application that is set up to use the default ldap server/authentication manager/authentication provider/user service. I have another DAO that already does majority of the work that those do (besides the authenticating a user) using Spring-LDAP. My problem is that I want the principal to be of my own custom bean class. What is the simplest way to do this?

Initially I was thinking to create a custom authentication provider, but since the default one does exactly what I want, there doesnt seem to be a need. I am thinking I just need to override whatever object actually returns the Principal bean. Is this possible, and able to be injected into the security ldap authenticator context?

This is how I currently have it set up:

 <ldap-server 
  url="ldap://HOST:3268/BASEDN"
  manager-dn="FULLDN" 
  manager-password="PASS"/>

    <authentication-manager>
 <ldap-authentication-provider user-search-filter="(samaccountname={0})"/>
 <authentication-provider>
      <ldap-user-service  user-search-filter="(samaccountname={0})"/>
 </authentication-provider>

</authentication-manager> 

Is the 'ldap-user-service' what links the Principal bean to the Authentication object of the SecurityContext?

The problem is right now I have a 2nd LDAP configuration (almost identical to the auth configuration) that is for the DAO, when a user goes to a page, I simply re-lookup their user account, and get back the User object (which would be nice if it was the SecurityContext Principal)...

+1  A: 

Use ldap-authentification-provider/@user-context-mapper-ref and implement an own org.springframework.security.ldap.userdetails.UserDetailsContextMapper.

lexicore