使用MySQL数据库来验证Spring Security的用户? [英] Using mysql database to authenticate users in Spring security?

查看:511
本文介绍了使用MySQL数据库来验证Spring Security的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Spring Security在我的web应用程序对用户进行认证..
因为我不是一个成熟的用户Spring框架,我不能让我们如何能做到的配置设置,使用JDBC的用户服务一个明确的想法..
我已经做了以下configurations.but它不工作

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.

推荐答案

您通常使用自定义做<一个href=\"http://www.$c$crcorp.com/blog/spring/security-spring/writing-custom-userdetailsservice-for-spring-security.html\"相对=nofollow> 的UserDetailsS​​ervice 。在的UserDetailsS​​ervice 是一个DAO使用时,他们试图登录加载有关的用户数据。看一看在 loadUserByUsername(字符串的用户名)方法和春季的UserDetails 类。

You usually do it with a custom UserDetailsService. The UserDetailsService is a DAO used to load data about a user when they attempt login. Have a look at the loadUserByUsername(String username) method and the UserDetails class in spring.

哟需要在你的上下文中定义它:

Yo need to define it in your context:

<bean id="myDetailsService"
    class="com.company.service.impl.MyDetailsService" />

要使用它,你可以将它添加到您的安全配置:

To use it you can add this to your security config:

<authentication-manager>
    <authentication-provider user-service-ref="myDetailsService" />
</authentication-manager>

和你的安全过滤器将使用它。

and all you security filters will use it.

您可以问一个更具体的问题,如果你需要帮助实现它,但你不会有麻烦IMO。

You can ask a more specific question if you need help implementing it, but you won't have trouble IMO.

这篇关于使用MySQL数据库来验证Spring Security的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆