【发布时间】:2016-11-14 17:06:27
【问题描述】:
如何在hybris中进行不区分大小写的用户名认证?
【问题讨论】:
标签: java spring-security hybris
如何在hybris中进行不区分大小写的用户名认证?
【问题讨论】:
标签: java spring-security hybris
首先你必须重写 DefaultCustomerFacade 的 register 方法(在 commercefacades 中的文件)。
你会发现默认实现强制小写阻止你在你的 uid 中使用大写字符 -->
customer.setUid(registerData.getLogin().toLowerCase())
然后你必须创建一个具有别名“acceleratorAuthenticationProvider”的新 bean,它会覆盖方法 authenticate。
在这个方法中你必须实现类似的东西
final UserModel userModel = findUserCaseInsensitive(authentication.getName());
if (userModel != null)
{
usernameResult = userModel.getUid();
token = new UsernamePasswordAuthenticationToken(authentication.getName(), authentication.getCredentials());
token.setDetails(authentication.getDetails());
}
findUserCaseInsensitive 方法应该调用一个执行灵活搜索的 DAO。
这是一个例子:
SELECT {user.PK} FROM {User as user} WHERE lower({user.uid}) = lower(?uid)
【讨论】: