zoukankan      html  css  js  c++  java
  • Spring security 知识笔记【入门】

    一、生成spring boot项目文件

    二、pom文件如下

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>
    
        <groupId>com.Eleven</groupId>
        <artifactId>Eleven</artifactId>
        <version>1.0-SNAPSHOT</version>
        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>2.2.0.M2</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-security</artifactId>
            </dependency>
        </dependencies>
    
    </project>

    二、Spring Boot启动文件

    package Eleven;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.web.servlet.ServletComponentScan;
    
    @SpringBootApplication
    @ServletComponentScan   //扫描过滤器等servlet、filter注解
    public class ElevenApplication {
        public static void main(String[] args){
            SpringApplication.run(ElevenApplication.class,args);
        }
    }

    三、新建两个controller

    package Eleven.controller;
    
    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RestController;
    
    
    
    
    @RestController
    public class AuthenticationTestController {
        @GetMapping("/user")
        public String helloWorld(){
            return "This is a user page!";
        }
    
        @GetMapping("/admin/test/*")
        public String getAdminInfo(){
            return "This is Admin page!";
        }
    
    
    
    }

    四、启动后,访问controller路径,提示需要登录,默认用户user,默认的密码是动态的,已在控制台输出

    五、登录后可显示controller的内容

    六、自定义用户名、密码

    在配置文件(application.properties)中增加以下

    spring.security.user.name = admin
    spring.security.user.password = 123456
  • 相关阅读:
    692. 前K个高频单词
    准备工作:更新代码和运行环境
    1319. 连通网络的操作次数——并查集
    <leetcode c++>25. K 个一组翻转链表
    织梦dedecms手机站关闭自动生成首页index.html
    IIS7 IIS7.5 伪静态 web.config 配置方法不带WWW的301跳转到带WWW
    win7和xp一样有左下角显示桌面快捷方式
    Win7系统传真与扫描功能无法使用的处理方法
    织梦dedecms将列表页重复的第一页去除的方法
    秦岭土蜂蜜价格 秦岭土蜂蜜多少钱一斤
  • 原文地址:https://www.cnblogs.com/Eleven-Liu/p/11142746.html
Copyright © 2011-2022 走看看