mouf/security.rightsservice-splash

该包包含一组类,用于将 Splash MVC 框架(>=v4)与 RightsService 组件绑定。它具有以下特点:一个 @RequiresRight 注解,仅允许登录用户访问。

v10.0.2 2022-12-06 15:30 UTC

This package is auto-updated.

Last update: 2024-09-06 18:55:40 UTC


README

该包是 Mouf PHP 框架的一部分,包含 @Right 注解,该注解将 Splash MVC 框架RightsService 集成。

该包提供了一种有用的过滤器

@Right 注解

此过滤器可用于任何操作。如果使用此注解,且用户不具备指定的权限,则用户将被拒绝访问。

/**
 * A sample default action that requires to have the "ACCESS_ADMIN_RIGHT" right.
 *
 * @URL /admin
 * @Right("ACCESS_ADMIN_RIGHT")
 */
public function index() { ... }

@Right 注解需要一个名为 ForbiddenMiddleware::classForbiddenMiddleware 实例存在。如果您的 ForbiddenMiddleware 实例不是命名为 ForbiddenMiddleware::class(或者您想使用多个 ForbiddenMiddleware 实例,可以在注解的参数中指定要使用的中间件实例)

/**
 * A sample default action that requires to have the "ACCESS_ADMIN_RIGHT" right.
 *
 * @URL /admin
 * @Right(name="ACCESS_ADMIN_RIGHT",instance="myForbiddenMiddleware")
 */
public function index() { ... }

组合权限: @AndRight@OrRight 注解

有时,您可能需要检查用户是否具有 2 个权限(),或者两个权限中的任何一个()。

为此,您不需要将字符串传递给 @Right 注解,而是可以传递一个 @AndRight 或 @OrRight 注解。

例如,要检查用户是否同时具有 CAN_DO_THIS 和 CAN_DO_THAT 权限,您应该使用

/**
 * An action that requires to have both the "CAN_DO_THIS" and "CAN_DO_THAT" right.
 *
 * @URL /admin
 * @Right(@AndRight({@Right("CAN_DO_THIS"), @Right("CAN_DO_THAT")}))
 */
public function index() { ... }

如果,您想检查用户是否具有多个权限中的任何一个,您将使用 @OrRight

/**
 * An action that requires to have either the "CAN_DO_THIS" or "CAN_DO_THAT" right.
 *
 * @URL /admin
 * @Right(@OrRight({@Right("CAN_DO_THIS"), @Right("CAN_DO_THAT")}))
 */
public function index() { ... }

您可以将 @AndRight 和 @OrRight 注解结合起来,只要最顶层的注解是 @Right。此外,如果您需要组合复杂的权限,您可能需要开始质疑您的权限系统并进行重构。@AndRight 和 @OrRight 应该很少使用。