ITPub博客

首页 > IT职业 > IT图书 > 使用Spring Security安全控制

使用Spring Security安全控制

IT图书 作者:corespeed 时间:2021-09-09 09:19:54 0 删除 编辑

准备工作

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

Web层实现请求映射

@Controller  
public 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

html>  
  
      
        Spring Security入门  
      
      
        

欢迎使用Spring Security!

           

点击  打个招呼吧

         

src/main/resources/templates/hello.html

html>  
  
      
        Hello World!  
      
      
        

Hello world!

         

可以看到在index.html中提供到/hello的链接,显然在这里没有任何安全控制,所以点击链接后就可以直接跳转到hello.html页面。源码来源

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4440/viewspace-2802269/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: Spring AOP入门
请登录后发表评论 登录
全部评论

注册时间:2019-09-09

  • 博文量
    90
  • 访问量
    1012