summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRoland Hedberg <roland.hedberg@adm.umu.se>2013-04-21 17:22:01 +0200
committerRoland Hedberg <roland.hedberg@adm.umu.se>2013-04-21 17:22:01 +0200
commit6dec8bfc913153544e8610b38ff4a6535792d7e7 (patch)
treef79920b52487c1f1e5155f177d87643cf9616ddf /src
parent40041b642e11a8838cc99f4ec358d134192f4166 (diff)
downloadpysaml2-6dec8bfc913153544e8610b38ff4a6535792d7e7.tar.gz
Adding authn context support.. plus first test
Diffstat (limited to 'src')
-rw-r--r--src/saml2/__init__.py8
-rw-r--r--src/saml2/authn_context/__init__.py31
2 files changed, 35 insertions, 4 deletions
diff --git a/src/saml2/__init__.py b/src/saml2/__init__.py
index eb1efdb7..4320e620 100644
--- a/src/saml2/__init__.py
+++ b/src/saml2/__init__.py
@@ -670,12 +670,20 @@ class SamlBase(ExtensionContainer):
return self
+ def clear_text(self):
+ if self.text:
+ _text = self.text.strip()
+ if _text == "":
+ self.text = None
+
def __eq__(self, other):
try:
assert isinstance(other, SamlBase)
except AssertionError:
return False
+ self.clear_text()
+ other.clear_text()
if len(self.keyswv()) != len(other.keyswv()):
return False
diff --git a/src/saml2/authn_context/__init__.py b/src/saml2/authn_context/__init__.py
index 47d87729..e746a8f0 100644
--- a/src/saml2/authn_context/__init__.py
+++ b/src/saml2/authn_context/__init__.py
@@ -34,10 +34,13 @@ class Authn(object):
if spec.authn_context_class_ref:
_endpspec[spec.authn_context_class_ref.text] = target
elif spec.authn_context_decl:
- _endpspec[
- spec.authn_context_decl.c_namespace] = spec.authn_context_decl
+ key = spec.authn_context_decl.c_namespace
+ try:
+ _endpspec[key].append((spec.authn_context_decl, target))
+ except KeyError:
+ _endpspec[key] = [(spec.authn_context_decl, target)]
- def pick(self, endpoint, authn_context):
+ def pick(self, endpoint, req_authn_context):
"""
Given which endpoint the request came in over and what
authentication context is defined find out where to send the user next.
@@ -45,4 +48,24 @@ class Authn(object):
:param endpoint: The service endpoint URL
:param authn_context: An AuthnContext instance
:return: An URL
- """ \ No newline at end of file
+ """
+
+ try:
+ _endpspec = self.db[endpoint]
+ except KeyError:
+ self.db[endpoint] = {}
+ _endpspec = self.db[endpoint]
+
+ if req_authn_context.authn_context_class_ref:
+ return _endpspec[req_authn_context.authn_context_class_ref.text]
+ elif req_authn_context.authn_context_decl:
+ key = req_authn_context.authn_context_decl.c_namespace
+ for spec, target in _endpspec[key]:
+ if self.match(req_authn_context, spec):
+ return target
+
+ def match(self, requested, provided):
+ if requested == provided:
+ return True
+ else:
+ return False \ No newline at end of file