I want to use Spring security to authenticate users in my web application.. Since am not a matured user to Spring framework ,i can't get a clear idea about how we can do the configuration settings to use jdbc-user-service .. i had done the following configurations.but its not working
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="myDataSource"/>
</authentication-provider>
</authentication-manager>
<beans:bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<beans:property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<beans:property name="url" value="jdbc:mysql://localhost:3306/testDB"/>
<beans:property name="username" value="admin"/>
<beans:property name="password" value="admin"/>
</beans:bean>
..can anyone please help me to solve the issue with a sample config file. Thanks in advance.
You usually do it with a custom
UserDetailsService
. TheUserDetailsService
is a DAO used to load data about a user when they attempt login. Have a look at theloadUserByUsername(String username)
method and theUserDetails
class in spring.Yo need to define it in your context:
To use it you can add this to your security config:
and all you security filters will use it.
You can ask a more specific question if you need help implementing it, but you won't have trouble IMO.
another way to do this is to create tables using the standard spring security database schema (http://static.springsource.org/spring-security/site/docs/3.0.x/reference/appendix-schema.html). Then you can simply use spring's jdbc-userservice:
Or if you want to use your own schema you can override the queries like this:
Add these lines to your
<authentication-provider>
tag:Of course you'll have to tweak the queries to match your table names.