Package ndg :: Package xacml :: Package finder :: Module policyfinderbase
[hide private]

Source Code for Module ndg.xacml.finder.policyfinderbase

 1  """NDG Security finder base class 
 2   
 3  NERC DataGrid 
 4  """ 
 5  __author__ = "R B Wilkinson" 
 6  __date__ = "01/11/11" 
 7  __copyright__ = "(C) 2011 Science and Technology Facilities Council" 
 8  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
 9  __license__ = "BSD - see LICENSE file in top-level directory" 
10  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
11  __revision__ = "$Id$" 
12   
13  from abc import ABCMeta, abstractmethod 
14  import logging 
15  log = logging.getLogger(__name__) 
16   
17  from ndg.xacml.parsers import XMLParseError 
18 19 -class PolicyFinderBase(object):
20 """ 21 Base class for policy finders. The specific finder strategy is implemented 22 in the findPolicy and findPolicySet methods. 23 """ 24 __metaclass__ = ABCMeta 25
26 - def __init__(self):
27 self.policyMap = {} 28 self.policySetMap = {}
29 30 @abstractmethod
31 - def findPolicy(self, policyIdReference, common):
32 """ 33 Retrieves a policy for a specified policy ID. 34 @param policyIdReference: policy ID reference 35 @type policyIdReference: str 36 @param common: parsing common data 37 @type common: from ndg.xacml.parsers.common.Common 38 @return: policy 39 @rtype: None (subclasses should return ndg.xacml.core.policy.Policy) 40 """ 41 return None
42 43 @abstractmethod
44 - def findPolicySet(self, policySetIdReference, common):
45 """ 46 Retrieves a policy set for a specified policy set ID. 47 @param policySetIdReference: policy set ID reference 48 @type policySetIdReference: str 49 @param common: parsing common data 50 @type common: from ndg.xacml.parsers.common.Common 51 @return: policy set 52 @rtype: None (subclasses should return ndg.xacml.core.policy.PolicySet) 53 """ 54 return None
55
56 - def setReader(self, reader):
57 """ 58 Sets the reader to be used when parsing referenced policies. 59 @param reader: reader 60 @type reader: ndg.xacml.parsers.AbstractReader derived type 61 """ 62 self.reader = reader
63
64 - def addPolicyReference(self, policy):
65 """ 66 @param policy: policy 67 @type policy: ndg.xacml.core.policy.Policy 68 @raise XMLParseError: if the policy's ID is a duplicate of one already 69 found 70 """ 71 if policy.policyId in self.policyMap: 72 raise XMLParseError("Duplicate Policy ID %r found" % policy.policyId) 73 self.policyMap[policy.policyId] = policy
74
75 - def addPolicySetReference(self, policySet):
76 """ 77 @param policySet: policy set 78 @type policySet: ndg.xacml.core.policy.PolicySet 79 @raise XMLParseError: if the policy's ID is a duplicate of one already 80 found 81 """ 82 if policySet.policySetId in self.policySetMap: 83 raise XMLParseError("Duplicate PolicySet ID %r found" % policySet.policySetId) 84 self.policySetMap[policySet.policySetId] = policySet
85