Class UserController
java.lang.Object
com.JesacaLin.GrubGoblin_v13.controllers.UserController
@PreAuthorize("isAuthenticated()")
@RestController
@RequestMapping("/app_user")
public class UserController
extends Object
Controller for managing User entities.
-
Constructor Summary
ConstructorsConstructorDescriptionUserController
(UserDAO userDAO) Constructs a new UserController with the given UserDAO. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRoleToUser
(String username, String role) Adds a role to a User.createUser
(User user) Creates a new User.int
deleteUser
(String username) Deletes a User by its username.getRolesForUser
(String username) Retrieves all roles for a given User.getUserByUsername
(String username) Retrieves a User by its username.Retrieves all Users.void
removeRoleFromUser
(String username, String role) Removes a role from a User.updateUser
(String username, User user, Principal principal) Updates a User.
-
Constructor Details
-
UserController
Constructs a new UserController with the given UserDAO.- Parameters:
userDAO
- the UserDAO to use for user management
-
-
Method Details
-
listOfUsers
-
getUserByUsername
-
createUser
-
updateUser
@PreAuthorize("hasAuthority(\'contributor\') or hasAuthority(\'admin\')") @PutMapping("/{username}") public User updateUser(@PathVariable String username, @RequestBody User user, Principal principal) Updates a User.- Parameters:
username
- the username of the User to updateuser
- the User data to update- Returns:
- the updated User if the authorized user is same user.
-
deleteUser
@PreAuthorize("hasAuthority(\'admin\')") @DeleteMapping("/{username}") public int deleteUser(@PathVariable String username) Deletes a User by its username.- Parameters:
username
- the username of the User to delete- Returns:
- the number of rows affected by the delete
-
getRolesForUser
-
addRoleToUser
-
removeRoleFromUser
-