Changeset 6719
- Timestamp:
- 11/03/10 09:29:21 (11 years ago)
- Location:
- TI12-security/trunk/NDGSecurity/python
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/NDGSecurity/python/ndg_security_server/ndg/security/server/attributeauthority.py
r6686 r6719 59 59 60 60 class AttributeAuthority(object): 61 """NDG Attribute Authority - service for allocation of user authorization62 tokens - attribute certificates.61 """NDG Attribute Authority - rewritten with a SAML 2.0 Attribute Query 62 interface for Earth System Grid 63 63 64 64 @type propertyDefaults: dict 65 65 @cvar propertyDefaults: valid configuration property keywords 66 66 67 @type attributeInterfacePropertyDefaults: dict68 @cvar attributeInterfacePropertyDefaults: valid configuration property67 @type ATTRIBUTE_INTERFACE_PROPERTY_DEFAULTS: dict 68 @cvar ATTRIBUTE_INTERFACE_PROPERTY_DEFAULTS: valid configuration property 69 69 keywords for the Attribute Interface plugin 70 70 … … 77 77 under DEFAULT_CONFIG_DIRNAME 78 78 79 @type ATTRIBUTE_INTERFACE_ KEYNAME: basestring80 @param ATTRIBUTE_INTERFACE_ KEYNAME: attribute interface parameters key79 @type ATTRIBUTE_INTERFACE_OPTPREFIX: basestring 80 @param ATTRIBUTE_INTERFACE_OPTPREFIX: attribute interface parameters key 81 81 name - see initAttributeInterface for details 82 82 """ 83 83 84 # Code designed from NERC Data Grid Enterprise and Information Viewpoint85 # documents.86 #87 # Also, draws from Neil Bennett's ACServer class used in the Java88 # implementation of NDG Security89 90 84 DEFAULT_CONFIG_DIRNAME = "conf" 91 85 DEFAULT_PROPERTY_FILENAME = "attributeAuthority.cfg" 92 ATTRIBUTE_INTERFACE_KEYNAME = 'attributeInterface' 86 87 # Config file special parameters 88 HERE_OPTNAME = 'here' 89 PREFIX_OPTNAME = 'prefix' 90 91 # Config file option names 92 ISSUER_NAME_OPTNAME = 'issuerName' 93 ASSERTION_LIFETIME_OPTNAME = 'assertionLifetime' 94 DN_SEPARATOR_OPTNAME = 'dnSeparator' 95 96 ATTRIBUTE_INTERFACE_OPTPREFIX = 'attributeInterface' 97 ATTRIBUTE_INTERFACE_MOD_FILEPATH_OPTNAME = 'modFilePath' 98 ATTRIBUTE_INTERFACE_CLASSNAME_OPTNAME = 'className' 99 93 100 CONFIG_LIST_SEP_PAT = re.compile(',\s*') 94 101 95 attributeInterfacePropertyDefaults = { 96 'modFilePath': '', 97 'className': '' 102 103 ATTRIBUTE_INTERFACE_PROPERTY_DEFAULTS = { 104 ATTRIBUTE_INTERFACE_MOD_FILEPATH_OPTNAME: '', 105 ATTRIBUTE_INTERFACE_CLASSNAME_OPTNAME: '' 98 106 } 99 107 … … 102 110 # in the config 103 111 propertyDefaults = { 104 'issuerName':'',105 'assertionLifetime':-1,106 'dnSeparator':'/',107 ATTRIBUTE_INTERFACE_ KEYNAME: attributeInterfacePropertyDefaults112 ISSUER_NAME_OPTNAME: '', 113 ASSERTION_LIFETIME_OPTNAME: -1, 114 DN_SEPARATOR_OPTNAME: '/', 115 ATTRIBUTE_INTERFACE_OPTPREFIX: ATTRIBUTE_INTERFACE_PROPERTY_DEFAULTS 108 116 } 109 117 118 __slots__ = ( 119 '__issuerName', 120 '__assertionLifetime', 121 '__dnSeparator', 122 '__propFilePath', 123 '__propFileSection', 124 '__propPrefix', 125 '__attributeInterfaceCfg' 126 ) 127 110 128 def __init__(self): 111 129 """Create new Attribute Authority instance""" … … 113 131 114 132 # Initial config file property based attributes 115 for name, val in AttributeAuthority.propertyDefaults.items(): 116 setattr(self, '_AttributeAuthority__%s' % name, val) 133 self.__issuerName = None 134 self.__assertionLifetime = None 135 self.__dnSeparator = None 117 136 118 137 self.__propFilePath = None … … 285 304 286 305 @classmethod 287 def fromPropertyFile(cls, propFilePath=None, propFileSection='DEFAULT',288 pr opPrefix='attributeauthority.'):306 def fromPropertyFile(cls, propFilePath=None, section='DEFAULT', 307 prefix='attributeauthority.'): 289 308 """Create new NDG Attribute Authority instance from the property file 290 309 settings … … 294 313 configuration parameters. It defaults to $NDGSEC_AA_PROPFILEPATH or 295 314 if not set, $NDGSEC_DIR/conf/attributeAuthority.cfg 296 @type propFileSection: basestring297 @param propFileSection: section of properties file to read from.315 @type section: basestring 316 @param section: section of properties file to read from. 298 317 properties files 318 @type prefix: basestring 319 @param prefix: set a prefix for filtering attribute authority 320 property names - useful where properties are being parsed from a file 321 section containing parameter names for more than one application 322 """ 323 324 attributeAuthority = AttributeAuthority() 325 if section: 326 attributeAuthority.propFileSection = section 327 328 if prefix: 329 attributeAuthority.propPrefix = prefix 330 331 # If path is None it will default to setting derived from environment 332 # variable - see setPropFilePath() 333 attributeAuthority.propFilePath = propFilePath 334 335 attributeAuthority.readProperties() 336 attributeAuthority.initialise() 337 338 return attributeAuthority 339 340 @classmethod 341 def fromProperties(cls, prefix='attributeauthority.', **prop): 342 """Create new NDG Attribute Authority instance from input property 343 keywords 344 299 345 @type propPrefix: basestring 300 346 @param propPrefix: set a prefix for filtering attribute authority 301 347 property names - useful where properties are being parsed from a file 302 348 section containing parameter names for more than one application 303 @type bReadMapConfig: boolean 304 @param bReadMapConfig: by default the Map Configuration file is 305 read. Set this flag to False to override. 306 """ 307 349 """ 308 350 attributeAuthority = AttributeAuthority() 309 if propFileSection: 310 attributeAuthority.propFileSection = propFileSection 311 312 if propPrefix: 313 attributeAuthority.propPrefix = propPrefix 314 315 attributeAuthority.propFilePath = propFilePath 316 attributeAuthority.readProperties() 317 attributeAuthority.initialise() 318 319 return attributeAuthority 320 321 @classmethod 322 def fromProperties(cls, propPrefix='attributeauthority.', **prop): 323 """Create new NDG Attribute Authority instance from input property 324 keywords 325 326 @type propPrefix: basestring 327 @param propPrefix: set a prefix for filtering attribute authority 328 property names - useful where properties are being parsed from a file 329 section containing parameter names for more than one application 330 """ 331 attributeAuthority = AttributeAuthority() 332 if propPrefix: 333 attributeAuthority.propPrefix = propPrefix 351 if prefix: 352 attributeAuthority.propPrefix = prefix 334 353 335 354 attributeAuthority.setProperties(**prop) … … 358 377 # '+ 1' allows for the dot separator 359 378 lenAttributeInterfacePrefix = len( 360 AttributeAuthority.ATTRIBUTE_INTERFACE_KEYNAME) + 1379 AttributeAuthority.ATTRIBUTE_INTERFACE_OPTPREFIX) + 1 361 380 362 381 for name, val in prop.items(): … … 364 383 name = name[lenPropPrefix:] 365 384 366 if name.startswith(AttributeAuthority.ATTRIBUTE_INTERFACE_KEYNAME): 385 if name.startswith( 386 AttributeAuthority.ATTRIBUTE_INTERFACE_OPTPREFIX): 367 387 name = name[lenAttributeInterfacePrefix:] 368 388 self.attributeInterfaceCfg[name] = val … … 392 412 self.propFilePath) 393 413 394 defaultItems = {'here': os.path.dirname(self.propFilePath)} 414 defaultItems = { 415 AttributeAuthority.HERE_OPTNAME: os.path.dirname(self.propFilePath) 416 } 395 417 396 418 cfg = CaseSensitiveConfigParser(defaults=defaultItems) 397 419 cfg.read(self.propFilePath) 398 420 421 if cfg.has_option(self.propFileSection, 422 AttributeAuthority.PREFIX_OPTNAME): 423 self.propPrefix = cfg.get(self.propFileSection, 424 AttributeAuthority.PREFIX_OPTNAME) 425 399 426 cfgItems = dict([(name, val) 400 427 for name, val in cfg.items(self.propFileSection) 401 if name != 'here']) 428 if (name != AttributeAuthority.HERE_OPTNAME and 429 name != AttributeAuthority.PREFIX_OPTNAME)]) 402 430 self.setProperties(**cfgItems) 403 431 … … 416 444 modFilePath = classProperties.pop('modFilePath', None) 417 445 418 self.__attributeInterface = instantiateClass(modName, 419 className, 446 self.__attributeInterface = instantiateClass(className, 420 447 moduleFilePath=modFilePath, 421 448 objectType=AttributeInterface, -
TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/unit/attributeauthority/test_attributeauthority.cfg
r6686 r6719 8 8 9 9 [DEFAULT] 10 prefix= 'attribute-authority.'10 prefix=attribute-authority. 11 11 attribute-authority.assertionLifetime = 3600 12 12 attribute-authority.issuerName = /O=My Organisation/OU=Centre/CN=Attribute Authority -
TI12-security/trunk/NDGSecurity/python/ndg_security_test/ndg/security/test/unit/attributeauthority/test_attributeauthority.py
r6686 r6719 29 29 CaseSensitiveConfigParser) 30 30 from ndg.security.server.attributeauthority import (AttributeAuthority, 31 SQLAlchemyAttributeInterface, InvalidAttributeFormat )31 SQLAlchemyAttributeInterface, InvalidAttributeFormat, AttributeInterface) 32 32 33 33 from ndg.saml.saml2.core import (Response, Attribute, SAMLVersion, Subject, … … 54 54 self.assert_(aa.issuerName == cls.ISSUER_NAME) 55 55 56 def test02FromProperti s(self):56 def test02FromProperties(self): 57 57 58 58 # Casts from string to float 59 59 assertionLifetime = "86400" 60 60 issuerName = 'My issuer' 61 attributeInterfaceClassName = ('ndg.security.server.attributeauthority.' 62 'AttributeInterface') 63 61 64 aa = AttributeAuthority.fromProperties(issuerName=issuerName, 62 assertionLifetime=assertionLifetime) 65 assertionLifetime=assertionLifetime, 66 attributeInterface_className=attributeInterfaceClassName) 67 63 68 self.assert_(aa) 64 69 self.assert_(aa.assertionLifetime == float(assertionLifetime)) 65 70 self.assert_(aa.issuerName == issuerName) 71 self.assert_(isinstance(aa.attributeInterface, AttributeInterface)) 66 72 67 73
Note: See TracChangeset
for help on using the changeset viewer.