免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2061 | 回复: 0
打印 上一主题 下一主题

Spring Cloud Spring Boot mybatis分布式微服务云架构(十三)使用Spring Security... [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2018-06-14 11:22 |只看该作者 |倒序浏览
准备工作

首先,构建一个简单的Web工程,以用于后续添加安全控制,也可以用之前Chapter3-1-2做为基础工程。若对如何使用Spring Boot构建Web应用,可以先阅读《Spring Boot开发Web应用》一文。

Web层实现请求映射
  1. @Controller
  2. public class HelloController {

  3.     @RequestMapping("/")
  4.     public String index() {
  5.         return "index";
  6.     }

  7.     @RequestMapping("/hello")
  8.     public String hello() {
  9.         return "hello";
  10.     }

  11. }
复制代码
  • /:映射到index.html
  • /hello:映射到hello.html
实现映射的页面
  • src/main/resources/templates/index.html
    1. <!DOCTYPE html>
    2. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
    3.     <head>
    4.         <title>Spring Security入门</title>
    5.     </head>
    6.     <body>
    7.         <h1>欢迎使用Spring Security!</h1>
    8.         <p>点击 <a th:href="@{/hello}">这里</a> 打个招呼吧</p>
    9.     </body>
    10. </html>
    复制代码
    src/main/resources/templates/hello.html
    1. <!DOCTYPE html>
    2. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
    3.       xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
    4.     <head>
    5.         <title>Hello World!</title>
    6.     </head>
    7.     <body>
    8.         <h1>Hello world!</h1>
    9.     </body>
    10. </html>
    复制代码
    可以看到在index.html中提供到/hello的链接,显然在这里没有任何安全控制,所以点击链接后就可以直接跳转到hello.html页面。


您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP