liusheng
2025-12-26 2944ea778f0fc87c8e09ae47200d9de8069049e3
ruoyi-framework/src/main/java/com/ruoyi/framework/config/SecurityConfig.java
@@ -25,8 +25,7 @@
 * @author ruoyi
 */
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    /**
     * 自定义用户认证逻辑
     */
@@ -60,6 +59,7 @@
    @Autowired
    private WxOpenIDAuthenticationSecurityConfig wxOpenIDAuthenticationSecurityConfig;
    /**
     * 解决 无法直接注入 AuthenticationManager
     *
@@ -68,8 +68,7 @@
     */
    @Bean
    @Override
    public AuthenticationManager authenticationManagerBean() throws Exception
    {
    public AuthenticationManager authenticationManagerBean() throws Exception {
        return super.authenticationManagerBean();
    }
@@ -89,8 +88,7 @@
     * authenticated       |   用户登录后可访问
     */
    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception
    {
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity
                //微信openid注入
                .apply(wxOpenIDAuthenticationSecurityConfig).and()
@@ -103,20 +101,20 @@
                // 过滤请求
                .authorizeRequests()
                // 对于登录login 注册register 验证码captchaImage 允许匿名访问
                .antMatchers("/login","/openidlogin", "/register", "/captchaImage", "/getToken").anonymous()
                .antMatchers("/login", "/openidlogin", "/register", "/captchaImage", "/getToken").anonymous()
                .antMatchers(
                        HttpMethod.GET,
                        "/",
                        "/*.html",
                        "/**/*.html",
                        "/**/*.css",
                        "/**/*.js"
//                        "/profile/**"
                        "/**/*.js",
                        "/profile/**"
                ).permitAll()
//                .antMatchers("/swagger-ui.html").anonymous()
//                .antMatchers("/swagger-resources/**").anonymous()
//                .antMatchers("/webjars/**").anonymous()
//                .antMatchers("/*/api-docs").anonymous()
                .antMatchers("/swagger-ui.html").permitAll()
                .antMatchers("/swagger-resources/**").permitAll()
                .antMatchers("/webjars/**").permitAll()
                .antMatchers("/*/api-docs").permitAll()
//                .antMatchers("/druid/**").anonymous()
                // 除上面外的所有请求全部需要鉴权认证
                .anyRequest().authenticated()
@@ -134,8 +132,7 @@
     * 强散列哈希加密实现
     */
    @Bean
    public BCryptPasswordEncoder bCryptPasswordEncoder()
    {
    public BCryptPasswordEncoder bCryptPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }
@@ -143,8 +140,7 @@
     * 身份认证接口
     */
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception
    {
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService).passwordEncoder(bCryptPasswordEncoder());
    }
}