Package com.inesm.KeyManager.services
Class UserManager
java.lang.Object
com.inesm.KeyManager.services.UserManager
Provides all functionalities regarding user management.
-
Constructor Summary
ConstructorsConstructorDescriptionUserManager(UserRepository rep, CryptographyService crypto, SettingsService settings) Constructor for the User Manager class. -
Method Summary
Modifier and TypeMethodDescriptionvoidchangePassword(User user) Updates a user password in the database.createRole(Role role) Creates a new role in the database.createUser(User user) Creates a user in the database.voiddeleteRequest(long requestID) Deletes a request from the database.voiddeleteRole(long roleID) Deletes a role from the database.voiddeleteUser(String username) Deletes a user from the database.Gets all available operations from the database.getRoles()Gets all roles from the database.getUserByUsername(String username) Gets a user from the database.getUsers()Gets all users from the database.Performs a login operation using password authentication.loginUser2FA(String username, String password) Performs a login operation using password authentication and smartcard authentication.Patches a user.updateRole(Role role) Updates a role in the database.
-
Constructor Details
-
UserManager
@Autowired public UserManager(UserRepository rep, CryptographyService crypto, SettingsService settings) Constructor for the User Manager class.- Parameters:
rep- the user repository used to interface with the databasecrypto- the cryptographic service used to hash and validate user passwordssettings- the settings service that holds user related settings
-
-
Method Details
-
loginUser2FA
public User loginUser2FA(String username, String password) throws ObjectNotFoundException, InvalidLoginException, LoginAttemptLockedException, ResourceLockedException Performs a login operation using password authentication and smartcard authentication. Method currently implemented using the Portuguese Citizen Card for the smartcard authentication. Checks if the smartcard information is valid , and if the supplied password matches the stored password.- Parameters:
username- the username of the userpassword- the password of the user- Returns:
- the user object of the supplied username
- Throws:
ObjectNotFoundException- if the user was not found in the databaseInvalidLoginException- if the login operation failed due to password mismatch, citizenCard info mismatch, or smartcard authentication failure or an hashing operation errorLoginAttemptLockedException- if the user is currently locked from attempting loginsResourceLockedException- if the user is not active- See Also:
-
loginUser
public User loginUser(String username, String password) throws ObjectNotFoundException, InvalidLoginException, LoginAttemptLockedException, ResourceLockedException Performs a login operation using password authentication. Checks if the supplied password matches the stored password.- Parameters:
username- the username of the userpassword- the password of the user- Returns:
- the user object of the supplied username
- Throws:
ObjectNotFoundException- if the user was not found in the databaseInvalidLoginException- if the login operation failed due to password mismatch, or an hashing operation errorLoginAttemptLockedException- if the user is currently locked from attempting loginsResourceLockedException- if the user is not active- See Also:
-
getUsers
Gets all users from the database.- Returns:
- a list contained the retrieved users
-
getUserByUsername
Gets a user from the database.- Parameters:
username- the username of the user- Returns:
- the user retrieved
- Throws:
ObjectNotFoundException- if the referenced user could not be found
-
createUser
Creates a user in the database.- Parameters:
user- the user object to be created- Returns:
- the created user
- Throws:
InvalidParametersException- if the user object received contained any invalid parametersHashingErrorException- if an exception occurred when attempting to hash the user password
-
patchUser
Patches a user. Will update all fields set in the update, and replace them with the original user's fields.- Parameters:
update- the user object contained the fields to be updated, not null, must have username set- Returns:
- the updated user object
- Throws:
ObjectNotFoundException- if the user was not foundInvalidParametersException- if the user update contained invalid parameters
-
deleteUser
Deletes a user from the database.- Parameters:
username- the username of the user to be deleted- Throws:
ObjectNotFoundException- if the user specified could not be found.
-
changePassword
Updates a user password in the database. Sets the temporary password field to false.- Parameters:
user- the user to be updated, not null, must have the username and password fields set.- Throws:
HashingErrorException- if an exception occurred hashing the user passwordObjectNotFoundException- if the user could not be found
-
getRoles
Gets all roles from the database.- Returns:
- a list contained all the retrieved roles
-
createRole
Creates a new role in the database.- Parameters:
role- the role to be created- Returns:
- the created role
- Throws:
InvalidParametersException- if the role contained invalid parameters
-
updateRole
public Role updateRole(Role role) throws ObjectNotFoundException, ResourceLockedException, InvalidParametersException Updates a role in the database.- Parameters:
role- the role containing the fields to be updated, not null, must have roleID set- Returns:
- the update role
- Throws:
ObjectNotFoundException- if the role could not be foundResourceLockedException- if the role attempting to be updated is the default admin roleInvalidParametersException- if the role contained invalid parameters
-
deleteRole
public void deleteRole(long roleID) throws RoleCurrentlyAssignedException, ObjectNotFoundException, ResourceLockedException Deletes a role from the database.- Parameters:
roleID- the roleID of the role to be deleted- Throws:
RoleCurrentlyAssignedException- if the role is currently assign to a userObjectNotFoundException- if the role specified could not be foundResourceLockedException- if the role is the default admin role (not allowed to be deleted)
-
getOperations
Gets all available operations from the database.- Returns:
- the list containing all the operations retrieved
-
deleteRequest
Deletes a request from the database.- Parameters:
requestID- the requestID of the request to be deleted- Throws:
ObjectNotFoundException- if the referenced request could not be found
-