<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
@RequestMapping("level1/{id}")
public String level1(@PathVariable int id){
return "views/level1/"+id;
}
@RequestMapping("level2/{id}")
public String level2(@PathVariable int id){
return "views/level2/"+id;
}
@RequestMapping("level3/{id}")
public String level3(@PathVariable int id){
return "views/level3/"+id;
}
public class SecurityConfig extends WebSecurityConfigurerAdapter{
}
WebSecurityConfigurerAdapter是WebSecurity适配器,自动帮我们配置Security,重写调用configure()方法进行认证和授权
@EnableWebSecurity 开启Springboot的Security功能
AuthenticationManagerBuilder是自定义认证的载体
授权的载体是 HttpSecurity
额外包含 login、logout、RememberMe 功能
<html lang="en"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/extras/spring-security">