我正在尝试开发Spring Boot Web应用程序,并使用Spring Security Java配置对其进行安全保护。
根据Spring博客中的建议,将我的静态Web资源放置在“src/main/resources/public”中后,我能够获取静态资源。也就是说,在浏览器中输入https://localhost/test.html
可以提供HTML内容。
问题
启用Spring Security后,访问静态资源URL需要进行身份验证。
我相关的Spring Security Java配置如下:
@Override
protected void configure(HttpSecurity http) throws Exception {
// @formatter:off
http.
authorizeRequests()
.antMatchers("/","/public/**", "/resources/**","/resources/public/**")
.permitAll()
.antMatchers("/google_oauth2_login").anonymous()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/")
.loginProcessingUrl("/login")
.defaultSuccessUrl("/home")
.and()
.csrf().disable()
.logout()
.logoutSuccessUrl("/")
.logoutUrl("/logout") // POST only
.and()
.requiresChannel()
.anyRequest().requiresSecure()
.and()
.addFilterAfter(oAuth2ClientContextFilter(),ExceptionTranslationFilter.class)
.addFilterAfter(googleOAuth2Filter(),OAuth2ClientContextFilter.class)
.userDetailsService(userService);
// @formatter:on
}
我该如何配置 antMatchers 来允许放置在 src/main/resources/public 内的静态资源?