Custom UserDetialsService with Multiple Parameters in Spring Security

Spring Security has a UserDetailsService with method

public UserDetails loadUserByUsername(String username) 

Usually we need to create a UserDetailsServiceImpl that implements this interface and provides an implementation for the above method.

In my application, the username will not be unique. This may be the same for different organizations. It will be unique with the organization. Therefore, I need to find user data by user name and organization.

In this case, the above method will not work. I am trying to create a method that will take two parameters, that is, the username and the name of the organization and get the user data.

The login form will contain three usernames, organization name and password. This authentication part with three i / p parameters works correctly.

But I can not call my custom method call.

Please, help.

+4
source share
1 answer

A simpler option that I can think of now is to combine the organization with the username . And add a simple DB function that does this for insertion for each user.

In your database you can:

  |  organization |  username |  organization_username |

 |  IBM |  Jonny |  IBM_Jonny |

So, you would call your method something like:

 myDetailsService.loadUserByUsername("IBM_Jonny"); 

Or without any changes to the database:

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

All Articles