source: TI12-security/trunk/python/Tests/xacml/test_xacml.py @ 5115

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/python/Tests/xacml/test_xacml.py@5115
Revision 5115, 2.0 KB checked in by pjkersha, 11 years ago (diff)

Completed functionality for policy target creation

Line 
1from ndg.security.common.authz.xacml import AttributeDesignator, TargetMatch, \
2    Target, MatchFunction, EqualFunction
3
4
5def createPolicyTarget():
6    # OpenID designator - string equal match
7    subjectDesignatorType = "http://www.w3.org/2001/XMLSchema#anyURI"
8    subjectDesignatorId = "urn:oasis:names:tc:xacml:1.0:subject:subject-id"
9    subjectMatchId = "urn:oasis:names:tc:xacml:1.0:function:string-equal";
10   
11    subjectDesignator = AttributeDesignator(AttributeDesignator.SUBJECT_TARGET,
12                                            subjectDesignatorType,
13                                            subjectDesignatorId)
14 
15    subjectFunction = EqualFunction(subjectMatchId)
16    subjectValue = 'http://localhost:7443/openid/john.smith'
17   
18    subjectMatch = TargetMatch(TargetMatch.SUBJECT,
19                               subjectFunction,
20                               subjectDesignator,
21                               subjectValue)
22    subject = [subjectMatch]
23   
24    # Regex match to URI
25    resourceDesignatorType ="http://www.w3.org/2001/XMLSchema#anyURI"
26    resourceDesignatorId ="urn:oasis:names:tc:xacml:1.0:resource:resource-id"
27
28    resourceMatchId="urn:oasis:names:tc:xacml:1.0:function:regexp-string-match"
29
30    resourceDesignator=AttributeDesignator(AttributeDesignator.RESOURCE_TARGET,
31                                           resourceDesignatorType,
32                                           resourceDesignatorId)
33
34    resourceValue = "http://localhost:7080/secured"
35
36    resourceFunction = MatchFunction(resourceMatchId);
37
38    resourceMatch = TargetMatch(TargetMatch.RESOURCE,
39                                resourceFunction,
40                                resourceDesignator,
41                                resourceValue)
42    resource = [resourceMatch]
43
44    subjects = [subject]
45    resources = [resource]
46
47    # No action type attributes have been specified in the target
48    return Target(subjects, resources)
49
50if __name__ == "__main__":
51    target = createPolicyTarget()
Note: See TracBrowser for help on using the repository browser.