Skip to content

Commit

Permalink
Changed parameter name from _cache to cache.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roland Hedberg committed Apr 19, 2013
1 parent f6933b0 commit 48bbb17
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 17 deletions.
27 changes: 18 additions & 9 deletions example/idp2/idp.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@
logger = logging.getLogger("saml2.idp")


class Cache(object):
def __init__(self):
self.user2uid = {}
self.uid2user = {}


def _expiration(timeout, tformat="%a, %d-%b-%Y %H:%M:%S GMT"):
"""
Expand Down Expand Up @@ -417,8 +423,8 @@ def do_verify(environ, start_response, _):
resp = Unauthorized("Unknown user or wrong password")
else:
uid = rndstr(24)
IDP.uid2user[uid] = user
IDP.user2uid[user] = uid
IDP.cache.uid2user[uid] = user
IDP.cache.user2uid[user] = uid
logger.debug("Register %s under '%s'" % (user, uid))
kaka = set_cookie("idpauthn", "/", uid)
lox = "http://%s%s?id=%s&key=%s" % (environ["HTTP_HOST"],
Expand Down Expand Up @@ -463,8 +469,8 @@ def do(self, request, binding, relay_state=""):
if msg.name_id:
lid = IDP.ident.find_local_id(msg.name_id)
logger.info("local identifier: %s" % lid)
del IDP.uid2user[IDP.user2uid[lid]]
del IDP.user2uid[lid]
del IDP.cache.uid2user[IDP.cache.user2uid[lid]]
del IDP.cache.user2uid[lid]
# remove the authentication
try:
IDP.session_db.remove_authn_statements(msg.name_id)
Expand Down Expand Up @@ -603,13 +609,13 @@ def do(self, request, binding, relay_state=""):
_query = _req.message

name_id = _query.subject.name_id
uid = IDP.ident.find_local_id(name_id)
uid = name_id.text
logger.debug("Local uid: %s" % uid)
identity = EXTRA[uid]

# Comes in over SOAP so only need to construct the response
args = IDP.response_args(_query, [BINDING_SOAP])
msg = IDP.create_attribute_response(identity, destination="",
msg = IDP.create_attribute_response(identity,
name_id=name_id, **args)

logger.debug("response: %s" % msg)
Expand Down Expand Up @@ -664,7 +670,7 @@ def kaka2user(kaka):
morsel = cookie_obj.get("idpauthn", None)
if morsel:
try:
return IDP.uid2user[morsel.value]
return IDP.cache.uid2user[morsel.value]
except KeyError:
return None
else:
Expand Down Expand Up @@ -768,7 +774,7 @@ def application(environ, start_response):
try:
query = parse_qs(environ["QUERY_STRING"])
logger.debug("QUERY: %s" % query)
user = IDP.uid2user[query["id"][0]]
user = IDP.cache.uid2user[query["id"][0]]
except KeyError:
user = None

Expand Down Expand Up @@ -816,6 +822,7 @@ def application(environ, start_response):
LOOKUP = TemplateLookup(directories=[ROOT + 'templates', ROOT + 'htdocs'],
module_directory=ROOT + 'modules',
input_encoding='utf-8', output_encoding='utf-8')

# ----------------------------------------------------------------------------

if __name__ == '__main__':
Expand All @@ -826,8 +833,10 @@ def application(environ, start_response):

PORT = 8088

IDP = server.Server(sys.argv[1])
IDP = server.Server(sys.argv[1], cache=Cache()
)
IDP.ticket = {}

SRV = make_server('', PORT, application)
print "IdP listening on port: %s" % PORT
SRV.serve_forever()
4 changes: 2 additions & 2 deletions src/saml2/ecp.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ class ECPServer(Server):
TODO: Still tentative
"""
def __init__(self, config_file="", config=None, _cache=""):
Server.__init__(self, config_file, config, _cache)
def __init__(self, config_file="", config=None, cache=None):
Server.__init__(self, config_file, config, cache)

def parse_ecp_authn_query(self):
pass
Expand Down
8 changes: 2 additions & 6 deletions src/saml2/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import os

import shelve
import sys
import memcache
from saml2.mongo_store import IdentMDB, SessionStorageMDB
from saml2.sdb import SessionStorage
Expand Down Expand Up @@ -52,22 +51,19 @@
from saml2.assertion import filter_attribute_value_assertions

from saml2.ident import IdentDB
#from saml2.profile import paos
from saml2.profile import ecp

logger = logging.getLogger(__name__)


class Server(Entity):
""" A class that does things that IdPs or AAs do """
def __init__(self, config_file="", config=None, _cache="", stype="idp",
def __init__(self, config_file="", config=None, cache=None, stype="idp",
symkey=""):
Entity.__init__(self, stype, config, config_file)
self.init_config(stype)
self._cache = _cache
self.cache = cache
self.ticket = {}
self.user2uid = {}
self.uid2user = {}
#
self.session_db = self.choose_session_storage()
# Needed for
Expand Down

0 comments on commit 48bbb17

Please sign in to comment.