Package ndg :: Package saml :: Package saml2 :: Package binding :: Package soap :: Package client :: Module authzdecisionquery
[hide private]

Source Code for Module ndg.saml.saml2.binding.soap.client.authzdecisionquery

  1  """SAML 2.0 bindings module implements SOAP binding for Authorisation Decision 
  2  query 
  3   
  4  NERC DataGrid Project 
  5  """ 
  6  __author__ = "P J Kershaw" 
  7  __date__ = "12/02/10" 
  8  __copyright__ = "(C) 2009 Science and Technology Facilities Council" 
  9  __license__ = "http://www.apache.org/licenses/LICENSE-2.0" 
 10  __contact__ = "Philip.Kershaw@stfc.ac.uk" 
 11  __revision__ = '$Id: authzdecisionquery.py 8047 2012-03-28 09:46:29Z rwilkinson $' 
 12  import logging 
 13  log = logging.getLogger(__name__) 
 14   
 15  from M2Crypto.m2urllib2 import HTTPSHandler 
 16   
 17  from ndg.saml.saml2.core import AuthzDecisionQuery 
 18   
 19  from ndg.saml.saml2.binding.soap.client.subjectquery import ( 
 20                                                      SubjectQuerySOAPBinding, 
 21                                                      SubjectQueryResponseError) 
 22   
 23  # Prevent whole module breaking if this is not available - it's only needed for 
 24  # AuthzDecisionQuerySslSOAPBinding 
 25  try: 
 26      from ndg.saml.utils.m2crypto import SSLContextProxy 
 27      _sslContextProxySupport = True 
 28       
 29  except ImportError: 
 30      _sslContextProxySupport = False 
31 32 33 -class AuthzDecisionQueryResponseError(SubjectQueryResponseError):
34 """SAML Response error from Attribute Query"""
35
36 37 -class AuthzDecisionQuerySOAPBinding(SubjectQuerySOAPBinding):
38 """SAML Attribute Query SOAP Binding 39 40 Nb. Assumes X.509 subject type for query issuer 41 """ 42 SERIALISE_KW = 'serialise' 43 DESERIALISE_KW = 'deserialise' 44 QUERY_TYPE = AuthzDecisionQuery 45 __slots__ = () 46
47 - def __init__(self, **kw):
48 '''Create SOAP Client for SAML Authorization Decision Query''' 49 cls = AuthzDecisionQuerySOAPBinding 50 51 # Default to ElementTree based serialisation/deserialisation 52 if cls.SERIALISE_KW not in kw: 53 from ndg.saml.xml.etree import AuthzDecisionQueryElementTree 54 kw[cls.SERIALISE_KW] = AuthzDecisionQueryElementTree.toXML 55 56 if cls.DESERIALISE_KW not in kw: 57 from ndg.saml.xml.etree import ResponseElementTree 58 kw[cls.DESERIALISE_KW] = ResponseElementTree.fromXML 59 60 super(AuthzDecisionQuerySOAPBinding, self).__init__(**kw)
61
62 63 -class AuthzDecisionQuerySslSOAPBinding(AuthzDecisionQuerySOAPBinding):
64 """Specialisation of AuthzDecisionQuerySOAPbinding taking in the setting of 65 SSL parameters for mutual authentication 66 """ 67 SSL_CONTEXT_PROXY_SUPPORT = _sslContextProxySupport 68 __slots__ = ('__sslCtxProxy',) 69
70 - def __init__(self, **kw):
71 if not AuthzDecisionQuerySslSOAPBinding.SSL_CONTEXT_PROXY_SUPPORT: 72 raise ImportError("ndg.security.common.utils.m2crypto import " 73 "failed - missing M2Crypto package?") 74 75 # Miss out default HTTPSHandler and set in send() instead 76 if 'handlers' in kw: 77 raise TypeError("__init__() got an unexpected keyword argument " 78 "'handlers'") 79 80 super(AuthzDecisionQuerySslSOAPBinding, self).__init__(handlers=(), 81 **kw) 82 self.__sslCtxProxy = SSLContextProxy()
83
84 - def send(self, query, **kw):
85 """Override base class implementation to pass explicit SSL Context 86 """ 87 httpsHandler = HTTPSHandler(ssl_context=self.sslCtxProxy.createCtx()) 88 self.client.openerDirector.add_handler(httpsHandler) 89 return super(AuthzDecisionQuerySslSOAPBinding, self).send(query, **kw)
90 91 @property
92 - def sslCtxProxy(self):
93 """SSL Context Proxy object used for setting up an SSL Context for 94 queries 95 """ 96 return self.__sslCtxProxy
97
98 - def __setattr__(self, name, value):
99 """Enable setting of SSLContextProxy attributes as if they were 100 attributes of this class. This is intended as a convenience for 101 making settings parameters read from a config file 102 """ 103 try: 104 super(AuthzDecisionQuerySslSOAPBinding, self).__setattr__(name, 105 value) 106 107 except AttributeError, e: 108 # Coerce into setting SSL Context Proxy attributes 109 try: 110 setattr(self.sslCtxProxy, name, value) 111 except: 112 raise e
113