准备工作

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

Web层实现请求映射

1
2
3
4
5
6
7
8
9
10
11
12
13
14
@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

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <!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
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <!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页面。

使用Spring Security安全控制(二十六)的更多相关文章

  1. Spring Security(二十六):8. Spring Security Community

    8.1 Issue Tracking Spring Security uses JIRA to manage bug reports and enhancement requests. If you ...

  2. Spring Security(二十九):9.4.1 ExceptionTranslationFilter

    ExceptionTranslationFilter is a Spring Security filter that has responsibility for detecting any Spr ...

  3. Spring Security(三十六):12. Spring MVC Test Integration

    Spring Security provides comprehensive integration with Spring MVC Test Spring Security提供与Spring MVC ...

  4. Spring Security(二十八):9.4 Authentication in a Web Application

    Now let’s explore the situation where you are using Spring Security in a web application (without we ...

  5. Spring Security(二十五):7. Sample Applications

    There are several sample web applications that are available with the project. To avoid an overly la ...

  6. Spring Security(二十四):6.6 The Authentication Manager and the Namespace

    The main interface which provides authentication services in Spring Security is the AuthenticationMa ...

  7. Spring Security(二十二):6.4 Method Security

    From version 2.0 onwards Spring Security has improved support substantially for adding security to y ...

  8. Spring Security(二十):6.2.3 Form and Basic Login Options

    You might be wondering where the login form came from when you were prompted to log in, since we mad ...

  9. 二十六:Struts2 和 spring整合

    二十六:Struts2 和 spring整合 将项目名称为day29_02_struts2Spring下的scr目录下的Struts.xml文件拷贝到新项目的scr目录下 在新项目的WebRoot-- ...

  10. Spring Security 解析(二) —— 认证过程

    Spring Security 解析(二) -- 认证过程   在学习Spring Cloud 时,遇到了授权服务oauth 相关内容时,总是一知半解,因此决定先把Spring Security .S ...

随机推荐

  1. git 恢复单个文件的历史版本

    首先查看该文件的历史版本信息:git log Default@2x.png 记录下需要恢复的commit版本号:如 9aa51d89799716aa68cff3f30c26f8815408e926 恢 ...

  2. Centos7 linux下通过源码安装redis以及使用

    下载redis安装包 wget http://download.redis.io/releases/redis-5.0.3.tar.gz 解压压缩包 tar -zxvf redis-.tar.gz y ...

  3. 搭建Nuget服务器

    1.新建一个web网站应用程序 (最好是ASP.NET空Web应用程序) 2.通过NuGet扩展 引用 NuGet.Server包 引用之后的项目结构为 将此网站部署到IIS上,即可访问,既搭建好了 ...

  4. MVC6 发布IIS

    asp.net5的MVC6发布出来的结果和MVC5之前版本的相差太远了,直接在本地的IIS服务器上面是不可能运行的. 看了汤姆大叔的MVC6项目发布与部署,讲了很多丰富的知识点.但是对于立即要解决问题 ...

  5. 如何直接执行js代码

    安装node.js 进入cmd ,输入node js文件名

  6. @Scope注解设置创建bean的方式和生命周期

    1.1.1            Scope注解创建bean的方式和生命周期 作用 Scope设置对象在spring容器(IOC容器)中的生命周期,也可以理解为对象在spring容器中的创建方式. 取 ...

  7. Mac Anaconda 简单介绍 -- 环境管理

    Anaconda Anaconda(官方网站)就是可以便捷获取包且对包能够进行管理,同时对环境可以统一管理的发行版本.Anaconda包含了conda.Python在内的超过180个科学包及其依赖项. ...

  8. 基于 Spring Cloud 完整的微服务架构实战

    本项目是一个基于 Spring Boot.Spring Cloud.Spring Oauth2 和 Spring Cloud Netflix 等框架构建的微服务项目. @作者:Sheldon地址:ht ...

  9. HTML 第十三章总结

    前言 这一章的内容主要是处理 HTML 中的 tabular data,可以分为三个部分: 如何在 HTML 中创建表格 如何在 CSS 中 style 表格 如何在 CSS 中 style HTML ...

  10. php安装soap等扩展的方式: 已经安装了php却发现少安装了一下扩展

    php安装soap等扩展的方式: 已经安装了php却发现少安装了一下扩展 1.首先确认下php.ini的安装位置 我的安装目录是: /usr/local/php 一般位置: /usr/local/ph ...