-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR(#65) from feature/security-utils-#64 Security Context 에서 회원 …
…정보를 편하게 가져오기 위한 유틸리티 클래스
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
src/main/java/com/t3t/frontserver/auth/util/SecurityContextUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.t3t.frontserver.auth.util; | ||
|
||
import org.springframework.security.core.context.SecurityContextHolder; | ||
|
||
public class SecurityContextUtils { | ||
|
||
private static final String ANONYMOUS_USER = "anonymousUser"; | ||
|
||
/** | ||
* 유틸리티 클래스이므로 인스턴스화를 방지한다. | ||
* | ||
* @author woody35545(구건모) | ||
*/ | ||
private SecurityContextUtils() { | ||
throw new IllegalStateException("Utility class"); | ||
} | ||
|
||
/** | ||
* 현재 로그인한 사용자의 식별자를 조회한다. | ||
* | ||
* @return 현재 로그인한 사용자의 식별자, 로그인하지 않은 경우 null | ||
* @author woody35545(구건모) | ||
*/ | ||
public static Long getMemberId() { | ||
if (!isLoggedIn()) { | ||
return null; | ||
} | ||
return Long.parseLong(SecurityContextHolder.getContext().getAuthentication().getName()); | ||
} | ||
|
||
/** | ||
* 현재 사용자가 로그인 상태인지 확인한다. | ||
* | ||
* @return 로그인 상태 여부 | ||
* @author woody35545(구건모) | ||
*/ | ||
public static boolean isLoggedIn() { | ||
return SecurityContextHolder.getContext().getAuthentication() == null || | ||
!ANONYMOUS_USER.equals(SecurityContextHolder.getContext().getAuthentication().getName()); | ||
} | ||
} |