简体   繁体   中英

How to make case insensitive username authentication in hybris?

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

First you have to override the register method of DefaultCustomerFacade (file in 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())

Then you have to create a new bean with alias "acceleratorAuthenticationProvider" that override the method authenticate.

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. Here is an example :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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