JavaSpring安全性动态登录
我有一个文件bean:
<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.1.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="/secured/*" access="ROLE_USER" />
<form-login login-processing-url="/login" login-page="/loginPage"
username-parameter="username" password-parameter="password"
default-target-url="/secured/mypage" authentication-failure-url="/loginPage?auth=fail" />
<logout logout-url="/logout" logout-success-url="/logoutPage" />
</http>
<authentication-manager>
<authentication-provider>
<user-service>
<user name="srccodes" password="password" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
我有一个登录页面,我从外部数据库检查登录密码,该登录与“srccodes”password=“password”不同。如何动态地添加用户并对其产生影响,例如ROLE_USER
# 1 楼答案
检查此example 根据您的示例,您将密码和用户详细信息存储在xml中!它将从数据库选项卡获取用户凭据
1.您必须更改身份验证管理器的设置
并设置与数据库的连接
如果要创建用户,必须将新记录插入到
users
表和user_roles
表