source: TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/__init__.py @ 6673

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg-security/TI12-security/trunk/NDGSecurity/python/ndg_security_common/ndg/security/common/authz/xacml/__init__.py@6673
Revision 6673, 1.9 KB checked in by pjkersha, 11 years ago (diff)

Started pruning trunk of old security code. None of this code is used by the current system but it remains in the code base and is still unit tested:

  • NDG Attribute Certificate (replaced by SAML assertions)
  • SOAP/WSDL interfaces (replaced by SAML over SOAP)
  • Attribute Authority get NDG Attribute Certificate interface (replaced with SAML AttributeQuery/Response)
  • Session Manager (separate web service not needed for session management, new system uses Beaker to achieve much the same thing)
  • NDG Credential Wallet (SAML replacement)
  • WS-Security (replaced by SSL with client Authentication). WS-Security code is now in a separate WSSecurity branch to be released as a separate egg.
  • ndg.security.common.XMLSec (no digital signature needed for SAML currently but may need to be revived later. This code uses PyXML which breaks with Python >= 2.5.5. If revived it should be implemented with 4Suite-XML or ElementTree or lxml
Line 
1class PolicyComponent(object):
2    """Base class for Policy and Policy subelements"""
3    XACML_2_0_XMLNS = "urn:oasis:names:tc:xacml:2.0:policy:schema:os"
4
5    __slots__ = ('__xmlns', '__reader', '__writer')
6
7    ELEMENT_LOCAL_NAME = None
8   
9    def __init__(self):
10        self.__xmlns = PolicyComponent.XACML_2_0_XMLNS
11        self.__reader = None
12        self.__writer = None
13       
14    def _getXmlns(self):
15        return self.__xmlns
16
17    def _setXmlns(self, value):
18        if not isinstance(value, basestring):
19            raise TypeError('Expecting string type for "xmlns" '
20                            'attribute; got %r' % type(value))
21        self.__xmlns = value
22
23    xmlns = property(_getXmlns, _setXmlns, 
24                     doc="XML Namespace for policy the document")
25   
26    @property
27    def isValidXmlns(self):
28        return self.xmlns in PolicyComponent.XMLNS
29
30    def read(self, obj):
31        """Read using callable assinged to reader property"""
32        if self.__reader is None:
33            raise AttributeError('No reader set for %r' % self.__class__)
34       
35        self.__reader(self, obj)
36
37    @classmethod
38    def Read(cls, obj):
39        """Construct a new Policy""" 
40        xacmlObj = cls()
41        xacmlObj.read(obj)
42        return xacmlObj
43   
44    def write(self, obj):
45        """Read using callable assinged to reader property"""
46        if self.__writer is None:
47            raise AttributeError('No writer set for %r' % self.__class__)
48       
49        self.__writer(self, obj)
50       
51           
52class RequestPropertyBase(PolicyComponent):
53    """Base type for Subject, Resource, Action and Environment types"""
54    MATCH_TYPE = None
55   
56    __slots__ = ('__matches', )
57   
58    def __init__(self):
59        # Derived types can specify the type for matches via the MATCH_TYPE
60        # class variable
61        self.__matches = TypedList(self.__class__.MATCH_TYPE)
62       
63    @property
64    def matches(self):
65        return self.__matches
Note: See TracBrowser for help on using the repository browser.