当前位置: 首页>>代码示例>>Python>>正文


Python PDP.evaluate方法代码示例

本文整理汇总了Python中ndg.xacml.core.context.pdp.PDP.evaluate方法的典型用法代码示例。如果您正苦于以下问题:Python PDP.evaluate方法的具体用法?Python PDP.evaluate怎么用?Python PDP.evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ndg.xacml.core.context.pdp.PDP的用法示例。


在下文中一共展示了PDP.evaluate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: XacmlDynamicPolicyTestCase

# 需要导入模块: from ndg.xacml.core.context.pdp import PDP [as 别名]
# 或者: from ndg.xacml.core.context.pdp.PDP import evaluate [as 别名]

#.........这里部分代码省略.........
                                    "http://www.w3.org/2001/XMLSchema#string")()
        subject_match1.attributeValue.value = 'staff'
        subject_match1.attributeDesignator = SubjectAttributeDesignator()
        subject_match1.attributeDesignator.attributeId = ROLE_ATTRIBUTE_ID
        subject_match1.attributeDesignator.dataType = "http://www.w3.org/2001/XMLSchema#string"

        subject1 = Subject()
        subject1.matches.append(subject_match1)

        singlerole_rule.target.subjects.append(subject1)
        
        self.policy.rules.append(singlerole_rule)

    @staticmethod
    def _create_request_ctx(resourceId, 
                          includeSubject=True,
                          subjectId=SUBJECT_ID,
                          subjectRoles=None,
                          roleAttributeId=ROLE_ATTRIBUTE_ID,
                          action='read',
                          resourceContent=None):
        """Create an example XACML Request Context for tests"""
        if subjectRoles is None:
            subjectRoles = ('staff',)
            
        request = Request()
        
        if includeSubject:
            subject = CtxSubject()
            openidSubjectAttribute = Attribute()
            
            openidSubjectAttribute.attributeId = "urn:esg:openid"
            openidSubjectAttribute.dataType = AnyUriAttributeValue.IDENTIFIER
            
            openidSubjectAttribute.attributeValues.append(
                                                        AnyUriAttributeValue())
            openidSubjectAttribute.attributeValues[-1].value = subjectId
                                        
            
            subject.attributes.append(openidSubjectAttribute)
    
            for role in subjectRoles:
                roleAttribute = Attribute()
                
                roleAttribute.attributeId = roleAttributeId
                roleAttribute.dataType = StringAttributeValue.IDENTIFIER
                
                roleAttribute.attributeValues.append(StringAttributeValue())
                roleAttribute.attributeValues[-1].value = role 
            
                subject.attributes.append(roleAttribute)
                                      
            request.subjects.append(subject)
        
        resource = ResourceCtx()
        resourceAttribute = Attribute()
        resource.attributes.append(resourceAttribute)
        
        resourceAttribute.attributeId = Identifiers.Resource.RESOURCE_ID
                            
        resourceAttribute.dataType = AnyUriAttributeValue.IDENTIFIER
        resourceAttribute.attributeValues.append(AnyUriAttributeValue())
        resourceAttribute.attributeValues[-1].value = resourceId

        resource.resourceContent = resourceContent

        request.resources.append(resource)
        
        request.action = Action()
        actionAttribute = Attribute()
        request.action.attributes.append(actionAttribute)
        
        actionAttribute.attributeId = Identifiers.Action.ACTION_ID
        actionAttribute.dataType = StringAttributeValue.IDENTIFIER
        actionAttribute.attributeValues.append(StringAttributeValue())
        actionAttribute.attributeValues[-1].value = action

        request.environment = Environment()
        
        return request
    
    def _create_pdp(self):
        self._create_policy()
        self.pdp = PDP(policy=self.policy)
        
    def test01_create_policy(self):
        self._create_policy()
        
    def test02_create_pdp(self):
        self._create_pdp()
        
    def test03_test_rule(self):
        self._create_pdp()
        request = self._create_request_ctx('http://localhost/dataset1/my.nc', 
                                           subjectId='http://me.openid.ac.uk', 
                                           subjectRoles=('staff',))
        response = self.pdp.evaluate(request)
        for result in response.results:
            self.failIf(result.decision != Decision.PERMIT, 
                        "Expecting Permit decision") 
开发者ID:LiangLinCn,项目名称:ndg_xacml,代码行数:104,代码来源:test_pdp.py

示例2: attributeValueFactory

# 需要导入模块: from ndg.xacml.core.context.pdp import PDP [as 别名]
# 或者: from ndg.xacml.core.context.pdp.PDP import evaluate [as 别名]
role = attributeValueFactory("http://www.w3.org/2001/XMLSchema#string")
arole = role("administrator")

# Add the role-attribute to the request-subject
#   id:     urn:oasis:names:tc:xacml:2.0:example:attribute:role
attr = Attribute()
attr.attributeId = "urn:oasis:names:tc:xacml:2.0:example:attribute:role"
attr.dataType = role.IDENTIFIER  # = http://www.w3.org/2001/XMLSchema#string
attr.attributeValues.append(arole)

subject = Subject()
subject.attributes.append(attr)
request.subjects.append(subject)

# See what we've received as result
res = pdp.evaluate(request)
for result in res.results:
    print result.decision


"""

How to add actions (I did not test it yet):


somevalue = attributeValueFactory("http://www.w3.org/2001/XMLSchema#string")
avalue = somevalue("https://www.gonicus.de/webdav")
bvalue = somevalue("read")

# Add a resource attribute
resourceAttribute = Attribute()
开发者ID:gonicus,项目名称:clacks,代码行数:33,代码来源:play.py


注:本文中的ndg.xacml.core.context.pdp.PDP.evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。