user-by-username-query需要多于1个参数 [英] user-by-username-query needing more than 1 parameter
问题描述
我必须实现一个弹簧安全件,它有超过1个参数来获取用户。它将通过其ID和产品名称获取用户。我知道user-by-username-query只能给出一个参数,我想知道是否有可能给出许多用户 - 用户名 - 查询选项并给他们一些ID,但我不知道如何在验证时会引用。有没有人有任何建议
I have to implement a spring security piece which has more than 1 parameter for getting users. It will get a user by its ID and a product name. I know that the user-by-username-query can only give the one parameter, I was wondering if it's possible to give many users-by-username-query options and give them some sort of ID, but I'm not sure how that would be referenced when authenticating. Does anyone have any suggestions
<sec:authentication-provider>
<sec:jdbc-user-service data-source-ref="dataSource"
users-by-username-query="
select username,password,enabled
from MY_USERS where username=? and product='productA'" />
推荐答案
您需要实现自己的 AuthenticationProvider
您无法重复使用 DaoAuthenticationProvider (jdbc-user-service),因为它使用
UserDetailsService ,这有一个基于一个字符串参数加载UserDetails的方法 UserDetails loadUserByUsername(String username)
You can not reuse the DaoAuthenticationProvider (jdbc-user-service), because it uses a
UserDetailsService, and this has a method to load the UserDetails based on only one string argument UserDetails loadUserByUsername(String username)
这篇关于user-by-username-query需要多于1个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!