Jas*_*son 7 spring spring-security spring-boot spring-java-config
我想使用Java Config在Spring Boot中定义类似于此XML的内容.
<http pattern="/webservices/**" security="none"/>
我需要一种不同的方法来保护它们,不能进行表单登录.保护他们将在以后到来.现在,我想停止使用http.formLogin()来保护它们.
我已经覆盖了WebSecurityConfigurerAdapter.configure().我找不到要说的API,像这样:
http.securityNone().antMatchers("/webservices")
这是我的configure()方法:
@Override
protected void configure(HttpSecurity http) throws Exception
http.csrf().disable();
http.headers().frameOptions().disable();
http.authorizeRequests()
.antMatchers("/resources/**",
//"/services/**", THIS LOGS IN AUTOMATICALLY AS 'ANONYMOUS'. NO GOOD!
//"/remoting/**", THIS LOGS IN AUTOMATICALLY AS 'ANONYMOUS'. NO GOOD!
"/pages/login",
"/pages/loginFailed").permitAll()
// Only authenticated can access these URLs and HTTP METHODs
.antMatchers("/secured/**").authenticated()
.antMatchers(HttpMethod.HEAD,"/**").authenticated()
.antMatchers(HttpMethod.GET,"/**").authenticated()
.antMatchers(HttpMethod.POST,"/**").authenticated()
.antMatchers(HttpMethod.PUT,"/**").authenticated()
.antMatchers(HttpMethod.DELETE,"/**").authenticated();
// Accept FORM-based authentication
http.formLogin()
.failureUrl("/pages/loginFailed")
.defaultSuccessUrl("/")
.loginPage("/pages/login")
.permitAll()
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/pages/logout"))
.logoutSuccessUrl("/pages/login")
.permitAll();
http.formLogin().successHandler(new AppLoginSuccessHandler());
}
Run Code Online (Sandbox Code Playgroud)
Art*_*lan 16
根据WebSecurityConfigurerAdapterJavaDocs:
/**
* Override this method to configure {@link WebSecurity}. For
* example, if you wish to ignore certain requests.
*/
public void configure(WebSecurity web) throws Exception {
}
Run Code Online (Sandbox Code Playgroud)
你可以这样做:
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring()
.antMatchers("/webservices/**");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5017 次 |
| 最近记录: |