我想使用 Spring security 对我的 Web 应用程序中的用户进行身份验证。
由于我不是 Spring 框架的成熟用户,我无法清楚地了解如何进行配置设置以使用 jdbc-user-service ..
我已经完成了以下配置。但它不起作用
<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>
..任何人都可以帮我通过示例配置文件解决问题。
提前致谢。
另一种方法是使用标准 spring security 数据库模式创建表(http://static.springsource.org/spring-security/site/docs/3.0.x/reference/appendix-schema.html http://static.springsource.org/spring-security/site/docs/3.0.x/reference/appendix-schema.html)。然后你可以简单地使用spring的jdbc-userservice:
<security:authentication-provider >
<security:jdbc-user-service data-source-ref="dataSource" />
<security:password-encoder hash="sha" />
</security:authentication-provider>
或者,如果您想使用自己的模式,您可以覆盖查询,如下所示:
<security:authentication-provider>
<securiy:jdbc-user-service
data-source-ref="dataSource"
users-by-username-query="select username, password from users where username=?"
authorities-by-username-query="select username, roleName from role..."
role-prefix="ROLE_"
/>
</security:authentication-provider>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)