spring boot 登陆控制类 HttpSecurity http
例子:
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
antMatchers表示ant风格通配符
regexmatchers表示正则通配符
相对ant风格,我想正则更适合我
http.authorizeRequests().antMatchers("/","home"); http.authorizeRequests().regexMatchers("");
authenticated()和permitAll()来定义该如何保护路径。authenticated()要求在执行该请求时,必须已经登录了应用。如果用户没有认证,Spring Security的Filter将会捕获该请求,并将用户重定向到应用的登录界面。同时permitAll()方法允许请求没有任何的安全限制。除了authenticated()和permitAll()以外,authorizeRequests()方法返回的对象还有更多的方法用于细粒度地保护请求。如下所示: