Package com.jk.webstack.services.account
Class AccountServices
java.lang.Object
com.jk.webstack.services.account.AccountServices
- All Implemented Interfaces:
org.springframework.security.core.userdetails.UserDetailsService
public class AccountServices
extends Object
implements org.springframework.security.core.userdetails.UserDetailsService
This class provides user account-related services in a web application.
It implements the UserDetailsService interface for user
authentication and retrieval.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidchangePassword(String userName, String currentPassword, String newPassword) This method changes the password for a user account.createAccount(String email, String firstname, String lastname, String password) This method create a new user account with the provided details.protected StringcreateLoginLink(Account account) This method create a login link for the specified user account.protected voidcreateToken(Account account) This method create a one-time token for a user account.protected AccountfindAccountByEmail(String email) This method find a user account by its email address.loadDetailsByToken(String tokenString) This method load user account details based on a token string.loadUserByUsername(String username) Locates the user based on the user name.static voidThis main method demonstrate how to make a new account services object.protected voidprocessCurrentAccount(Account account) This method process an existing user account.protected voidprocessNewAccount(Account account) This method process the creation of a new user account.protected voidresetAccount(Account account) This method resets the provided user account's password and create a new token for it.resetAccount(String email) This method reset the user account associated with the given email address.protected voidresetToken(Account account) This method reset the one-time token for a user account.voidsetEmailVerified(Account account) This method set the email verification status for a user account.
-
Constructor Details
-
AccountServices
public AccountServices()This method constructs a newAccountServices.
-
-
Method Details
-
loadUserByUsername
public Account loadUserByUsername(String username) throws org.springframework.security.core.userdetails.UsernameNotFoundException Locates the user based on the user name.- Specified by:
loadUserByUsernamein interfaceorg.springframework.security.core.userdetails.UserDetailsService- Parameters:
username- the user name identifying the user whose data is required.- Returns:
- a fully populated user record (never
null) - Throws:
org.springframework.security.core.userdetails.UsernameNotFoundException- if the user could not be found or the user has no GrantedAuthority
-
createAccount
public Account createAccount(String email, String firstname, String lastname, String password) throws AccountAlreadyExistsException This method create a new user account with the provided details.- Parameters:
email- Specifies the email address for the new account.firstname- Specifies the first name for the new account.lastname- Specifies the last name for the new account.password- Specifies the password for the new account.- Returns:
- the created Account object.
- Throws:
AccountAlreadyExistsException- if an account with the same email already exists.
-
processNewAccount
This method process the creation of a new user account.- Parameters:
account- Specifies the Account object representing the new user account to be created.
-
processCurrentAccount
This method process an existing user account.- Parameters:
account- Specifies the Account object representing the existing user account to be processed.
-
resetAccount
This method reset the user account associated with the given email address.- Parameters:
email- Specifies the email address of the user account to reset.- Returns:
- the updated Account object after resetting the account.
-
resetAccount
This method resets the provided user account's password and create a new token for it.- Parameters:
account- Specifies the user account to reset.
-
createLoginLink
This method create a login link for the specified user account.- Parameters:
account- Specifies the user account for which the login link is created.- Returns:
- a URL that can be used for user login with a token.
-
loadDetailsByToken
This method load user account details based on a token string.- Parameters:
tokenString- Specifies the token string used for authentication.- Returns:
- the user account associated with the provided token.
-
resetToken
This method reset the one-time token for a user account.- Parameters:
account- Specifies the user account for which the token needs to be reset.
-
createToken
This method create a one-time token for a user account.- Parameters:
account- Specifies the user account for which the token needs to be created.
-
main
This main method demonstrate how to make a new account services object.- Parameters:
args- the command-line arguments.
-
setEmailVerified
This method set the email verification status for a user account.- Parameters:
account- Specifies the user account for which the email verification status should be set.
-
findAccountByEmail
This method find a user account by its email address.- Parameters:
email- Specifies the email address of the user account to find.- Returns:
- the user account with the specified email address.
-
changePassword
This method changes the password for a user account.- Parameters:
userName- Specifies the user name (email address) for the account.currentPassword- Specifies the current password.newPassword- Specifies the new password.
-