简体   繁体   English

如何在hybris中进行不区分大小写的用户名认证?

[英]How to make case insensitive username authentication in hybris?

如何在hybris中进行不区分大小写的用户名认证?

First you have to override the register method of DefaultCustomerFacade (file in commercefacades). 首先,您必须覆盖DefaultCustomerFacade的注册方法(commercefacades中的文件)。

You will find that default implementation force lower case preventing you from having upper case characters in your uid --> customer.setUid(registerData.getLogin().toLowerCase()) 你会发现默认的实现强制小写使你无法在你的uid中使用大写字符 - > customer.setUid(registerData.getLogin().toLowerCase())

Then you have to create a new bean with alias "acceleratorAuthenticationProvider" that override the method authenticate. 然后,您必须使用别名“acceleratorAuthenticationProvider”创建一个覆盖方法身份验证的新bean。

In this method you have to implement something like 在这种方法中,你必须实现类似的东西

final UserModel userModel = findUserCaseInsensitive(authentication.getName());
if (userModel != null)
{
    usernameResult = userModel.getUid();
    token = new UsernamePasswordAuthenticationToken(authentication.getName(), authentication.getCredentials());
    token.setDetails(authentication.getDetails());
}

The method findUserCaseInsensitive should call a DAO that will perform a flexible search. findUserCaseInsensitive方法应调用将执行灵活搜索的DAO。 Here is an example : 这是一个例子:

SELECT {user.PK} FROM {User as user} WHERE lower({user.uid}) = lower(?uid)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM