开发者

Custom UserDetialsService with multiple parameters in Spring Security

Spring Security has a UserDetailsService with a method

public UserDetails loadUserByUsername(String username)

Normally we need to cre开发者_运维问答ate UserDetailsServiceImpl which implements this interface and provide the implementation for the above method.

In my application username will not be unique. It can be same across different organizations. It will be unique withing an organization. So I need to find user details by username and organization.

In this case the above method will not work. I am trying to create a method which will take two parameters i.e. username and organization name and fetch the user details.

The login form will have three parameters username, organization name and password. This authentication part with three i/p parameters is working properly.

But I am not able to have my custom method being called.

Please help.


The simpler option I can think of currently is concatenate the organization with the username. And add a simple DB function that does this on insert for each user.

In your DB you might have:

| organisation | username | organisation_username |

|     IBM      |   Jonny  |      IBM_Jonny        |

So you would call your method with something like:

myDetailsService.loadUserByUsername("IBM_Jonny");

Or without any changes to the database:

myDetailsService.loadUserByUsername(user.getCompany() + "_" + user.getUsername());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜