Class UserService
java.lang.Object
com.serinity.accesscontrol.service.UserService
Service class for managing user registration and authentication.
This class provides methods to register new users with a profile and role, as well as to authenticate existing users using their username and password.
- Since:
- 2026-02-03
- Version:
- 1.0
- Author:
- @ZouariOmar (zouariomar20@gmail.com)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic ServiceResult<Void> confirmResetMail(String email, String inputCode, String newPassword) Confirms a password reset by verifying the one-time code and applying the new password.static ServiceResult<Void> sendResetMail(String email) Initiates a password reset flow by sending a one-time code to the user's email address.static ServiceResult<User> Signs in a user using their email (or username) and password.static ServiceResult<User> signInWithFace(User user) Creates a new authenticated session for a user who was identified via face recognition, revoking any previously active session, and records the login in the audit log with actionAuditAction.USER_FACE_LOGIN.static ServiceResult<User> Registers a new user with email, password, and role.
-
Constructor Details
-
UserService
public UserService()
-
-
Method Details
-
signUp
public static ServiceResult<User> signUp(String email, String password, String confirmPassword, UserRole role) Registers a new user with email, password, and role.This method performs:
- Input validation for email, password, confirm password, and role.
- User creation with hashed password.
- Profile, session, and audit log creation.
- Persisting all entities using the corresponding repositories.
- Parameters:
email- the user's emailpassword- the user's chosen passwordconfirmPassword- confirmation of the passwordrole- the role assigned to the user- Returns:
- a
ServiceResultindicating success or failure with messages
-
signIn
Signs in a user using their email (or username) and password.This method performs the following steps:
- Validates the email/username format.
- Retrieves the user from the database.
- Verifies the password using
PasswordEncoder. - Checks for an existing active session.
- Returns a
ServiceResultcontaining success or error information.
- Parameters:
usernameOrEmail- the user's email or usernamepassword- the plain-text password provided by the user- Returns:
- a
ServiceResultcontaining the authenticatedUseror an error
-
signInWithFace
Creates a new authenticated session for a user who was identified via face recognition, revoking any previously active session, and records the login in the audit log with actionAuditAction.USER_FACE_LOGIN.- Parameters:
user- theUseridentified by the face recognition system- Returns:
- a
ServiceResultcontaining the authenticatedUser
-
sendResetMail
Initiates a password reset flow by sending a one-time code to the user's email address.The generated code is cached for 10 minutes. The user must call
confirmResetMail(String, String, String)with the correct code within that window to update their password.- Parameters:
email- the email address of the account to reset- Returns:
- a
ServiceResultindicating success or failure with a message
-
confirmResetMail
public static ServiceResult<Void> confirmResetMail(String email, String inputCode, String newPassword) Confirms a password reset by verifying the one-time code and applying the new password.The reset code must match the one previously sent via
sendResetMail(String)and must not have expired (10-minute TTL).- Parameters:
email- the email address of the account to resetinputCode- the one-time code entered by the usernewPassword- the desired new password (must meet complexity rules)- Returns:
- a
ServiceResultindicating success or failure with a message
-