-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApiController.java
More file actions
31 lines (26 loc) · 1.09 KB
/
ApiController.java
File metadata and controls
31 lines (26 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package org.javaspringcourse.controller;
import org.javaspringcourse.dto.UserInfo;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ApiController {
@GetMapping("/public/api")
public String publicApi() {
return "Hello World";
}
@GetMapping("/admin/api")
public UserInfo getAdminInfo(@AuthenticationPrincipal UserDetails user) {
return new UserInfo(user.getUsername(), user.getAuthorities().stream()
.map(GrantedAuthority::getAuthority)
.toList());
}
@GetMapping("/support/api")
public UserInfo getSupportUserInfo(@AuthenticationPrincipal UserDetails user) {
return new UserInfo(user.getUsername(), user.getAuthorities().stream()
.map(GrantedAuthority::getAuthority)
.toList());
}
}