Class AppUserDetailsServiceImpl
java.lang.Object
com.app.security.service.impl.AppUserDetailsServiceImpl
- All Implemented Interfaces:
org.springframework.security.core.userdetails.UserDetailsService
@Service
public class AppUserDetailsServiceImpl
extends Object
implements org.springframework.security.core.userdetails.UserDetailsService
Implementation of the
UserDetailsService
interface for loading user details.
This service is used to retrieve user details from the database by username and return a Spring Security
User
object containing the user's credentials and authorities. The service is responsible for
converting the retrieved user entity into a format suitable for Spring Security's authentication mechanism.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.security.core.userdetails.UserDetails
loadUserByUsername
(String username) Loads user details by the username.
-
Constructor Details
-
AppUserDetailsServiceImpl
public AppUserDetailsServiceImpl()
-
-
Method Details
-
loadUserByUsername
public org.springframework.security.core.userdetails.UserDetails loadUserByUsername(String username) throws org.springframework.security.core.userdetails.UsernameNotFoundException Loads user details by the username.This method retrieves a user by username from the database using the
UserRepository
, then converts the user entity into a Spring SecurityUser
object with the required information like username, password, enabled status, and roles. If the user is not found, it throws anEntityNotFoundException
.- Specified by:
loadUserByUsername
in interfaceorg.springframework.security.core.userdetails.UserDetailsService
- Parameters:
username
- the username of the user to be loaded- Returns:
- the
UserDetails
object containing the user's credentials and authorities - Throws:
org.springframework.security.core.userdetails.UsernameNotFoundException
- if the user with the given username is not found
-