feat: SecurityContextHolder 에서 email 리턴 메서드 구현

This commit is contained in:
dongHyo
2022-05-31 20:05:09 +09:00
parent ed0f7b4b24
commit 09d2a5b68c

View File

@@ -0,0 +1,21 @@
package com.ticketing.server.global.security;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
public class SecurityUtil {
private SecurityUtil() {
}
public static String getCurrentUserEmail() {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null || authentication.getName() == null) {
throw new IllegalStateException("Security Context 에 인증 정보가 없습니다.");
}
return authentication.getName();
}
}