feat: add shared Keycloak compose baseline
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.example.keycloakpattern;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.security.core.annotation.AuthenticationPrincipal;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
public class ApiController {
|
||||
|
||||
@GetMapping("/public")
|
||||
public Map<String, String> publicEndpoint() {
|
||||
return Map.of("status", "ok", "service", "keycloak-pattern-api");
|
||||
}
|
||||
|
||||
@GetMapping("/me")
|
||||
public Map<String, Object> currentUser(@AuthenticationPrincipal Jwt jwt) {
|
||||
Map<String, Object> response = new LinkedHashMap<>();
|
||||
response.put("subject", jwt.getSubject());
|
||||
response.put("username", jwt.getClaimAsString("preferred_username"));
|
||||
response.put("issuer", jwt.getIssuer());
|
||||
response.put("audience", jwt.getAudience());
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user