Changeset 5973
- Timestamp:
- 05/11/09 17:14:56 (11 years ago)
- Location:
- TI12-security/trunk/python
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI12-security/trunk/python/ndg_security_server/ndg/security/server/attributeauthority.py
r5971 r5973 1948 1948 SAML_VALID_REQUESTOR_DNS_OPTNAME = 'samlValidRequestorDNs' 1949 1949 SAML_ASSERTION_LIFETIME_OPTNAME = 'samlAssertionLifetime' 1950 SAML_ATTRIBUTE2SQLQUERY_MAP_OPTNAME = 'samlAttribute2SqlQueryMap' 1950 1951 1951 1952 __slots__ = ( … … 1957 1958 SAML_VALID_REQUESTOR_DNS_OPTNAME, 1958 1959 SAML_ASSERTION_LIFETIME_OPTNAME, 1959 'samlAttributeMap'1960 SAML_ATTRIBUTE2SQLQUERY_MAP_OPTNAME, 1960 1961 ) 1961 1962 __PRIVATE_ATTR_PREFIX = '_SQLAlchemyAttributeInterface__' … … 1977 1978 self.__samlValidRequestorDNs = None 1978 1979 self.__samlAssertionLifetime = None 1979 1980 self.__samlAttribute2SqlQueryMap = {} 1981 1980 1982 self.setProperties(**properties) 1983 1984 def __setattr__(self, name, value): 1985 """Provide a way to set the attribute map by dynamically handling 1986 attribute names containing the SAML attribute name as a suffix e.g. 1987 1988 attributeInterface.samlAttribute2SqlQueryMap_firstName = 'Philip' 1989 1990 will update __samlAttribute2SqlQueryMap with the 'firstName', 'Philip' 1991 key value pair. Similarly, 1992 1993 setattr('samlAttribute2SqlQueryMap.emailAddress', 'pjk@somewhere.ac.uk') 1994 1995 sets __samlAttribute2SqlQueryMap with the 'emailAddress', 1996 'pjk@somewhere.ac.uk' key value pair 1997 """ 1998 if (name != 'samlAttribute2SqlQueryMap' and 1999 name.startswith('samlAttribute2SqlQueryMap')): 2000 2001 suffix = name.replace('samlAttribute2SqlQueryMap','') 2002 if suffix[0] not in ('.', '_'): 2003 raise AttributeError('Expecting "." or "_" separator for ' 2004 'special "samlAttribute2SqlQueryMap*" ' 2005 'attribute setting') 2006 2007 samlAttributeName = suffix[1:] 2008 self.__samlAttribute2SqlQueryMap[samlAttributeName] = value 2009 else: 2010 object.__setattr__(self, name, value) 1981 2011 1982 2012 def setProperties(self, **properties): … … 2023 2053 doc="SAML Subject SQL Query") 2024 2054 2025 def _getSamlAttributeSqlQueries(self): 2026 return self.__samlAttributeSqlQueries 2027 2028 def _setSamlAttributeSqlQueries(self, value): 2029 if isinstance(value, basestring): 2030 # Allow for multiple queries split by a newline. Empty and 2031 # commented lines are skipped 2032 self.__samlAttributeSqlQueries = [q for q in value.split(os.linesep) 2033 if q and not q.startswith('#')] 2055 def _getSamlAttribute2SqlQueryMap(self): 2056 return self.__samlAttribute2SqlQueryMap 2057 2058 def _setSamlAttribute2SqlQueryMap(self, value): 2059 if isinstance(value, dict): 2060 # Validate string type for keys and values 2061 invalidItems = [(k, v) for k, v in value.items() 2062 if (not isinstance(k, basestring) or 2063 not isinstance(v, basestring))] 2064 if invalidItems: 2065 raise TypeError('Expecting string type for ' 2066 '"samlAttribute2SqlQueryMap" dict items; ' 2067 'got these/this invalid item(s) %r' % 2068 invalidItems) 2069 2070 self.__samlAttribute2SqlQueryMap = value 2034 2071 2035 2072 elif isinstance(value, (tuple, list)): … … 2038 2075 raise TypeError('Expecting string type for "%s" ' 2039 2076 'attribute items; got %r' % 2040 (SQLAlchemyAttributeInterface.SAML_ATTRIBUTE _SQLQUERIES_OPTNAME,2077 (SQLAlchemyAttributeInterface.SAML_ATTRIBUTE2SQLQUERY_MAP_OPTNAME, 2041 2078 type(value))) 2042 2079 2043 self.__samlAttribute SqlQueries= value2080 self.__samlAttribute2SqlQueryMap = value 2044 2081 else: 2045 raise TypeError('Expecting string, list or tuple type for "%s"'2046 'attribute; got %r' %2047 (SQLAlchemyAttributeInterface.SAML_ATTRIBUTE_SQLQUERIES_OPTNAME,2048 2049 2050 2051 samlAttribute SqlQueries = property(_getSamlAttributeSqlQueries,2052 _setSamlAttributeSqlQueries,2053 doc="SQL Query or queries to obtain the "2082 raise TypeError('Expecting dict type for ' 2083 '"samlAttribute2SqlQueryMap" attribute; got %r' % 2084 (SQLAlchemyAttributeInterface.SAML_ATTRIBUTE2SQLQUERY_MAP_OPTNAME, 2085 type(value))) 2086 2087 2088 samlAttribute2SqlQueryMap = property(_getSamlAttribute2SqlQueryMap, 2089 _setSamlAttribute2SqlQueryMap, 2090 doc="SQL Query or queries to obtain the " 2054 2091 "attribute information to respond " 2055 2092 "a SAML attribute query. The " -
TI12-security/trunk/python/ndg_security_test/ndg/security/test/unit/attributeauthority/test_attributeauthority.py
r5971 r5973 240 240 "Check the .msg files in this directory") 241 241 242 243 from warnings import warn 242 244 243 245 class SQLAlchemyAttributeInterfaceTestCase(BaseTestCase): 244 246 def __init__(self, *arg, **kw): 245 247 super(SQLAlchemyAttributeInterfaceTestCase, self).__init__(*arg, **kw) 248 self.skipTests = False 246 249 try: 247 250 self._createDb() 251 248 252 except NotImplementedError: 249 pass250 251 def setUp(self):252 pass253 # Don't proceed with tests because SQLAlchemy is not installed 254 warn("Skipping SQLAlchemyAttributeInterfaceTestCase because " 255 "SQLAlchemy is not installed") 256 self.skipTests = True 253 257 254 258 def test01(self): 259 if self.skipTests: 260 return 261 255 262 attributeInterface = SQLAlchemyAttributeInterface() 263 attributeInterface.samlAttribute2SqlQueryMap_firstName = 'Philip' 264 setattr(attributeInterface, 'samlAttribute2SqlQueryMap.lastName', 265 'Kershaw') 266 attributeInterface.samlAttribute2SqlQueryMap['emailAddress'] = ('pjk' 267 '@somewhere.ac.uk') 268 256 269 257 270 if __name__ == "__main__":
Note: See TracChangeset
for help on using the changeset viewer.