標籤:security dex public 完整 bat 簡單 web應用 htm org
準備工作
首先,構建一個簡單的Web工程,以用於後續添加安全控制,若對如何使用Spring Boot構建Web應用,可以先閱讀《Spring Boot開發Web應用》一文。
Web層實現請求映射
@Controllerpublic class HelloController { @RequestMapping("/") public String index() { return "index"; } @RequestMapping("/hello") public String hello() { return "hello"; } }
/:映射到index.html
/hello:映射到hello.html
實現映射的頁面
- src/main/resources/templates/index.html
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <title>Spring Security入門</title> </head> <body> <h1>歡迎使用Spring Security!</h1> <p>點擊 <a th:href="@{/hello}">這裡</a> 打個招呼吧</p> </body></html>
src/main/resources/templates/hello.html
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <title>Hello World!</title> </head> <body> <h1>Hello world!</h1> </body></html>
可以看到在index.html中提供到/hello的連結,顯然在這裡沒有任何安全控制,所以點選連結後就可以直接跳轉到hello.html頁面。完整項目的源碼來源 支援人員1791743380
Spring Cloud Spring Boot mybatis分布式微服務雲架構(十三)使用Spring Security安全控制