指尖上的记忆指尖上的记忆
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub
首页
  • 基础
  • Laravel框架
  • Symfony框架
  • 基础
  • Gin框架
  • 基础
  • Spring框架
  • 命令
  • Nginx
  • Ai
  • Deploy
  • Docker
  • K8s
  • Micro
  • RabbitMQ
  • Mysql
  • PostgreSsql
  • Redis
  • MongoDb
  • Html
  • Js
  • 前端
  • 后端
  • Git
  • 知识扫盲
  • Golang
🌟 gitHub

symfony之user-role权限管理原理:

symfony的用户角色权限管理和java的差不多,都是通过 注释路由 来控制的,我还是觉得像 laravel下的 RBAC 权限控制系统比较好,更全面
通过 注释路由 来控制, 感觉太简单粗暴,适合简单的权限分配。

下面说一下这个验证过程:
symfony的默认权限验证 authenticate 调用的是 vendor/symfony/security-http/Firewall/AccessListener.php  中的 authenticate 方法
其中:
if (!$this->accessDecisionManager->decide($token, $attributes, $request, true)) {
           throw $this->createAccessDeniedException($request, $attributes);
       }
       
decide 调用的是  vendor/symfony/security-core/Authorization/AccessDecisionManager.php 中的 decide 方法

其中:
return $this->strategy->decide(
           $this->collectResults($token, $attributes, $object)
       );

collectResults 中的 $voter->vote($token, $object, $attributes); 调用的是  vendor/symfony/security-core/Authorization/Voter/RoleVoter.php 中的 vote 方法, 这个 vote 方法的逻辑很简单就是对比 $token里的
用户角色信息 和 当前路由需要的权限信息,用了两个 foreach 实现,如果有相等的,那么就可以验证通过.