Skip to content

Commit 8e73e29

Browse files
author
Roland Hedberg
committed
SPs may not use the complete NameID when referering to a entity sometimes they obvious think it's sufficient to use used the value without the context. So I need to deal with that.
1 parent 429677d commit 8e73e29

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

src/saml2/ident.py

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,15 @@ def create_id(self, nformat, name_qualifier="", sp_name_qualifier=""):
8989
return _id
9090

9191
def store(self, ident, name_id):
92+
"""
93+
94+
:param ident: user identifier
95+
:param name_id: NameID instance
96+
"""
9297
if isinstance(ident, unicode):
9398
ident = ident.encode("utf-8")
9499

100+
# One user may have more than one NameID defined
95101
try:
96102
val = self.db[ident].split(" ")
97103
except KeyError:
@@ -100,19 +106,24 @@ def store(self, ident, name_id):
100106
_cn = code(name_id)
101107
val.append(_cn)
102108
self.db[ident] = " ".join(val)
103-
self.db[_cn] = ident
109+
self.db[name_id.text] = ident
104110

105111
def remove_remote(self, name_id):
112+
"""
113+
Remove a NameID to userID mapping
114+
115+
:param name_id: NameID instance
116+
"""
106117
_cn = code(name_id)
107-
_id = self.db[_cn]
118+
_id = self.db[name_id.text]
108119
try:
109120
vals = self.db[_id].split(" ")
110121
vals.remove(_cn)
111122
self.db[_id] = " ".join(vals)
112123
except KeyError:
113124
pass
114125

115-
del self.db[_cn]
126+
del self.db[name_id.text]
116127

117128
def remove_local(self, sid):
118129
if isinstance(sid, unicode):
@@ -121,7 +132,8 @@ def remove_local(self, sid):
121132
try:
122133
for val in self.db[sid].split(" "):
123134
try:
124-
del self.db[val]
135+
nid = decode(val)
136+
del self.db[nid.text]
125137
except KeyError:
126138
pass
127139
del self.db[sid]
@@ -147,6 +159,13 @@ def get_nameid(self, userid, nformat, sp_name_qualifier, name_qualifier):
147159
return nameid
148160

149161
def find_nameid(self, userid, **kwargs):
162+
"""
163+
Find a set of NameID's that matches the search criteria.
164+
165+
:param userid: User id
166+
:param kwargs: The search filter a set of attribute/value pairs
167+
:return: a list of NameID instances
168+
"""
150169
res = []
151170
try:
152171
_vals = self.db[userid]
@@ -157,8 +176,8 @@ def find_nameid(self, userid, **kwargs):
157176
for val in _vals.split(" "):
158177
nid = decode(val)
159178
if kwargs:
160-
for key, val in kwargs.items():
161-
if getattr(nid, key, None) != val:
179+
for key, _val in kwargs.items():
180+
if getattr(nid, key, None) != _val:
162181
break
163182
else:
164183
res.append(nid)
@@ -245,10 +264,10 @@ def find_local_id(self, name_id):
245264
"""
246265

247266
try:
248-
return self.db[code(name_id)]
267+
return self.db[name_id.text]
249268
except KeyError:
250-
logger.debug("name: %s" % code(name_id))
251-
logger.debug("id keys: %s" % self.db.keys())
269+
logger.debug("name: %s" % name_id.text)
270+
#logger.debug("id sub keys: %s" % self.subkeys())
252271
return None
253272

254273
def match_local_id(self, userid, sp_name_qualifier, name_qualifier):
@@ -336,3 +355,7 @@ def handle_manage_name_id_request(self, name_id, new_id=None,
336355
def close(self):
337356
if hasattr(self.db, 'close'):
338357
self.db.close()
358+
359+
def sync(self):
360+
if hasattr(self.db, 'sync'):
361+
self.db.sync()

src/saml2/server.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ def create_authn_response(self, identity, in_response_to, destination,
523523
name_id = self.ident.construct_nameid(userid, policy,
524524
sp_entity_id,
525525
name_id_policy)
526+
logger.debug("construct_nameid: %s => %s" % (userid,
527+
name_id))
526528
except IOError, exc:
527529
response = self.create_error_response(in_response_to,
528530
destination,

0 commit comments

Comments
 (0)