woody преди 3 месеца
родител
ревизия
fc5c1d442b

+ 25 - 6
framework-base/src/main/java/com/chelvc/framework/base/util/SpringUtils.java

@@ -4,6 +4,7 @@ import java.io.File;
 import java.io.IOException;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
 import java.util.Objects;
@@ -11,6 +12,7 @@ import java.util.function.Predicate;
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
+import com.chelvc.framework.common.util.ObjectUtils;
 import com.chelvc.framework.common.util.StringUtils;
 import lombok.NonNull;
 import lombok.extern.slf4j.Slf4j;
@@ -54,13 +56,30 @@ public final class SpringUtils {
      * @param patterns 匹配模式数组
      * @return true/false
      */
-    public static boolean isPath(String path, String... patterns) {
-        if (StringUtils.isEmpty(path) || patterns == null || patterns.length == 0) {
-            return false;
+    public static boolean isPath(String path, @NonNull String... patterns) {
+        if (StringUtils.notEmpty(path) && ObjectUtils.notEmpty(patterns)) {
+            for (String pattern : patterns) {
+                if (StringUtils.notEmpty(pattern) && PATH_MATCHER.match(pattern, path)) {
+                    return true;
+                }
+            }
         }
-        for (String pattern : patterns) {
-            if (StringUtils.notEmpty(pattern) && PATH_MATCHER.match(pattern, path)) {
-                return true;
+        return false;
+    }
+
+    /**
+     * 判断资源路径是否符合指定匹配模式
+     *
+     * @param path     资源路径
+     * @param patterns 匹配模式集合
+     * @return true/false
+     */
+    public static boolean isPath(String path, @NonNull Collection<String> patterns) {
+        if (StringUtils.notEmpty(path) && ObjectUtils.notEmpty(patterns)) {
+            for (String pattern : patterns) {
+                if (StringUtils.notEmpty(pattern) && PATH_MATCHER.match(pattern, path)) {
+                    return true;
+                }
             }
         }
         return false;

+ 0 - 2
framework-security/src/main/java/com/chelvc/framework/security/config/OAuthConfigurer.java

@@ -32,7 +32,6 @@ import org.springframework.aop.framework.AopProxyUtils;
 import org.springframework.beans.factory.ObjectProvider;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.core.env.Environment;
@@ -76,7 +75,6 @@ import org.springframework.security.web.access.AccessDeniedHandler;
 @Slf4j
 @EnableWebSecurity
 @RequiredArgsConstructor(onConstructor = @__(@Autowired))
-@ConditionalOnProperty(name = "security.oauth.enabled", havingValue = "true")
 public class OAuthConfigurer extends WebSecurityConfigurerAdapter {
     private final SecurityProperties properties;
     private final ApplicationContext applicationContext;

+ 0 - 5
framework-security/src/main/java/com/chelvc/framework/security/config/SecurityProperties.java

@@ -52,11 +52,6 @@ public class SecurityProperties {
          * 是否区分应用范围
          */
         private boolean scoped = false;
-
-        /**
-         * 是否启用认证
-         */
-        private boolean enabled = true;
     }
 
     /**

+ 6 - 0
framework-security/src/main/java/com/chelvc/framework/security/interceptor/SecurityValidateInterceptor.java

@@ -19,6 +19,7 @@ import com.chelvc.framework.base.context.Session;
 import com.chelvc.framework.base.context.SessionContextHolder;
 import com.chelvc.framework.base.interceptor.BufferedRequestWrapper;
 import com.chelvc.framework.base.util.HttpUtils;
+import com.chelvc.framework.base.util.SpringUtils;
 import com.chelvc.framework.common.exception.FrameworkException;
 import com.chelvc.framework.common.util.AssertUtils;
 import com.chelvc.framework.common.util.CodecUtils;
@@ -141,6 +142,11 @@ public class SecurityValidateInterceptor implements HandlerInterceptor, WebMvcCo
     @Override
     public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
             throws Exception {
+        // 忽略地址处理
+        if (SpringUtils.isPath(request.getRequestURI(), this.properties.getIgnores())) {
+            return true;
+        }
+
         // 请求头校验
         Session session = SessionContextHolder.getSession();
         if (session.getPlatform() == null || session.getTerminal() == null