我在Spring Security中使用Spring引导1.3.2。 我具有以下配置(HttpSecurity HTTP)方法来INFORCE认证Spring Boot安全性不会通过WebSecurity忽略certian url
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网)方法忽略一些如下面的网址;
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers(
"/myapp/docs/**",
"/myapp/docs/*",
"/myapp/docs/index.html",
"/resources/**",
"/static/**");
}
但HTTP请求http://127.0.0.1:9000/myapp/docs/index.html仍然reuires用户名/密码(验证),并返回“状态”:401,“错误”:“未授权” ......其实没有上WebSecurity忽略网址的 是因为工作它也需要认证。如果我提供了auth,那么它就可以工作。我怎么能在这里简单地忽略一些网址(比如“/ myapp/docs/**”)。我已经
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled =真) 公共类SecurityConfig扩展WebSecurityConfigurerAdapter以下的SecurityConfig类定义{
我缺少什么?请指教。
谢谢您的答复,但你的建议,我的“/艾姆斯/ W/*”不受保护的。我可以找到所有这些网址; “/ iams/docs/**”,“/ iams/w/*”和“/ iams/api/*”没有基本身份验证。以下是根据您的建议设置的。在这里我想用用户名/密码保护“/ iams/w”和“/ iams/api /”,但是让所有人都可以在没有用户名/密码的情况下进入“/ iams/docs/*”。这是基于spring引导的restful实现,但想要公开一些像docs这样的url,以便它可以被所有人访问而不是api调用。 – lotse