Ver Fonte

鉴于 StoreLocalCache 中的值是动态变化的, 所以应该直接调用它提供的方法的来获取相应的值

reghao há 2 anos atrás
pai
commit
c0bed47ca7

+ 3 - 2
oss-store/src/main/java/cn/reghao/oss/store/inerceptor/AccessLogInterceptor.java

@@ -20,10 +20,10 @@ import javax.servlet.http.HttpServletResponse;
 @Slf4j
 @Component
 public class AccessLogInterceptor implements HandlerInterceptor {
-    private final String referFrom;
+    private final StoreLocalCache storeLocalCache;
 
     public AccessLogInterceptor(StoreLocalCache storeLocalCache) {
-        this.referFrom = storeLocalCache.getReferer();
+        this.storeLocalCache = storeLocalCache;
     }
 
     @Override
@@ -42,6 +42,7 @@ public class AccessLogInterceptor implements HandlerInterceptor {
             return true;
         }
 
+        String referFrom = storeLocalCache.getReferer();
         String objectName = uri.replaceFirst("/", "");
         if (objectName.startsWith("img/")) {
             return true;

+ 3 - 3
oss-store/src/main/java/cn/reghao/oss/store/inerceptor/TokenFilter.java

@@ -16,10 +16,10 @@ import java.io.IOException;
  */
 @Component
 public class TokenFilter implements Filter {
-    private final String secretKey;
+    private final StoreLocalCache storeLocalCache;
 
     public TokenFilter(StoreLocalCache storeLocalCache) {
-        this.secretKey = storeLocalCache.getSecretKey();
+        this.storeLocalCache = storeLocalCache;
     }
 
     @Override
@@ -32,7 +32,7 @@ public class TokenFilter implements Filter {
         int userId = -1;
         String token = ServletUtil.getBearerToken(request);
         if (token != null) {
-            OssPayload ossPayload = JwtUtil.getOssPayload(token, secretKey);
+            OssPayload ossPayload = JwtUtil.getOssPayload(token, storeLocalCache.getSecretKey());
             userId = ossPayload.getUserId();
         }