enygma / xacmlphp
OASIS/XACML 政策/授权库
1.1
2015-11-28 19:06 UTC
Requires
- php: >=5.3.1
Requires (Dev)
- phpunit/phpunit: 4.6.*
This package is auto-updated.
Last update: 2024-09-15 10:18:31 UTC
README
Xacml-php 库是对 OASIS/XACML 标准的基于策略的授权实现的库。它还在开发中,但基本概念已经存在。
OASIS 标准
OASIS/XACML 标准 是一个基于 XML 的结构,用于评估策略上的属性与主题上的属性,以查看是否存在匹配(基于操作规则和组合算法)。
术语
- 策略集:一组策略对象
- 策略:定义用于授权评估的策略。策略包含一组规则,这些规则将被评估,并根据策略的算法组合结果以确定整体策略的通过/失败状态
- 规则:由一组在目标内部使用的匹配项组成,用于评估授权
- 匹配:一个定义要查看的属性(设计ator)、要检查的值(值)以及要执行的操作(如“StringEqual”)以确定允许/拒绝结果的对象
- 属性:主题、资源、操作或环境上的属性
- 算法:用于组合对象(如策略或规则)评估结果的评估方法。在 OASIS 规范中,这些称为 函数。
- 效果:根据规范,这只能是 "允许" 或 "拒绝"
- 执行者:访问执行点,称为 OASIS 规范中的 PEP(策略执行点)
- 决策者:处理决策逻辑的对象,从策略追踪到匹配。在 OASIS 规范中称为 PDP(策略决策点)
- 资源:表示主题试图访问的 "某物" 的对象
示例用法
这是对 OASIS XACML 结构和流程的基本解释。它首先设置策略结构,使用规则和匹配,然后将它们分配给资源。然后,将主题和资源传递给执行者以检查是否允许访问。
<?php require_once 'vendor/autoload.php'; $enforcer = new \Xacmlphp\Enforcer(); $decider = new \Xacmlphp\Decider(); $enforcer->setDecider($decider); // Create some Matches $match1 = new \Xacmlphp\Match('StringEqual', 'property1', 'TestMatch1', 'test'); $match2 = new \Xacmlphp\Match('StringEqual', 'property1', 'TestMatch2', 'test1234'); // Create a Target container for our Matches $target = new \Xacmlphp\Target(); $target->addMatches(array($match1, $match2)); // Make a new Rule and add the Target to it $rule1 = new \Xacmlphp\Rule(); $rule1->setTarget($target) ->setId('TestRule') ->setEffect('Permit') ->setDescription( 'Test to see if there is an attribute on the subject' .'that exactly matches the word "test"' ) ->setAlgorithm(new \Xacmlphp\Algorithm\DenyOverrides()); // Make two new policies and add the Rule to it (with our Match) $policy1 = new \Xacmlphp\Policy(); $policy1->setAlgorithm('AllowOverrides')->setId('Policy1')->addRule($rule1); $policy2 = new \Xacmlphp\Policy(); $policy2->setAlgorithm('DenyOverrides')->setId('Policy2')->addRule($rule1); // Create the subject with its own Attribute $subject = new \Xacmlphp\Subject(); $subject->addAttribute( new \Xacmlphp\Attribute('property1', 'test') ); // Link the Policies to the Resource $resource = new \Xacmlphp\Resource(); $resource ->addPolicy($policy1) ->addPolicy($policy2); $environment = null; $action = null; $result = $enforcer->isAuthorized($subject, $resource); /** * The Subject does have a property that's equal to "test" on the "property1" * attribute, but the default Operation is to "fail closed". The other Match, * for "test1234" failed and DenyOverrides wins so the return is false. */ echo "\n\n".' END RESULT: '.var_export($result, true); echo "\n\n"; ?>