【发布时间】:2014-09-15 00:22:47
【问题描述】:
我正在尝试开发 Spring Boot Web 应用程序并使用 Spring 安全 Java 配置对其进行保护。
按照here in Spring blog 的建议将我的静态网络资源放入“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 中?
【问题讨论】:
-
请注意,您可能需要add content security headers 到您的静态内容(包括任何默认/自定义错误页面)以防止点击劫持等漏洞
标签: spring-mvc spring-security spring-boot