Browse Source

uat环境禁止访问api文档

wuweihao 5 years ago
parent
commit
833d6f59f0

+ 11 - 0
xiaoan-common/src/main/java/com/xiaoan/common/interceptor/CommonInterceptor.java

@@ -16,6 +16,9 @@ import javax.servlet.http.PushBuilder;
 @Component
 public class CommonInterceptor implements HandlerInterceptor {
 
+    @Value("${spring.profiles.active}")
+    private String active;
+
     @Override
     public boolean preHandle(HttpServletRequest request,
                              HttpServletResponse response, Object handler) throws Exception {
@@ -24,6 +27,14 @@ public class CommonInterceptor implements HandlerInterceptor {
                 && !request.getRequestURI().contains(".html") && !request.getRequestURI().contains(".mp3")){
             log.warn("start : {}", request.getRequestURI());
         }
+
+
+        // uat环境禁止访问api文档
+        if (active.equals("dev")) {
+            log.info("访问api文档拦截");
+            return !request.getRequestURI().contains("doc.html");
+        }
+
         return true;
     }
 

+ 27 - 0
xiaoan-common/src/main/java/com/xiaoan/common/util/FileUtils.java

@@ -14,6 +14,7 @@ import java.text.SimpleDateFormat;
 import java.util.Base64;
 import java.util.Date;
 import java.util.Enumeration;
+import java.util.Properties;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
@@ -115,6 +116,32 @@ public class FileUtils {
         }
     }
 
+
+    /**
+     * 读取配置文件值
+     * @param key : 配置文件key
+     * @return
+     */
+    public String getValue(String key){
+        log.info("run getValue");
+        log.info("key: {}", key);
+        Properties prop = new Properties();
+
+        // 需要用这这方式获取路径,有些方式放到tomcat不灵
+        String resource = FileUtils.getResource("application.properties");
+        log.info("path: {}", resource);
+        FileInputStream in = null;
+        try {
+            in = new FileInputStream(resource);
+            prop.load(in);
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        String property = prop.getProperty(key);
+        log.info("value: {}", property);
+        return prop.getProperty(key);
+    }
+
     /**
      * 大文件读写
      *

+ 0 - 35
xiaoan-web/src/main/java/com/xiaoan/web/shiro/ShiroConfig.java

@@ -3,7 +3,6 @@ package com.xiaoan.web.shiro;
 import com.alibaba.fastjson.serializer.SerializerFeature;
 import com.alibaba.fastjson.support.config.FastJsonConfig;
 import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter;
-import com.xiaoan.common.util.FileUtils;
 import lombok.extern.log4j.Log4j2;
 import org.apache.shiro.mgt.DefaultSessionStorageEvaluator;
 import org.apache.shiro.mgt.DefaultSubjectDAO;
@@ -19,8 +18,6 @@ import org.springframework.context.annotation.DependsOn;
 import org.springframework.http.MediaType;
 
 import javax.servlet.Filter;
-import java.io.FileInputStream;
-import java.io.IOException;
 import java.util.*;
 
 @Log4j2
@@ -83,14 +80,6 @@ public class ShiroConfig {
         filterRuleMap.put("/v2/**", "anon");
         filterRuleMap.put("/swagger-ui.html/**", "anon");
 
-//        String active = getValue("spring.profiles.active");
-//        log.info("active: {}", active);
-////
-////        // 正式环境拦截swagger
-//        if ("sit".equals(active)) {
-//            filterRuleMap.put("/doc.html", "jwt");
-////            filterRuleMap.put("/**/doc.html", "jwt");
-//        }
 
         // 所有请求通过我们自己的JWT Filter
         filterRuleMap.put("/api/manage/**", "jwt");
@@ -165,30 +154,6 @@ public class ShiroConfig {
 
 
 
-    /**
-     * 读取配置文件值
-     * @param key : 配置文件key
-     * @return
-     */
-    public String getValue(String key){
-        log.info("run getValue");
-        log.info("key: {}", key);
-        Properties prop = new Properties();
-
-        // 需要用这这方式获取路径,有些方式放到tomcat不灵
-        String resource = FileUtils.getResource("application.properties");
-        log.info("path: {}", resource);
-        FileInputStream in = null;
-        try {
-            in = new FileInputStream(resource);
-            prop.load(in);
-        } catch (IOException e) {
-            e.printStackTrace();
-        }
-        String property = prop.getProperty(key);
-        log.info("value: {}", property);
-        return prop.getProperty(key);
-    }
 
 
 }