【发布时间】:2017-05-02 07:44:40
【问题描述】:
我正在使用带有 Spring Security 的 Spring Boot 创建启用 SSL 的 Web 应用程序(手动创建的 SSL 文件)。一切正常,但是,每当我尝试访问任何静态资源(如 css 或 js 文件)时,它都无法找到这些文件并显示以下错误:
来自“https://localhost:8443/css/lib/index.css”的资源由于 MIME 类型不匹配(X-Content-Type-Options: nosniff)而被阻止。
不仅登录页面会发生这种情况,其他页面也会发生这种情况。成功登录后,我也收到此错误。
以下是我的安全配置:
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/css/**"/*, "/js/**", "/img/**", "/error"*/).permitAll()
.anyRequest().fullyAuthenticated()
.and()
.formLogin()
.loginPage("/login").permitAll()
.defaultSuccessUrl("/home", true)
.successHandler(authSuccessHandler)
.and()
.headers()
.frameOptions().sameOrigin()
.httpStrictTransportSecurity().disable()
.and()
.logout().addLogoutHandler(new LogoutHandler() {
@Override
public void logout(HttpServletRequest request,HttpServletResponse response, Authentication authentication) {
request.getSession().invalidate();
}
})
.logoutUrl("/logout").permitAll().logoutSuccessUrl("/login")
.invalidateHttpSession(true).logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.deleteCookies("JSESSIONID")
.and()
.sessionManagement().maximumSessions(1);
}
css文件放在以下路径:
src/main/resources/public/css/lib/index.csss
我正在使用 Freemarker,下面是我如何调用这个 css 文件:
<link rel="stylesheet" href="/css/lib/index.css" type="text/css" media="screen" charset="utf-8"/>
我在这里做错了什么?
【问题讨论】:
-
您是否尝试禁用content-type-options?
-
我试过 .headers() .frameOptions().sameOrigin() .httpStrictTransportSecurity().disable()
-
尝试禁用 contect_type_options.only 没有嗅探警告。但仍然得到 404
-
你会关心发布请求并响应 index.css 的 http 标头吗?使用 Chrome 应该很容易。来自 web.debug(true) 的日志也会有所帮助。
-
你能告诉我如何在 chrome 中做到这一点吗?
标签: java spring spring-mvc spring-boot spring-security