|
@@ -4,8 +4,10 @@ package com.diagbot.util;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
+import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* @Description: 用户工具类
|
|
@@ -25,13 +27,23 @@ public class UserUtils {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 获取当前请求的用户Id
|
|
|
+ * 获取当前请求的用户名称
|
|
|
* @return
|
|
|
*/
|
|
|
public static String getCurrentPrinciple() {
|
|
|
return (String) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取当前请求的用户ID
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String getCurrentPrincipleID() {
|
|
|
+ OAuth2AuthenticationDetails oauthDetails = (OAuth2AuthenticationDetails) SecurityContextHolder.getContext().getAuthentication().getDetails();
|
|
|
+ Map<String, Object> details = (Map<String, Object>) oauthDetails.getDecodedDetails();
|
|
|
+ return details.get("user_id").toString();
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 判读当前token用户是否为接口所需的参数username
|
|
|
*
|