浏览代码

fix: OAuth2 配置跳过

zhangying 1 周之前
父节点
当前提交
5051052cca

+ 5 - 0
zjrs-service-backend/pom.xml

@@ -396,6 +396,11 @@
             <artifactId>ojdbc11</artifactId>
             <version>23.2.0.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.springframework.boot</groupId>
+            <artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
+        </dependency>
     </dependencies>
 
     <build>

+ 3 - 7
zjrs-service-backend/src/main/java/com/zjrs/ZjrsServiceBackendApplication.java

@@ -14,22 +14,18 @@ import org.springframework.context.annotation.FilterType;
                         type = FilterType.REGEX,
                         pattern = "org\\.mohrss\\.leaf\\.ext\\.feign\\.filter\\..*"
                 ),
-                // 如果之前那个 ContextInterceptor 也报错,一并屏蔽
                 @ComponentScan.Filter(
                         type = FilterType.ASSIGNABLE_TYPE,
                         classes = {
                                 org.mohrss.leaf.ext.feign.filter.LeafFilterAutoConfiguration.class
                         }
                 ),
-                @ComponentScan.Filter(
-                        type = FilterType.ASSIGNABLE_TYPE,
-                        classes = {org.mohrss.leaf.auth.security.ContextInterceptor.class}
-                ),
                 @ComponentScan.Filter(
                         type = FilterType.ASSIGNABLE_TYPE,
                         classes = {
-                                org.mohrss.leaf.auth.security.ContextConfiguraction.class, // 排除配置类
-                                org.mohrss.leaf.auth.security.ContextInterceptor.class    // 排除拦截器类
+                                org.mohrss.leaf.auth.security.ContextConfiguraction.class,
+                                org.mohrss.leaf.auth.security.ContextInterceptor.class,
+                                org.mohrss.leaf.auth.config.TokenAutoConfig.class
                         }
                 )
         }

+ 5 - 5
zjrs-service-backend/src/main/java/com/zjrs/config/ResourceConfig.java

@@ -49,11 +49,11 @@ public class ResourceConfig {
         );
 
         // 4. 开启 OAuth2 资源服务器支持 (现代版核心配置)
-        http.oauth2ResourceServer(oauth2 -> oauth2
-                .jwt(jwt -> {}) // 如果是 JWT 模式
-                .authenticationEntryPoint(new LeafAuthExceptionEntryPoint())
-                .accessDeniedHandler(leafAccessDeniedHandler)
-        );
+//        http.oauth2ResourceServer(oauth2 -> oauth2
+//                .jwt(jwt -> {}) // 如果是 JWT 模式
+//                .authenticationEntryPoint(new LeafAuthExceptionEntryPoint())
+//                .accessDeniedHandler(leafAccessDeniedHandler)
+//        );
 
         // 5. 插入自定义过滤器(方法级鉴权)
         if (leafOAuth2ResourceProperties.getJwt().isServiceAuthenticationEnabled()