P.1-SpringSecurity简介、P.2-入门案例准备、P.3入门案例引入SpringSecurity

P1.SpringSecurity简介

  SpringSecurity是Spring家族中的一个安全管理框架。

    一般Web应用的需要进行认证和授权

      认证:验证当前访问系统的是否是本系统的用户,并且要确认具体是那个用户

      授权:经过认证后判断当前用户是否有权限进行某个操作

        注:认证和授权也是SpringSecurity做为安全框架的核心功能

P2.入门案例准备

  1创建Spring boot工程

  

   2注入相关依赖

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
</dependencies>

  创建启动类

  创建Controller层进行测试

P3.入门案例引入SpringSecurity

  整合SpringSecurity

<!--Spring Security 启动器-->
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-security</artifactId>
</dependency>

  再重启SpringBoot项目

  网址访问路径会自动更换

  

  页面也会随之改变

  

  默认的用户名是user

  密码会在控制层自动生成

  

  登录后会跳转新的页面

  

  默认退出是logout

 

posted @ 2023-04-25 09:27  ja不会va  阅读(21)  评论(0编辑  收藏  举报