From e56faa3cb343954f085c092a4d78a341ec72cdc7 Mon Sep 17 00:00:00 2001 From: mjkhan21 Date: Tue, 5 Mar 2024 18:22:10 +0900 Subject: [PATCH] =?UTF-8?q?getId(Object)=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cokr/xit/base/security/SecuredUserInfo.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/cokr/xit/base/security/SecuredUserInfo.java b/src/main/java/cokr/xit/base/security/SecuredUserInfo.java index 0c67f63..8696e2a 100644 --- a/src/main/java/cokr/xit/base/security/SecuredUserInfo.java +++ b/src/main/java/cokr/xit/base/security/SecuredUserInfo.java @@ -60,6 +60,20 @@ public class SecuredUserInfo extends UserInfo implements UserDetails { private List authorities; private boolean sealed; + @Override + public String getId(Object auth) { + UserInfo userInfo = null; + if (auth instanceof Authentication) { + Object obj = ((Authentication)auth).getPrincipal(); + if (obj instanceof UserInfo) + userInfo = (UserInfo)obj; + } + if (userInfo == null) + throw new RuntimeException(String.format("Unable to get a UserInfo from %s", auth)); + + return userInfo.getId(); + } + @Override public List getAuthorities() { return authorities != null ? authorities : Collections.emptyList();