[英]Spring security. add restriction for user log in
I have following spring security config: 我有以下春季安全配置:
<http auto-config="true" authentication-manager-ref="userAuthenticationManager">
<form-login login-page="/"
default-target-url="/member/personalAccount"
authentication-failure-url="/loginfailed" authentication-success-handler-ref="authSuccessHandler" />
<!-- <intercept-url pattern="/common/*" filters="none" /> -->
<intercept-url ..../>
<logout logout-url="/logout" logout-success-url="/" />
<port-mappings>
<port-mapping http="${http.port}" https="${https.port}"/>
</port-mappings>
</http>
....
<authentication-manager alias="userAuthenticationManager">
<!-- <authentication-provider user-service-ref="userSecurityService"> -->
<authentication-provider>
<password-encoder ref="encoder" />
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="select email,password,prop_was_moderated from terminal_user where email = ?"
authorities-by-username-query="select email,user_role from terminal_user where email = ?" />
</authentication-provider>
</authentication-manager>
Now I want to add new column to terminal_user
table. 现在,我想向
terminal_user
表添加新列。 This column called prop_confirmed
此列称为
prop_confirmed
I want to achieve that only user who has prop_confirmed
as true
can be log in. 我想实现只有
prop_confirmed
为true
用户才能登录。
Can you help me to achieve it? 你能帮我实现吗?
One way you could do it is to hardcode the prop_confirmed
condition in users-by-username-query
. 一种
prop_confirmed
方法是在users-by-username-query
对prop_confirmed
条件进行硬编码。 That way if user is not confirmed, it will be as if they don't exist and the authentication will fail: 这样,如果未确认用户,就好像他们不存在,并且身份验证将失败:
select email,password,prop_was_moderated from terminal_user
where email = ? AND prop_confirmed = TRUE
There are other (and possibly cleaner) solutions, such as customizing AuthenticationManager
. 还有其他(可能更清洁)的解决方案,例如自定义
AuthenticationManager
。 Take a look at my SO answer regarding similar question for more detailed description of these options. 看看我对类似问题的SO答案 ,以更详细地描述这些选项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.