PDA

View Full Version : Encorporating Custom UserDetails



bendg25
Dec 20th, 2004, 04:21 AM
Hi

I cannot find anywhere in the docs or this forum where it is possible to either a) add properties to UserDetails or b) (what I really want todo) use my own customer User object?

I know it is possible but how to you encorporate your own User object? I can no doubt do it by overriding existing providers/filters, but is there a cleaner / easier way?

Any help would be appreciated..

Ben Alex
Dec 20th, 2004, 05:21 AM
Nearly every deployment of Acegi Security will use DaoAuthenticationProvider, which needs an AuthenticationDao, and most people write their own AuthenticationDao. The AuthenticationDao needs to return a UserDetails implementation. Generally people return either User (which implements UserDetails) or a subclass of User, although naturally you're free to write your own UserDetails implementation.

bendg25
Dec 20th, 2004, 05:48 AM
ok thanks,

I thought they maybe a:

<param>userclass</param>
<value>my.com.UserDetails</value>

type thing for the Authenticator that would allow me to pass in my custom class, and then the authenticator use that (using reflection)..

Ben Alex
Dec 20th, 2004, 02:57 PM
Say the AuthenticationProvider created an instance of the class you specified, what would then populate it?

Using the UserDetails approach will make the UserDetails object available from Authentication.getPrincipal().