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