# spring-security **Repository Path**: DblSun/spring-security ## Basic Information - **Project Name**: spring-security - **Description**: 基于spring-security双过滤器链路认证实现 - **Primary Language**: Java - **License**: MIT - **Default Branch**: master - **Homepage**: https://gitee.com/DblSun/spring-security - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-05-25 - **Last Updated**: 2025-06-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: Java, SpringBoot ## README # 基于 Spring Security 双过滤器链路的认证 ------ ## 引言 ​ 在企业级Web应用开发中,**安全性**始终是一个关键考量因素。Spring Security 作为 Spring 生态系统中的安全框架,提供了全面而灵活的安全防护机制。其核心配置组件 HttpSecurity 与 WebSecurityConfigurerAdapter(在 Spring Security 5.7之前)允许开发者以声明式方式定义安全策略,涵盖认证、授权、会话管理、CSRF防护等多个安全维度。本文将深入探讨Spring Security的Web安全配置机制,分析 HttpSecurity 的功能与用法,以及 HttpSecurity 的工作原理,帮助开发者构建安全、可靠的Web应用系统。通过掌握这些核心概念和配置方法,开发者可以根据业务需求精确调整安全策略,在保障系统安全的同时提供良好的用户体验。 ## 项目概述 ### 基于 SpringBoot 3.4.5,Spring Security 6.5+ 的安全认证体系,包含两种认证方式: - 用户名密码认证(/username/**) - 手机验证码认证(/phone/**) > [!IMPORTANT] > > 本项目不在使用已经过时的 WebSecurityConfigurerAdapter ,而是采用全新的 HttpSecurity 注册为 Bean 的方式 ### 基于 RBAC 的细粒度权限控制 ![image-20250525101125076](A:\java\project\securityTemplate\images\rbac.png) - 根据用户查询角色、根据角色查询权限 - 数据库配置在项目文件根目录下 ## 技术栈说明 - SpringBoot 3.4.5 - SpringSecurity 6.5+ - Mysql 8.0+ - Redis 8.0+ - Hutool 工具包 - Mybatis 3.0.4 ## 项目目录结构 src ├── main │ ├── java │ │ └── com │ │ └── security │ │ ├── SecurityTemplateApplication.java *项目启动类* │ │ ├── config │ │ │ └── security *security配置* │ │ │ └── authentication │ │ │ ├── common *通用认证处理器* │ │ │ ├── sms *短信验证码认证模块* │ │ │ └── username *用户名密码认证模块* │ │ ├── constant *常量类* │ │ ├── controller *界面层* │ │ ├── domain │ │ │ ├── bo *业务层对象* │ │ │ ├── vo *视图层对象* │ │ │ └── po *持久层对象* │ │ ├── exception *异常层* │ │ ├── mapper *DAO层* │ │ └── service *业务层* │ │ │ └── impl *业务实现* │ │ └── utils *工具类* │ └── resources/ # 资源目录(当前未展示具体文件,可能包含配置文件如 application.yaml) ![image-20250525105714011](C:\Users\18122\AppData\Roaming\Typora\typora-user-images\image-20250525105714011.png) ## 注意事项 项目启动后会报如下 warn ,不影响正常运行,可忽略。报错原因:本项目未实现 UserDetailsService 类所以 Security 框架默认实现了基于内存的认证。 - Using generated security password: xxxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - This generated password is for development use only. Your security configuration must be updated before running your application in production.