Class SecurityService

java.lang.Object
com.jk.webstack.security.services.SecurityService
All Implemented Interfaces:
org.springframework.security.core.userdetails.UserDetailsService

public class SecurityService extends Object implements org.springframework.security.core.userdetails.UserDetailsService
This class provides user authentication and account management functionality for a web application.

It implements the UserDetailsService interface for loading user details and managing user accounts.

Version:
1.0
Author:
Dr. Jalal H. Kiswani
  • Constructor Details

    • SecurityService

      public SecurityService()
      This method constructs a new SecurityService.
  • Method Details

    • init

      protected void init()
      This method initializes the service, creating a default user and role if none exist.
    • loadUserByUsername

      public User loadUserByUsername(String username) throws org.springframework.security.core.userdetails.UsernameNotFoundException
      This method loads a user by their user name.
      Specified by:
      loadUserByUsername in interface org.springframework.security.core.userdetails.UserDetailsService
      Parameters:
      username - Specifies the user name of the user to load.
      Returns:
      the User object representing the loaded user.
      Throws:
      org.springframework.security.core.userdetails.UsernameNotFoundException - if the user is not found.
    • createAccount

      public User createAccount(String username, String firstname, String lastname, String password, UserRole role)
      This method create a user account with the provided details.
      Parameters:
      username - Specifies the user name 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.
      role - Specifies the UserRole associated with the new account.
      Returns:
      the User object representing the created account.
    • processNewAccount

      protected void processNewAccount(User account)
      This method process the creation of a new user account.
      Parameters:
      account - Specifies the new account.
    • processCurrentAccount

      protected void processCurrentAccount(User account)
      This method process an existing user account.
      Parameters:
      account - Specifies the existing account.
    • resetAccount

      public User resetAccount(String username)
      This method reset a user's account by generating a new password.
      Parameters:
      username - Specifies the user name of the account to reset.
      Returns:
      the User object representing the reset account.
    • resetAccount

      protected void resetAccount(User account)
      This method reset a user's account by generating a new password.
      Parameters:
      account - Specifies the account to reset.
    • findAccountUsername

      protected User findAccountUsername(String username)
      This method find a user account by user name.
      Parameters:
      username - Specifies the user name to search for.
      Returns:
      the User object representing the found account.
    • changePassword

      public void changePassword(String userName, String currentPassword, String newPassword)
      This method change a user's password.
      Parameters:
      userName - Specifies the user name of the user whose password is being changed.
      currentPassword - Specifies the user's current password.
      newPassword - Specifies the new password to set.