|
@@ -1,6 +1,7 @@
|
|
|
package com.xy.utils;
|
|
|
|
|
|
import cn.dev33.satoken.stp.StpUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpRequest;
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
@@ -11,14 +12,16 @@ import com.xy.consts.CommConsts;
|
|
|
import com.xy.entity.SysMenuJoinSysRoleMenu;
|
|
|
import com.xy.enums.SaTokenEnum;
|
|
|
import com.xy.error.CommRuntimeException;
|
|
|
-import lombok.AllArgsConstructor;
|
|
|
+import com.xy.error.HttpHandler;
|
|
|
import lombok.Data;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import lombok.experimental.Accessors;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
import org.springframework.web.context.request.RequestContextHolder;
|
|
|
import org.springframework.web.context.request.ServletRequestAttributes;
|
|
|
|
|
|
+import javax.annotation.PostConstruct;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.Serializable;
|
|
|
import java.util.ArrayList;
|
|
@@ -29,9 +32,20 @@ import java.util.Map;
|
|
|
* 权限工具类
|
|
|
*/
|
|
|
@Component
|
|
|
-@AllArgsConstructor
|
|
|
+@RequiredArgsConstructor
|
|
|
public class AuthorizeUtils {
|
|
|
|
|
|
+ private HttpHandler httpHandler;
|
|
|
+
|
|
|
+ private static AuthorizeUtils authorizeUtils;
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void init() {
|
|
|
+ authorizeUtils = this;
|
|
|
+ authorizeUtils.httpHandler = this.httpHandler;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
protected static AuthorizeConfig getAuthorizeConfig() {
|
|
|
AuthorizeConfig authorizeConfig = SpringBeanUtils.getBean(AuthorizeConfig.class);
|
|
|
if (authorizeConfig.getIsNative() == null) {
|
|
@@ -71,9 +85,6 @@ public class AuthorizeUtils {
|
|
|
public static String getToken() {
|
|
|
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
|
|
|
String token = request.getHeader(CommConsts.TOKEN_NAME);
|
|
|
- if (StringUtils.isEmpty(token)) {
|
|
|
- throw new CommRuntimeException(SaTokenEnum.NO_LOGIN.getKey(), SaTokenEnum.NO_LOGIN.getName());
|
|
|
- }
|
|
|
return token;
|
|
|
}
|
|
|
|
|
@@ -110,6 +121,9 @@ public class AuthorizeUtils {
|
|
|
* @return
|
|
|
*/
|
|
|
public static <T> T getLoginId(String token, Class<T> tClass) {
|
|
|
+ if (StrUtil.isEmpty(token)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
Object id;
|
|
|
//远程调用
|
|
|
AuthorizeConfig authorizeConfig = getAuthorizeConfig();
|