Step1: First applicationuserdetailsservice need to implement Userdetailsservice interface (in
Org.springframework.security.core.userdetails), the callback function that obtains the user details information must be implemented
Loaduserbyusername method, note that the user here implements the parameters of the Userdetails,credentialscontainer,user class, respectively:
Password,username,authorities,accountnonexpired,accountnonlocked,credentialsnonexpired,enable,
The code is as follows:
We can customize the addition of new user information, where we customize a Simpleuser class to inherit the user.
The code is as follows:
Note that the simpleuser must inherit the user, and must inherit the above 5 properties and the Hashcode,equals method, which must be given to these 5
Property assignment, Applicationuserdetailsservice calls the constructor method to generate a Simpleuser object. If the user does not exist, throw a
Usernamenotfoundexception exception.
The code is as follows:
When the Step2:loaduserbyusername method returns, it jumps to Daoauthenticationprovider (in
Org.springframework.security.authentication.dao) class in the Retrieveuser method
When the Step3:retrieveuser method returns, it jumps to Abstractuserdetailsauthenticationprovider (in
Org.springframework.security.authentication.dao) Authenticate method, this method will first look up the user from the cache.
If not, the user is checked out from the previous step of the Daoauthenticationprovider Loaduserbyusername method, which throws
Usernamenotfoundexception This exception, should be the user does not exist this error, that is bad credentials.
Step4:authenticate method Preauthenticationchecks.check (user), where basic validation is performed (valid, whether
is locked, expired) code is as follows:
In the Step5:authenticate method additionalauthenticationchecks (user,
(Usernamepasswordauthenticationtoken) authentication) method validation is performed here. The code is as follows:
Spring security talking about user authentication mechanism