Class UserService

java.lang.Object
com.dada.banking_project.services.impl.UserService
All Implemented Interfaces:
UserServiceInterface, org.springframework.security.core.userdetails.UserDetailsService

@Service public class UserService extends Object implements UserServiceInterface, org.springframework.security.core.userdetails.UserDetailsService
  • Constructor Details

    • UserService

      public UserService()
  • Method Details

    • loadUserByUsername

      public org.springframework.security.core.userdetails.UserDetails loadUserByUsername(String username) throws org.springframework.security.core.userdetails.UsernameNotFoundException
      Loads the user by its username
      Specified by:
      loadUserByUsername in interface org.springframework.security.core.userdetails.UserDetailsService
      Parameters:
      username - the username to search for
      Returns:
      the UserDetails object that matches the given username
      Throws:
      org.springframework.security.core.userdetails.UsernameNotFoundException - if the user with the given username is not found
    • saveUser

      public User saveUser(User user)
      Saves a new user to the database
      Specified by:
      saveUser in interface UserServiceInterface
      Parameters:
      user - the user to be saved
      Returns:
      the saved user
    • saveRole

      public Role saveRole(Role role)
      Saves a new role to the database
      Specified by:
      saveRole in interface UserServiceInterface
      Parameters:
      role - the role to be saved
      Returns:
      the saved role
    • addRoleToUser

      public void addRoleToUser(String username, String roleName)
      Adds a role to the user with the given username
      Specified by:
      addRoleToUser in interface UserServiceInterface
      Parameters:
      username - the username of the user to add the role to
      roleName - the name of the role to be added
    • getUser

      public User getUser(String username)
      Retrieves the user with the given username
      Specified by:
      getUser in interface UserServiceInterface
      Parameters:
      username - the username to search for
      Returns:
      the user with the given username
    • getUsers

      public List<User> getUsers()
      Retrieves all users from the database
      Specified by:
      getUsers in interface UserServiceInterface
      Returns:
      a list of all users