Skip to content

Commit

Permalink
[SHIBUI-1058]
Browse files Browse the repository at this point in the history
Added permissions checks to user controller endpoints (except for the
getCurrentUser).
  • Loading branch information
Bill Smith committed Jan 25, 2019
1 parent e43056b commit eb73a80
Showing 1 changed file with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand Down Expand Up @@ -48,6 +49,7 @@ public UsersController(UserRepository userRepository, RoleRepository roleReposit
this.userService = userService;
}

@Secured("ROLE_ADMIN")
@Transactional(readOnly = true)
@GetMapping
public List<User> getAll() {
Expand All @@ -65,12 +67,14 @@ public ResponseEntity<?> getCurrentUser() {
}
}

@Secured("ROLE_ADMIN")
@Transactional(readOnly = true)
@GetMapping("/{username}")
public ResponseEntity<?> getOne(@PathVariable String username) {
return ResponseEntity.ok(findUserOrThrowHttp404(username));
}

@Secured("ROLE_ADMIN")
@Transactional
@DeleteMapping("/{username}")
public ResponseEntity<?> deleteOne(@PathVariable String username) {
Expand All @@ -79,6 +83,7 @@ public ResponseEntity<?> deleteOne(@PathVariable String username) {
return ResponseEntity.noContent().build();
}

@Secured("ROLE_ADMIN")
@Transactional
@PostMapping
ResponseEntity<?> saveOne(@RequestBody User user) {
Expand All @@ -96,6 +101,7 @@ ResponseEntity<?> saveOne(@RequestBody User user) {
return ResponseEntity.ok(savedUser);
}

@Secured("ROLE_ADMIN")
@Transactional
@PatchMapping("/{username}")
ResponseEntity<?> updateOne(@PathVariable(value = "username") String username, @RequestBody User user) {
Expand Down

0 comments on commit eb73a80

Please sign in to comment.