diff options
author | Roland Hedberg <roland.hedberg@adm.umu.se> | 2013-04-15 11:04:04 +0200 |
---|---|---|
committer | Roland Hedberg <roland.hedberg@adm.umu.se> | 2013-04-15 11:04:04 +0200 |
commit | 5c5e5257e61c77768739fee8f23fbb0613c1a7f5 (patch) | |
tree | 837d526c0753eaf8f0c8acffe9bbad873f64f609 /src/saml2/sdb.py | |
parent | 3faabf9f6480e5473f9fc27424a9cb6f373a88f2 (diff) | |
download | pysaml2-5c5e5257e61c77768739fee8f23fbb0613c1a7f5.tar.gz |
Moved Mongo DB based class to another module.
Diffstat (limited to 'src/saml2/sdb.py')
-rw-r--r-- | src/saml2/sdb.py | 99 |
1 files changed, 5 insertions, 94 deletions
diff --git a/src/saml2/sdb.py b/src/saml2/sdb.py index a2a0c087..c5a2f819 100644 --- a/src/saml2/sdb.py +++ b/src/saml2/sdb.py @@ -1,10 +1,8 @@ import logging from hashlib import sha1 -from pymongo import MongoClient from saml2.ident import code -from saml2.mdie import to_dict, from_dict from saml2 import md from saml2 import saml @@ -51,26 +49,14 @@ class SessionStorage(object): def store_assertion(self, assertion, to_sign): self.assertion[assertion.id] = (assertion, to_sign) - - def get_assertion(self, cid): - return self.assertion[cid] - - def store_authn_statement(self, authn_statement, name_id): - """ - - :param authn_statement: - :param name_id: - :return: - """ - logger.debug("store authn about: %s" % name_id) - nkey = sha1(code(name_id)).hexdigest() - logger.debug("Store authn_statement under key: %s" % nkey) + key = sha1(code(assertion.subject.name_id)).hexdigest() try: - self.authn[nkey].append(authn_statement) + self.authn[key].append(assertion.authn_statement) except KeyError: - self.authn[nkey] = [authn_statement] + self.authn[key] = [assertion.authn_statement] - return nkey + def get_assertion(self, cid): + return self.assertion[cid] def get_authn_statements(self, name_id, session_index=None, requested_context=None): @@ -106,78 +92,3 @@ class SessionStorage(object): nkey = sha1(code(name_id)).hexdigest() del self.authn[nkey] - - -class SessionStorageMDB(object): - """ Session information is stored in a MongoDB database""" - - def __init__(self, collection=""): - connection = MongoClient() - db = connection[collection] - self.assertion = db.assertion - self.authn = db.authn - - def store_assertion(self, assertion, to_sign): - self.assertion[assertion.id] = { - "assertion": to_dict(assertion, ONTS.values(), True), - "to_sign": to_sign} - - def get_assertion(self, cid): - _dict = self.assertion[cid] - return {"assertion": from_dict(_dict["assertion"], ONTS, True), - "to_sign": _dict["to_sign"]} - - def store_authn_statement(self, authn_statement, name_id): - """ - - :param authn_statement: - :param name_id: - :return: - """ - logger.debug("store authn about: %s" % name_id) - nkey = sha1(code(name_id)).hexdigest() - logger.debug("Store authn_statement under key: %s" % nkey) - _as = to_dict(authn_statement, ONTS.values(), True) - try: - self.authn[nkey].append(_as) - except KeyError: - self.authn[nkey] = [_as] - - return nkey - - def get_authn_statements(self, name_id=None, session_index=None, - requested_context=None): - """ - - :param name_id: One of name_id or key can be used to get the authn - statement - :param session_index: If match against a session index should be done - :param requested_context: Authn statements should match a specific - authn context - :return: - """ - result = [] - key = sha1(code(name_id)).hexdigest() - try: - statements = [from_dict(t, ONTS, True) for t in self.authn[key]] - except KeyError: - logger.info("Unknown subject %s" % name_id) - return [] - - for statement in statements: - if session_index: - if statement.session_index != session_index: - continue - if requested_context: - if not context_match(requested_context, - statement.authn_context): - continue - result.append(statement) - - return result - - def remove_authn_statements(self, name_id): - logger.debug("remove authn about: %s" % name_id) - nkey = sha1(code(name_id)).hexdigest() - - del self.authn[nkey] |