Analytics 서비스 및 보안 기능 업데이트
- Analytics 서비스 구현 추가 (API, 소스 코드) - Event 서비스 소스 코드 추가 - 보안 관련 공통 컴포넌트 업데이트 (JWT, UserPrincipal, ErrorCode) - API 컨벤션 및 명세서 업데이트 - 데이터베이스 SQL 스크립트 추가 - 백엔드 개발 문서 및 테스트 가이드 추가 - Kafka 메시지 체크 도구 추가 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -18,6 +18,10 @@ public enum ErrorCode {
|
||||
COMMON_004("COMMON_004", "서버 내부 오류가 발생했습니다"),
|
||||
COMMON_005("COMMON_005", "지원하지 않는 작업입니다"),
|
||||
|
||||
// 일반 에러 상수 (Legacy 호환용)
|
||||
NOT_FOUND("NOT_FOUND", "요청한 리소스를 찾을 수 없습니다"),
|
||||
INVALID_INPUT_VALUE("INVALID_INPUT_VALUE", "유효하지 않은 입력값입니다"),
|
||||
|
||||
// 인증/인가 에러 (AUTH_XXX)
|
||||
AUTH_001("AUTH_001", "인증에 실패했습니다"),
|
||||
AUTH_002("AUTH_002", "유효하지 않은 토큰입니다"),
|
||||
|
||||
@@ -12,6 +12,7 @@ import javax.crypto.SecretKey;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* JWT 토큰 생성 및 검증 제공자
|
||||
@@ -49,17 +50,20 @@ public class JwtTokenProvider {
|
||||
* Access Token 생성
|
||||
*
|
||||
* @param userId 사용자 ID
|
||||
* @param storeId 매장 ID
|
||||
* @param email 이메일
|
||||
* @param name 이름
|
||||
* @param roles 역할 목록
|
||||
* @return Access Token
|
||||
*/
|
||||
public String createAccessToken(Long userId, String email, String name, List<String> roles) {
|
||||
|
||||
public String createAccessToken(Long userId, Long storeId, String email, String name, List<String> roles) {
|
||||
Date now = new Date();
|
||||
Date expiryDate = new Date(now.getTime() + accessTokenValidityMs);
|
||||
|
||||
return Jwts.builder()
|
||||
.subject(userId.toString())
|
||||
.claim("storeId", storeId != null ? storeId.toString() : null)
|
||||
.claim("email", email)
|
||||
.claim("name", name)
|
||||
.claim("roles", roles)
|
||||
@@ -76,7 +80,7 @@ public class JwtTokenProvider {
|
||||
* @param userId 사용자 ID
|
||||
* @return Refresh Token
|
||||
*/
|
||||
public String createRefreshToken(Long userId) {
|
||||
public String createRefreshToken(UUID userId) {
|
||||
Date now = new Date();
|
||||
Date expiryDate = new Date(now.getTime() + refreshTokenValidityMs);
|
||||
|
||||
@@ -95,9 +99,9 @@ public class JwtTokenProvider {
|
||||
* @param token JWT 토큰
|
||||
* @return 사용자 ID
|
||||
*/
|
||||
public Long getUserIdFromToken(String token) {
|
||||
public UUID getUserIdFromToken(String token) {
|
||||
Claims claims = parseToken(token);
|
||||
return Long.parseLong(claims.getSubject());
|
||||
return UUID.fromString(claims.getSubject());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -110,12 +114,14 @@ public class JwtTokenProvider {
|
||||
Claims claims = parseToken(token);
|
||||
|
||||
Long userId = Long.parseLong(claims.getSubject());
|
||||
String storeIdStr = claims.get("storeId", String.class);
|
||||
Long storeId = storeIdStr != null ? Long.parseLong(storeIdStr) : null;
|
||||
String email = claims.get("email", String.class);
|
||||
String name = claims.get("name", String.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> roles = claims.get("roles", List.class);
|
||||
|
||||
return new UserPrincipal(userId, email, name, roles);
|
||||
return new UserPrincipal(userId, storeId, email, name, roles);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.kt.event.common.security;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
@@ -8,6 +9,7 @@ import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
@@ -15,13 +17,24 @@ import java.util.stream.Collectors;
|
||||
* JWT 토큰에서 추출한 사용자 정보를 담는 객체
|
||||
*/
|
||||
@Getter
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class UserPrincipal implements UserDetails {
|
||||
|
||||
/**
|
||||
* 사용자 ID
|
||||
*/
|
||||
private final Long userId;
|
||||
private final UUID userId;
|
||||
|
||||
/**
|
||||
* 매장 ID
|
||||
*/
|
||||
private final UUID storeId;
|
||||
|
||||
/**
|
||||
* 매장 ID
|
||||
*/
|
||||
private final Long storeId;
|
||||
|
||||
/**
|
||||
* 사용자 이메일
|
||||
|
||||
Reference in New Issue
Block a user