繁体   English   中英

具有安全性的Spring Boot不提供我的静态内容

[英]Spring Boot with Security is not serving my static content

嗨,这是我的安全配置文件,我正在使用Spring Boot 2.0.6.RELEASE,我的静态内容文件仅在static文件夹中,位于static-> css,js,图像,字体

我已经尝试了所有其他帖子解决方案,但没有一个对我有用,并且静态内容仍然是安全样式,没有得到应用等。

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final String[] PUBLIC_MATCHER = {"/css/**","/js/**","/fonts/**","/images/**", "/"};

    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http
            .authorizeRequests()
            .antMatchers(PUBLIC_MATCHER)
            .permitAll().anyRequest().authenticated()
            .and()
            .csrf().disable().cors().disable()
            .formLogin().failureUrl("/login?error").defaultSuccessUrl("/dashboard")
            .loginPage("/login").permitAll()
            .and()
            .logout().logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
            .logoutSuccessUrl("/?logout").deleteCookies("remember-me").permitAll()
            .and()
            .rememberMe();

       }
    }
 }

在您的安全配置文件中添加此方法,希望它可以工作

//this method allows static resources to be neglected by spring security
        @Override
        public void configure(WebSecurity web) throws Exception {
            web
                .ignoring()
                .antMatchers("/resources/**", "/static/**","/css/**","/js/**","/fonts/**","/images/**");
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM