wlzboy
2025-11-09 fa5ea853099e88be253fca4fb2b0c2b7af5f396e
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
@@ -20,6 +20,7 @@
import com.ruoyi.framework.security.filter.JwtAuthenticationTokenFilter;
import com.ruoyi.framework.security.handle.AuthenticationEntryPointImpl;
import com.ruoyi.framework.security.handle.LogoutSuccessHandlerImpl;
import com.ruoyi.framework.security.WechatAuthenticationProvider;
import com.ruoyi.common.annotation.Anonymous;
import org.springframework.security.web.util.matcher.RequestMatcher;
import org.springframework.web.method.HandlerMethod;
@@ -78,6 +79,12 @@
    private RequestMappingHandlerMapping requestMappingHandlerMapping;
    /**
     * 微信认证提供者
     */
    @Autowired
    private WechatAuthenticationProvider wechatAuthenticationProvider;
    /**
     * 获取所有标注了@Anonymous的URL
     */
    private Set<String> getAnonymousUrls() {
@@ -89,21 +96,27 @@
            if (anonymous != null) {
                Set<String> patterns = entry.getKey().getPatternValues();
                urls.addAll(patterns);
                System.out.println("✅ 检测到匿名接口: " + patterns + " - " + handlerMethod.getMethod().getName());
            }
        }
        System.out.println("📜 所有匿名接口列表: " + urls);
        return urls;
    }
    /**
     * 身份验证实现
     * 支持用户名密码认证和微信认证
     */
    @Bean
    public AuthenticationManager authenticationManager()
    {
        // 用户名密码认证提供者
        DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
        daoAuthenticationProvider.setUserDetailsService(userDetailsService);
        daoAuthenticationProvider.setPasswordEncoder(bCryptPasswordEncoder());
        return new ProviderManager(daoAuthenticationProvider);
        // 返回ProviderManager,支持多种认证方式
        return new ProviderManager(daoAuthenticationProvider, wechatAuthenticationProvider);
    }
    /**