【发布时间】:2016-09-10 06:23:51
【问题描述】:
我正在使用带有 Spring Security 的 Spring boot 1.3.2。 我有以下 configure(HttpSecurity http) 方法来强制身份验证
protected void configure(HttpSecurity http) throws Exception {
RequestMatcher csrfRequestMatcher = new RequestMatcher() {
private AntPathRequestMatcher[] requestMatchers = {
new AntPathRequestMatcher("/iams/w/*")
};
@Override
public boolean matches(HttpServletRequest request) {
for (AntPathRequestMatcher rm : requestMatchers) {
if (rm.matches(request)) { return true; }
}
return false;
} // method matches
};
http
.csrf()
.requireCsrfProtectionMatcher(csrfRequestMatcher)
.and()
.authorizeRequests()
.anyRequest().authenticated()
.and()
.requestCache()
.requestCache(new NullRequestCache())
.and()
.httpBasic();
}
我有以下 configure(WebSecurity web) 方法来忽略下面的一些 url;
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(
"/myapp/docs/**",
"/myapp/docs/*",
"/myapp/docs/index.html",
"/resources/**",
"/static/**");
}
但是对 http://127.0.0.1:9000/myapp/docs/index.html 的 http 请求仍然需要用户名/密码(身份验证)并返回 "status":401,"error":"Unauthorized"... 实际上,WebSecurity 上的任何忽略 url 都不起作用,因为它还需要身份验证。如果我提供身份验证,那么它可以工作。我怎样才能在这里简单地忽略一些网址(例如 "/myapp/docs/**" )。我在 SecurityConfig 类中有以下定义
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true) 公共类 SecurityConfig 扩展 WebSecurityConfigurerAdapter {
我错过了什么?请指教。
【问题讨论】:
标签: spring-security spring-boot restful-authentication