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

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

New Policy Information Point class ndg.security.common.authz.pip.esg.PIP for ESG Authorisation Service.

Line 
1"""NDG Security authorisation package - contains code for Gatekeeper (PEP)
2and authorisation interfaces (PDP)
3
4NERC DataGrid Project
5"""
6__author__ = "P J Kershaw"
7__date__ = "04/04/08"
8__copyright__ = "(C) 2009 Science and Technology Facilities Council"
9__contact__ = "Philip.Kershaw@stfc.ac.uk"
10__license__ = "BSD - see LICENSE file in top-level directory"
11__contact__ = "Philip.Kershaw@stfc.ac.uk"
12__revision__ = "$Id: __init__.py 3755 2008-04-04 09:11:44Z pjkersha $"
13 
14       
15class _AttrDict(dict):
16    """Utility class for holding a constrained list of attributes governed
17    by a namespace list"""
18    namespaces = ()
19    def __init__(self, **attributes):
20        invalidAttributes = [attr for attr in attributes
21                             if attr not in self.__class__.namespaces]
22        if len(invalidAttributes) > 0:
23            raise TypeError("The following attribute namespace(s) are not "
24                            "recognised: %s" % invalidAttributes)
25           
26        self.update(attributes)
27
28    def __setitem__(self, key, val):
29        if key not in self.__class__.namespaces:
30            raise KeyError('Namespace "%s" not recognised.  Valid namespaces '
31                           'are: %s' % self.__class__.namespaces)
32           
33        dict.__setitem__(self, key, val)
34
35
36    def update(self, d, **kw):       
37        for dictArg in (d, kw):
38            for k in dictArg:
39                if k not in self.__class__.namespaces:
40                    raise KeyError('Namespace "%s" not recognised.  Valid '
41                                   'namespaces are: %s' % 
42                                   self.__class__.namespaces)
43       
44        dict.update(self, d, **kw)
45 
46   
47class SubjectRetrievalError(Exception):
48    """Generic exception class for errors related to information about the
49    subject"""       
50       
51       
52class SubjectBase(object):
53    '''Base class Subject designator'''
54    namespaces = ("urn:ndg:security:authz:1.0:attr:subject:roles", )
55    (ROLES_NS,) = namespaces
Note: See TracBrowser for help on using the repository browser.