httpSecurity
類似于spring security的xml配置文件命名空間配置中的
使用示例:
最基本的基于表單的配置如下。該配置將所有的url訪問權(quán)限設(shè)定為角色名稱為"ROLE_USER".同時(shí)也定義了內(nèi)存認(rèn)證模式:使用用戶名"user"和密碼“password”,角色"ROLE_USER"來認(rèn)證。
@Configuration @EnableWebSecurity public class FormLoginSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/").hasRole("USER") .and() .formLogin(); } @Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth .inMemoryAuthentication() .withUser("user") .password("password") .roles("USER"); } }