feat: add shared Keycloak compose baseline

This commit is contained in:
donghyeon-ka
2026-07-25 13:14:58 +09:00
parent 1eeff83d0b
commit f47dea3e24
17 changed files with 532 additions and 1 deletions
@@ -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;
}
}