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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addRoleToUser
(String username, String roleName) Adds a role to the user with the given usernameRetrieves the user with the given usernamegetUsers()
Retrieves all users from the databaseorg.springframework.security.core.userdetails.UserDetails
loadUserByUsername
(String username) Loads the user by its usernameSaves a new role to the databaseSaves a new user to the database
-
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 interfaceorg.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
Saves a new user to the database- Specified by:
saveUser
in interfaceUserServiceInterface
- Parameters:
user
- the user to be saved- Returns:
- the saved user
-
saveRole
Saves a new role to the database- Specified by:
saveRole
in interfaceUserServiceInterface
- Parameters:
role
- the role to be saved- Returns:
- the saved role
-
addRoleToUser
Adds a role to the user with the given username- Specified by:
addRoleToUser
in interfaceUserServiceInterface
- Parameters:
username
- the username of the user to add the role toroleName
- the name of the role to be added
-
getUser
Retrieves the user with the given username- Specified by:
getUser
in interfaceUserServiceInterface
- Parameters:
username
- the username to search for- Returns:
- the user with the given username
-
getUsers
Retrieves all users from the database- Specified by:
getUsers
in interfaceUserServiceInterface
- Returns:
- a list of all users
-