我已经学习Java编程13周并正在开发一个RESTful的Web服务。现在,我的后端处理完了,接下来我要开始创建用户界面。其中一个要求是要使用http基础认证进行用户登录。我已经将其配置完成,当用户导航到页面时,会弹出对话框,您可以输入一个我预先设置好的用户以进行登录。但是,我真正需要的是检查数据库中的用户信息是否匹配。我已经进行了广泛的搜索,试图找到一种配置方法来验证数据库中的用户,但无济于事。这是我的spring-security.xml文件和我的虚拟用户。
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<!-- <http auto-config="true"> <intercept-url pattern="/welcome*" access="ROLE_USER"
/> <form-login login-page="/login" default-target-url="/welcome" authentication-failure-url="/loginfailed"
/> <logout logout-success-url="/logout" /> </http> -->
<http>
<intercept-url pattern="/*" access="ROLE_USER" />
<http-basic />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="tmain" password="123456" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans>
以下是我认为与我的web.xml文件设置相关的唯一相关信息。
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
有人能指导我如何配置Spring Security来使用数据库进行身份验证,而不是使用我拥有的虚拟用户吗? 我在数据库中有一个名为User的实体,其中包含名字、姓氏、电子邮件、密码、活动状态和时区。 电子邮件是用户的用户名。 非常感谢任何帮助。