15
15
import jakarta .validation .Valid ;
16
16
import lombok .RequiredArgsConstructor ;
17
17
import lombok .extern .log4j .Log4j2 ;
18
+ import org .springframework .context .annotation .Profile ;
19
+ import org .springframework .core .env .Environment ;
18
20
import org .springframework .http .HttpStatus ;
19
21
import org .springframework .http .MediaType ;
20
22
import org .springframework .http .ResponseEntity ;
24
26
import org .springframework .security .core .Authentication ;
25
27
import org .springframework .security .core .context .SecurityContextHolder ;
26
28
import org .springframework .security .core .userdetails .UsernameNotFoundException ;
29
+ import org .springframework .security .oauth2 .core .oidc .user .OidcUser ;
27
30
import org .springframework .validation .annotation .Validated ;
28
31
import org .springframework .web .bind .annotation .GetMapping ;
29
32
import org .springframework .web .bind .annotation .PostMapping ;
30
33
import org .springframework .web .bind .annotation .RequestBody ;
31
34
import org .springframework .web .bind .annotation .RestController ;
32
35
36
+ import java .io .IOException ;
33
37
import java .security .Principal ;
34
38
35
39
@ RestController
@@ -41,7 +45,7 @@ public class AuthController {
41
45
private final JwtService jwtService ;
42
46
private final AuthService authService ;
43
47
private final FindUserService findUserService ;
44
-
48
+ private final Environment environment ;
45
49
46
50
@ PostMapping ("/api/v1/login" )
47
51
public ResponseEntity <?> login (@ Valid @ RequestBody AuthRequestDTO authRequestDTO , HttpServletRequest request , HttpServletResponse response ) {
@@ -95,13 +99,29 @@ public ResponseEntity<StatusDTO> changePassword(@Valid @RequestBody PassRequestD
95
99
96
100
@ PreAuthorize ("hasAuthority('USER')" )
97
101
@ GetMapping ("/api/v1/hc" )
98
- public ResponseEntity <String > hc () {
102
+ public ResponseEntity <StatusDTO > hc (Principal principal ) {
103
+ UserInfo userInfo = findUserService .findUser (principal .getName ());
99
104
try {
100
- return new ResponseEntity <>("" , HttpStatus .OK );
105
+ return new ResponseEntity <>(new StatusDTO (userInfo .getHighestRole ()), HttpStatus .OK );
106
+ } catch (Exception e ){
107
+ throw new RuntimeException (e );
108
+ }
109
+ }
110
+
111
+ @ GetMapping ("/api/v1/status" )
112
+ public ResponseEntity <StatusDTO > status () {
113
+ String [] activeProfiles = environment .getActiveProfiles ();
114
+ String profile = "" ;
115
+ if (activeProfiles .length > 0 ) {
116
+ profile = activeProfiles [0 ];
117
+ }
118
+ try {
119
+ return new ResponseEntity <>(new StatusDTO (profile ), HttpStatus .OK );
101
120
} catch (Exception e ){
102
121
throw new RuntimeException (e );
103
122
}
104
123
}
124
+
105
125
@ PreAuthorize ("hasAuthority('ADMIN')" )
106
126
@ GetMapping ("/api/v1/hc/admin" )
107
127
public ResponseEntity <String > hcAdmin () {
0 commit comments