public String hello() {
return “hello”;
}
}
-
/
:映射到index.html -
/hello
:映射到hello.html
实现映射的页面
- src/main/resources/templates/index.html
欢迎使用Spring Security!
点击 这里 打个招呼吧
- src/main/resources/templates/hello.html
xmlns:sec=“http://www.thymeleaf.org/thymeleaf-extras-springsecurity3”>
Hello world!
可以看到在index.html中提供到/hello
的链接,显然在这里没有任何安全控制,所以点击链接后就可以直接跳转到hello.html页面。
整合Spring Security
在这一节,我们将对/hello
页面进行权限控制,必须是授权用户才能访问。当没有权限的用户访问后,跳转到登录页面。
添加依赖
在pom.xml中添加如下配置,引入对Spring Security的依赖。
…
org.springframework.boot
spring-boot-starter-security
…