【发布时间】:2017-05-06 00:30:12
【问题描述】:
在我的 Spring Boot 应用程序中,我将 Spring Security 配置为
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.antMatchers("/css/**", "/js/**", "/images/**", "**/index.html").permitAll()
.antMatchers("/**.html").permitAll()
.antMatchers(HttpMethod.POST, "/login").permitAll()
.anyRequest().authenticated()
.and()
.addFilterBefore(new LoginFilter("/login"), BasicAuthenticationFilter.class)
.addFilterBefore(new TokenFilter(), BasicAuthenticationFilter.class);
}
}
我在resources/static/index.html 下有index.html。在我启用安全性后,它停止了服务。我错过了什么?
如果我在没有任何安全性的情况下返回,我会在服务器上呈现我的 HTML。
【问题讨论】:
-
.antMatchers("/*.html").permitAll() 对你有用吗?我的印象是 ** 用于目录, * 用于字符:docs.spring.io/spring-framework/docs/current/javadoc-api/org/…
-
这也不起作用
-
您是否使用
@Configuration注释了您的WebSecurityConfig类?并显示您的LoginFilter和TokenFilter。 -
你得到什么回应? 401、403 或 ...
标签: java spring spring-boot spring-security