Ignore:
Timestamp:
27/10/10 16:05:18 (10 years ago)
Author:
pjkersha
Message:

ndg_xacml:

  • added support for custom AttributeValue? DataTypes? - this means that the ESGF GroupRole? attribute type can be added directly into XACML policies.
  • TODO: add support for adding custom functions so that a PDP can correctly apply rules based on custom types like the ESGF GroupRole?.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/ndg_xacml/ndg/xacml/parsers/etree/factory.py

    r7087 r7661  
    1515from ndg.xacml.parsers import AbstractReaderFactory 
    1616from ndg.xacml.utils.factory import importModuleObject 
    17  
    18 from ndg.xacml.core.policy import Policy 
    19 from ndg.xacml.core.target import Target 
    20 from ndg.xacml.core.rule import Rule 
    21  
    22 # Target child elements 
    23 from ndg.xacml.core.subject import Subject 
    24 from ndg.xacml.core.action import Action 
    25 from ndg.xacml.core.resource import Resource 
    26 from ndg.xacml.core.environment import Environment 
     17from ndg.xacml.utils import VettedDict 
     18from ndg.xacml.core import XacmlCoreBase 
     19from ndg.xacml.parsers.etree.reader import ETreeAbstractReader 
    2720 
    2821 
     22class ETreeReaderClassMap(VettedDict): 
     23    """Specialised dictionary to hold mappings of XACML classes to their 
     24    equivalent ElementTree reader classes 
     25    """ 
     26     
     27    def __init__(self): 
     28        """Force entries to derive from AttributeValue and IDs to 
     29        be string type 
     30        """         
     31        # Filters are defined as staticmethods but reference via self here to  
     32        # enable derived class to override them as standard methods without 
     33        # needing to redefine this __init__ method             
     34        VettedDict.__init__(self, self.keyFilter, self.valueFilter) 
     35         
     36    @staticmethod 
     37    def keyFilter(key): 
     38        """Enforce XACML base class type keys 
     39         
     40        @param key: URN for attribute 
     41        @type key: basestring 
     42        @return: boolean True indicating key is OK 
     43        @rtype: bool 
     44        @raise TypeError: incorrect input type 
     45        """ 
     46        if not issubclass(key, XacmlCoreBase): 
     47            raise TypeError('Expecting %r derived type for key; got %r' %  
     48                            (XacmlCoreBase, type(key)))  
     49        return True  
     50     
     51    @staticmethod 
     52    def valueFilter(value): 
     53        """Enforce ElementTree abstract reader derived types for values 
     54        @param value: attribute value 
     55        @type value: ndg.xacml.core.attributevalue.AttributeValue derived type 
     56        @return: boolean True indicating attribute value is correct type 
     57        @rtype: bool 
     58        @raise TypeError: incorrect input type 
     59        """ 
     60        if not issubclass(value, ETreeAbstractReader): 
     61            raise TypeError('Expecting %r derived type for value; got %r' %  
     62                            (ETreeAbstractReader, type(value)))  
     63        return True  
     64     
     65     
    2966class ReaderFactory(AbstractReaderFactory): 
    3067    """Parser factory for ElementTree based parsers for XACML types""" 
     68    READER_CLASS_MAP = ETreeReaderClassMap() 
     69     
     70    @classmethod 
     71    def addReader(cls, xacmlType, readerClass): 
     72        """Add custom classes and readers 
     73         
     74        @param xacmlType: XACML type to return a parser class for 
     75        @type xacmlType: type 
     76        @param readerClass: ElementTree based reader for the input XACML type.   
     77        @type readerClass: ndg.xacml.parsers.etree.reader.ETreeAbstractReader  
     78        derived type 
     79        """ 
     80        cls.READER_CLASS_MAP[xacmlType] = readerClass 
    3181     
    3282    @classmethod 
     
    3787        @type xacmlType: type 
    3888        @return: ElementTree based reader for the input XACML type.  The class 
    39         and module containing the class are infered from the XACML class name 
     89        and module containing the class are inferred from the XACML class name 
    4090        input e.g.  
    4191         
     
    4696        @raise ImportError: if no reader class found for input type 
    4797        """ 
    48         xacmlTypeName = xacmlType.__name__ 
    49         readerClassName = 'ndg.xacml.parsers.etree.%sreader.%sReader' % ( 
     98        if xacmlType in cls.READER_CLASS_MAP: 
     99            # Retrieve from mapping 
     100            return cls.READER_CLASS_MAP[xacmlType] 
     101        else: 
     102            # Infer from the package structure 
     103            xacmlTypeName = xacmlType.__name__ 
     104            readerClassName = 'ndg.xacml.parsers.etree.%sreader.%sReader' % ( 
    50105                                                        xacmlTypeName.lower(), 
    51106                                                        xacmlTypeName) 
    52         readerClass = importModuleObject(readerClassName) 
    53         return readerClass 
     107            readerClass = importModuleObject(readerClassName) 
     108            return readerClass 
    54109             
Note: See TracChangeset for help on using the changeset viewer.