开发者

How to create and configure the custom UserDetailsByNameServiceWrapper in Spring security 3.0.5?

开发者 https://www.devze.com 2023-04-01 06:03 出处:网络
I am using spring security 3.0.5 in my web application based on Spring MVC. We need to check four parameters for the authentication i.e. username, password, company and organization.

I am using spring security 3.0.5 in my web application based on Spring MVC. We need to check four parameters for the authentication i.e. username, password, company and organization.

For this I have written my own custom authentication token which encapsulates these four fields. I also have a custom user details service.

Normal UserDetails service has loadUserByUsername(username) but in my case I need this method to accept all the four parameters. For this I have decided to provide custom implementation of UserDetailsByNameServiceWrapper which calls loadUserByUsername(username).

In my custom 开发者_高级运维implementation I will pass whole authentication object instead of just the username.

I am not getting how do i plugin my custom UserDetailsByNameServiceWrapper in the spring security xml file.

Please help.


Instead of creating 'your own' UserDetailsByNameServiceWrapper you'll want to implement AuthenticationUserDetailsService instead. This class can then be injected with the following Spring Security configuration:

<bean id="preAuthAuthProvider" class="org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationProvider">
    <property name="preAuthenticatedUserDetailsService" ref="yourAuthenticationUserDetailsService" />
</bean>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号