简体   繁体   English

Sylius管理控制器如何受限于管理员用户

[英]How are Sylius Admin Controllers Restricted to Admin Users

When working in a traditional (or more accurately, some traditional) PHP MVC systems, if an application has an "admin" area that requires users to login to the application, a programmer will either use a controller class that inherits from some base admin controller, or uses some admin trait. 在传统的(或更准确的, 某些传统的)PHP MVC系统中工作时,如果应用程序具有需要用户登录到应用程序的“管理”区域,程序员将使用从某些基本管理控制器继承的控制器类,或使用一些管理特征。 The routing code in these systems knows to use certain methods on the admin controller/trait to check if a user is authorized. 这些系统中的路由代码知道在管理控制器/特征上使用某些方法来检查用户是否被授权。

Sylius controllers, however, are stand-alone classes with no parent classes . 但是,Sylius控制器是没有父类的独立类

<?php
//...
final class DashboardController
{
    //...
}

and don't appear to contain any code that does a "is the user logged in" check. 并且似乎不包含任何“用户登录”检查的代码。

How does a sylius programmer create a route to an controller that requires a user to be logged in? sylius程序员如何创建到需要用户登录的控制器的路由?

What system, under the hood, enforces a sylius user being logged in or not? 引擎盖下的哪个系统强制执行sylius用户登录?

Sylius is using Symfony as a PHP Framework and it relies on the Security component to restrict access to certain areas of the application that are not intended to be public (eg. admin panel). Sylius使用Symfony作为PHP框架,它依赖于安全组件来限制对应用程序的某些不公开的区域(例如管理面板)的访问。

Such configuration can be seen here: https://github.com/Sylius/Sylius/blob/master/config/packages/security.yaml (see lines #16 and #101). 这样的配置可以在这里看到: https//github.com/Sylius/Sylius/blob/master/config/packages/security.yaml (参见第16行和第101行)。

Resources (basically, every entity in Sylius - product, users, attributes, taxons) have a more advanced permissions that can be leveraged through plugins like https://github.com/Sylius/RbacPlugin or https://bitbag.shop/products/sylius-access-control-layer . 资源(基本上,Sylius中的每个实体 - 产品,用户,属性,分类)都有更高级的权限,可以通过https://github.com/Sylius/RbacPluginhttps://bitbag.shop/products等插件来利用/ sylius-access-control-layer

Example: https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/AdminBundle/Resources/config/routing/admin_user.yml#L10 示例: https//github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/AdminBundle/Resources/config/routing/admin_user.yml#L10

You can read more about how Symfony Security component works here: https://symfony.com/doc/current/components/security.html 您可以在此处阅读有关Symfony Security组件如何工作的更多信息: https//symfony.com/doc/current/components/security.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM