SpringSecurity - 实战 RBAC(一)

前言

通过 SpringSecurity 学习专栏 中几篇文章的学习,我们 初识SpringSecurity,也分析了 SpringSecurity启动流程。接下来我们就以典型的 RBAC模型 为例,来做一个实战项目

技术选型

截至到发文时,SpringBoot 最新的 GA 版本为 2.7.2

  • SpringBoot2.7.2
  • SpringSecurity5.7.2
  • 前端:vue-element-admin

实战

1、创建项目

在这里插入图片描述

2、pom.xml

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.7.2</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>boot-admin-example</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>boot-admin-example</name>
    <description>boot-admin-example</description>
    
    <properties>
        <java.version>1.8</java.version>
        <maven.compiler.source>${java.version}</maven.compiler.source>
        <maven.compiler.target>${java.version}</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
    
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </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>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <excludes>
                        <exclude>
                            <groupId>org.projectlombok</groupId>
                            <artifactId>lombok</artifactId>
                        </exclude>
                    </excludes>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

3、启动项目

得力于 SpringBoot 的强大特性,什么都不用配置就可以启动项目,访问 http://localhost:8080,会跳转到默认的登录页面 /login

在这里插入图片描述

4、创建并启动前端项目

# 首先 cd 到存放项目的目录下,clone 项目到 vue-admin-example 目录
git clone https://github.com/PanJiaChen/vue-admin-template vue-admin-example

# 进入项目目录
cd vue-admin-example

# 安装依赖,使用淘宝镜像源加速
npm install --registry=https://registry.npm.taobao.org

# 本地开发 启动项目
npm run dev

在这里插入图片描述

总结

这篇文章我们只是创建好了前后端项目,在接下来的 SpringSecurity - 实战 RBAC(二) 文章中,我们会打通前后端项目,并且实现简单的登录功能。

代码已上传至 Gitee 中:

  • 后端https://gitee.com/hoticket/boot-admin-example
  • 前端https://gitee.com/hoticket/vue-admin-example.git
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值