Ver Fonte

修改网关服务器,增加authorizeExcepiton异常

郭志波 há 6 anos atrás
pai
commit
d45df3b8ad

+ 21 - 0
src/main/java/com/leanwo/gateway/exception/AuthorizeException.java

@@ -0,0 +1,21 @@
+package com.leanwo.gateway.exception;
+
+import javax.ws.rs.ext.Provider;
+
+/**
+ * 访问权限异常,返回给前端401,前端会跳转到登陆界面
+ * @author YangZhiJie
+ *
+ */
+@Provider
+public class AuthorizeException extends RuntimeException {
+	
+	public AuthorizeException(){
+		
+	}
+	
+	public AuthorizeException(String message){
+		super(message);
+	}
+
+}

+ 2 - 6
src/main/java/com/leanwo/gateway/util/FeignConfig.java

@@ -21,6 +21,7 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
 import com.auth0.jwt.JWT;
 import com.auth0.jwt.algorithms.Algorithm;
 import com.auth0.jwt.exceptions.JWTCreationException;
+import com.leanwo.gateway.exception.AuthorizeException;
 import com.leanwo.gateway.exception.TokenException;
 
 import feign.RequestInterceptor;
@@ -55,12 +56,7 @@ public class FeignConfig implements RequestInterceptor {
         LoginContext loginContext = LoginContextUtil.getLoginContext();
 
         if (loginContext == null) {
-        	// 临时的解决办法,后面前端会加token验证
-        	String token = generateRegisterToken();
-            loginContext = new LoginContext();
-            loginContext.setToken(token);
-            loginContext.setAccountId(2L);            
-//            throw new AuthorizeException("您没有权限调用业务服务器。");
+            throw new AuthorizeException("您没有权限调用业务服务器。");
         }
         String token = loginContext.getToken();
         logger.info("jwtToken:" + token);