Package de.dlr.proseo.usermgr.rest
Class UserManager
java.lang.Object
de.dlr.proseo.usermgr.rest.UserManager
Service methods required to manage user accounts.
- Author:
- Dr. Thomas Bassler
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classException to indicate unmodified data to caller -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncountUsers(String mission) Count the users matching the specified mission, if anycreateUser(RestUser restUser) Create a user (optionally with direct authorities)voiddeleteUserByName(String username) Delete a user by user namegetUserByName(String username) Get a user by nameGet users by missionmodifyUser(String username, RestUser restUser) Update a user by user name If the password is changed, the password expiration date will be updated according to the password expiration period configured.(package private) static UsertoModelUser(RestUser restUser) Convert a user from REST format to the prosEO data model format (including directly assigned authorities)(package private) static RestUsertoRestUser(User modelUser) Convert a user from prosEO data model format to REST format (including directly assigned authorities)
-
Field Details
-
userRepository
Repository for User objects
-
-
Constructor Details
-
UserManager
public UserManager()
-
-
Method Details
-
toModelUser
Convert a user from REST format to the prosEO data model format (including directly assigned authorities)- Parameters:
restUser- the REST user to convert- Returns:
- the converted model user
- Throws:
IllegalArgumentException- if an invalid authority value was given
-
toRestUser
Convert a user from prosEO data model format to REST format (including directly assigned authorities)- Parameters:
modelUser- the model user to convert- Returns:
- the converted REST user
-
createUser
Create a user (optionally with direct authorities)- Parameters:
restUser- a Json representation of the new user- Returns:
- a Json representation of the user after creation (with ACL security identity ID)
- Throws:
IllegalArgumentException- if any of the input data was invalid
-
getUsers
public List<RestUser> getUsers(String mission, Integer recordFrom, Integer recordTo) throws jakarta.persistence.NoResultException, org.springframework.web.client.HttpClientErrorException Get users by mission- Parameters:
mission- the mission coderecordFrom- first record of filtered and ordered result to returnrecordTo- last record of filtered and ordered result to return- Returns:
- a list of Json objects representing the users authorized for the given mission
- Throws:
jakarta.persistence.NoResultException- if no user is found for the given missionorg.springframework.web.client.HttpClientErrorException- if the result list exceeds a configured maximum
-
getUserByName
public RestUser getUserByName(String username) throws IllegalArgumentException, jakarta.persistence.NoResultException Get a user by name- Parameters:
username- the user name- Returns:
- a Json object corresponding to the user found
- Throws:
IllegalArgumentException- if no user name was givenjakarta.persistence.NoResultException- if no user with the given name exists
-
deleteUserByName
public void deleteUserByName(String username) throws jakarta.persistence.EntityNotFoundException, RuntimeException Delete a user by user name- Parameters:
username- the name of the user to delete- Throws:
jakarta.persistence.EntityNotFoundException- if the user to delete does not exist in the databaseRuntimeException- if the deletion was not performed as expected
-
modifyUser
public RestUser modifyUser(String username, RestUser restUser) throws jakarta.persistence.EntityNotFoundException, IllegalArgumentException, UserManager.NotModifiedException Update a user by user name If the password is changed, the password expiration date will be updated according to the password expiration period configured. Note: This method cannot detect, whether a password was actually changed, because due to the BCrypt algorithm used the same password may yield different salted hashes with each encryption run. It is in the responsibility of the calling component to make sure that the password was indeed altered (and that it conforms to any applicable password policy).- Parameters:
username- the name of the user to updaterestUser- a Json object containing the modified (and unmodified) attributes- Returns:
- a response containing a Json object corresponding to the user after modification
- Throws:
jakarta.persistence.EntityNotFoundException- if no user with the given user name existsIllegalArgumentException- if any of the input data was invalidUserManager.NotModifiedException- if the user data was not modified (input data same as database data)
-
countUsers
Count the users matching the specified mission, if any- Parameters:
mission- the mission code- Returns:
- the number of users found as string
-