允许在没有spring安全认证的情况下使用静态资源
嗨,我在我的web应用程序中集成了spring安全性。我的允许在没有spring安全认证的情况下使用静态资源,spring,spring-boot,spring-security,Spring,Spring Boot,Spring Security,嗨,我在我的web应用程序中集成了spring安全性。我的configure()方法被覆盖为 @Override protected void configure( HttpSecurity http ) throws Exception { http.cors().and().csrf().disable().authorizeRequests().antMatchers(HttpMethod.POST, "/rest/auth/**").permitAll()
configure()
方法被覆盖为
@Override
protected void configure( HttpSecurity http ) throws Exception
{
http.cors().and().csrf().disable().authorizeRequests().antMatchers(HttpMethod.POST, "/rest/auth/**").permitAll()
.antMatchers("/resources/static/**")
.permitAll().antMatchers("/").permitAll().anyRequest().authenticated().and()
.addFilter(new JWTAuthenticationFilter(authenticationManager()))
.addFilter(new JWTAuthorizationFilter(authenticationManager()));
}
我的项目结构如图所示。但是spring安全性实际上不允许在没有身份验证的情况下使用资源。在
WebSecurityConfig.java
中,如果删除.anyRequest().authenticated()
,则允许浏览器呈现css
和js
。如何解决这个问题 /resources/static
可能应该是/static
/I给出的/static/**
,它不起作用。您还需要配置匿名()
以允许匿名访问。您是否尝试过@Override public void configure(WebSecurity web)抛出异常{web.ignering().antMatchers(“/resources/static/**”);}
@M.Deinum如何配置匿名()
?/resources/static
应该是/static
/I给定的/static/**
,它不起作用您还需要配置匿名()
以允许匿名访问。您尝试过@覆盖公共无效配置(WebSecurity web)引发异常{web.ignering().antMatchers(“/resources/static/**”);}
@M.Deinum如何配置匿名()
?