- Full Java 21 + Spring Boot 3.3 backend with Virtual Threads - HikariCP connection pool for Oracle ADB - JWT auth, Redis caching, OCI GenAI integration - YouTube transcript extraction via API + Playwright browser fallback - SSE streaming for bulk operations - Scheduled daemon for channel scanning/video processing - Mobile UI: collapse restaurant list to single row on selection - Switch PM2 ecosystem config to Java backend Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
44 lines
1.4 KiB
Java
44 lines
1.4 KiB
Java
package com.tasteby.security;
|
|
|
|
import io.jsonwebtoken.Claims;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
import org.springframework.web.server.ResponseStatusException;
|
|
|
|
/**
|
|
* Utility to extract current user info from SecurityContext.
|
|
*/
|
|
public final class AuthUtil {
|
|
|
|
private AuthUtil() {}
|
|
|
|
public static Claims getCurrentUser() {
|
|
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
|
if (auth == null || !(auth.getPrincipal() instanceof Claims)) {
|
|
throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, "Not authenticated");
|
|
}
|
|
return (Claims) auth.getPrincipal();
|
|
}
|
|
|
|
public static Claims getCurrentUserOrNull() {
|
|
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
|
if (auth == null || !(auth.getPrincipal() instanceof Claims)) {
|
|
return null;
|
|
}
|
|
return (Claims) auth.getPrincipal();
|
|
}
|
|
|
|
public static Claims requireAdmin() {
|
|
Claims user = getCurrentUser();
|
|
if (!Boolean.TRUE.equals(user.get("is_admin", Boolean.class))) {
|
|
throw new ResponseStatusException(HttpStatus.FORBIDDEN, "관리자 권한이 필요합니다");
|
|
}
|
|
return user;
|
|
}
|
|
|
|
public static String getUserId() {
|
|
return getCurrentUser().getSubject();
|
|
}
|
|
}
|