3
from hashlib import sha1
5
from saml2.ident import code
9
from saml2.extension import mdui
10
from saml2.extension import idpdisc
11
from saml2.extension import dri
12
from saml2.extension import mdattr
13
from saml2.extension import ui
21
mdattr.NAMESPACE: mdattr,
24
idpdisc.NAMESPACE: idpdisc,
26
xmldsig.NAMESPACE: xmldsig,
27
xmlenc.NAMESPACE: xmlenc
30
__author__ = 'rolandh'
32
logger = logging.getLogger(__name__)
35
def context_match(cfilter, cntx):
39
# The key to the stored authn statement is placed encrypted in the cookie
42
class SessionStorage(object):
43
""" In memory storage of session information """
46
self.db = {"assertion": {}, "authn": {}}
47
self.assertion = self.db["assertion"]
48
self.authn = self.db["authn"]
50
def store_assertion(self, assertion, to_sign):
51
self.assertion[assertion.id] = (assertion, to_sign)
52
key = sha1(code(assertion.subject.name_id)).hexdigest()
54
self.authn[key].append(assertion.authn_statement)
56
self.authn[key] = [assertion.authn_statement]
58
def get_assertion(self, cid):
59
return self.assertion[cid]
61
def get_authn_statements(self, name_id, session_index=None,
62
requested_context=None):
67
:param requested_context:
71
key = sha1(code(name_id)).hexdigest()
73
statements = self.authn[key]
75
logger.info("Unknown subject %s" % name_id)
78
for statement in statements:
80
if statement.session_index != session_index:
83
if not context_match(requested_context,
84
statement[0].authn_context):
86
result.append(statement)
90
def remove_authn_statements(self, name_id):
91
logger.debug("remove authn about: %s" % name_id)
92
nkey = sha1(code(name_id)).hexdigest()