Package com.example.demo.appuser
Class AppUserService
java.lang.Object
com.example.demo.appuser.AppUserService
- All Implemented Interfaces:
org.springframework.security.core.userdetails.UserDetailsService
@Service
public class AppUserService
extends Object
implements org.springframework.security.core.userdetails.UserDetailsService
Service class that manages business logic for
AppUser entities.
It implements UserDetailsService to integrate with Spring Security
for user authentication.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintenableAppUser(String email) Activates a user account by setting theenabledstatus totrue.org.springframework.security.core.userdetails.UserDetailsloadUserByUsername(String email) Locates the user based on the email address.signUpUser(AppUser appUser) Handles the user registration process.
-
Constructor Details
-
AppUserService
public AppUserService()
-
-
Method Details
-
loadUserByUsername
public org.springframework.security.core.userdetails.UserDetails loadUserByUsername(String email) throws org.springframework.security.core.userdetails.UsernameNotFoundException Locates the user based on the email address. This method is required by theUserDetailsServiceinterface and is used by Spring Security during the authentication process.- Specified by:
loadUserByUsernamein interfaceorg.springframework.security.core.userdetails.UserDetailsService- Parameters:
email- The email (username) identifying the user whose data is required.- Returns:
- A fully populated user record (an
AppUserinstance). - Throws:
org.springframework.security.core.userdetails.UsernameNotFoundException- if the user with the given email is not found.
-
signUpUser
Handles the user registration process.This method checks if the user already exists, encodes the password, saves the new user to the database, generates a unique confirmation token, and persists the token.
- Parameters:
appUser- TheAppUserobject containing the new user's details.- Returns:
- The generated confirmation token string.
- Throws:
IllegalStateException- if a user with the provided email already exists.
-
enableAppUser
Activates a user account by setting theenabledstatus totrue. This method is typically called after the user successfully confirms their email via the confirmation token.- Parameters:
email- The email of the user to enable.- Returns:
- The number of records updated (should be 1 upon success).
-