File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
src/main/java/com/example/jwt_auth_server/controller Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change 11package com .example .jwt_auth_server .controller ;
22
33import java .util .HashMap ;
4+ import java .util .List ;
45import java .util .Map ;
56
67import org .springframework .http .ResponseEntity ;
8+ import org .springframework .security .access .prepost .PreAuthorize ;
79import org .springframework .security .core .Authentication ;
810import org .springframework .security .core .context .SecurityContextHolder ;
911import org .springframework .security .core .userdetails .UsernameNotFoundException ;
1012import org .springframework .web .bind .annotation .GetMapping ;
1113import org .springframework .web .bind .annotation .RequestMapping ;
1214import org .springframework .web .bind .annotation .RestController ;
1315
16+ import com .example .jwt_auth_server .model .User ;
1417import com .example .jwt_auth_server .service .UserService ;
1518
1619@ RestController
@@ -23,6 +26,13 @@ public UserController(UserService userService) {
2326 this .userService = userService ;
2427 }
2528
29+ @ GetMapping
30+ @ PreAuthorize ("hasRole('ADMIN')" )
31+ public ResponseEntity <List <User >> getAllUsers () {
32+ List <User > users = userService .getAllUsers ();
33+ return ResponseEntity .ok (users );
34+ }
35+
2636 @ GetMapping ("/me" )
2737 public ResponseEntity <?> getCurrentUser () {
2838 Authentication authentication = SecurityContextHolder .getContext ().getAuthentication ();
You can’t perform that action at this time.
0 commit comments