Spring security using JPA. How to configure applicationContext-security.XML file?(using DaoAuthenticationProvider)
I was using JDBC Authentication service for my security. code of authentication provider is ,
<authentication-provider>
<jdbc-user-service id="userDetailsService" data-source-ref="dataSource" />
</authentication-provider>
And for data source,
<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/demodata" />
<property name="username" value="root"/>
<property name="password" value="root"/>
</bean>
Also I was using daoAuthenticationProvider , code of that is,
<beans:bean id="daoAuthenticationProvider" class="org.springframework.security.providers.dao.DaoAuthenticationProvider">
<property name="userDetail开发者_运维知识库sService" ref="userDetailsService"/>
<property name="saltSource" ref bean="saltSource"/>
<property name="passwordEncoder" ref="passwordEncoder"/>
</beans:bean>
And It was working properly. Now I want to use JPA connection instead of JDBC. So I Created new class CustomUserDetailsService which implements UserDetailsService Interface. Now My authentication provider looks like,
<authentication-provider user-service-ref="CustomUserDetailsService">
</authentication-provider>
<beans:bean id="CustomUserDetailsService" class="com.service.CustomUserDetailsService" />
Authentication manager's code :
<beans:bean id="authenticationManager"
class="org.springframework.security.providers.ProviderManager">
<beans:property name="providers"><beans:list>
<beans:ref local="daoAuthenticationProvider" />
</beans:list> </beans:property>
<beans:property name="sessionController"
ref="defaultConcurrentSessionController" />
</beans:bean>
Problem is that, Now how do I give its reference in daoAuthenticationProvider's property userDetailsService? Thank you in advance. (I can provide more information if needed)
??? Just reference the new UserDetailsService by id:
<beans:bean id="daoAuthenticationProvider"
class="org.springframework.security.providers.dao.DaoAuthenticationProvider">
<property name="userDetailsService" ref="CustomUserDetailsService"/>
<property name="saltSource" ref bean="saltSource"/>
<property name="passwordEncoder" ref="passwordEncoder"/>
</beans:bean>
Or am I missing something?
Instead of
<authentication-provider user-service-ref="CustomUserDetailsService">
</authentication-provider>
<beans:bean id="CustomUserDetailsService"
class="com.service.CustomUserDetailsService" />
Can you try the following as suggested here?
<beans:bean id="CustomUserDetailsService" class="com.service.CustomUserDetailsService">
<custom-authentication-provider/>
</beans>
精彩评论