Skip to content

Commit 197d105

Browse files
author
Hans Hörberg
committed
Merge remote-tracking branch 'upstream/master'
2 parents 62914b4 + c1eb135 commit 197d105

File tree

19 files changed

+382
-271
lines changed

19 files changed

+382
-271
lines changed

example/README

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ To make it easy, for me :-), both the IdP and the SP uses the same keys.
2121

2222
To run the setup do
2323

24-
./run.sh
24+
./all.sh start
2525

2626
and then use your favourit webbrowser to look at "http://localhost:8087/whoami"
27+
28+
./all stop
29+
30+
will of course stop your IdP and SP.

example/all.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/sh
2+
3+
startme() {
4+
cd sp-wsgi
5+
if [ ! -f conf.py ] ; then
6+
cp conf.py.example conf.py
7+
fi
8+
../../tools/make_metadata.py conf > sp.xml
9+
10+
cd ../idp2
11+
if [ ! -f idp_conf.py ] ; then
12+
cp idp_conf.py.example conf.py
13+
fi
14+
../../tools/make_metadata.py idp_conf > idp.xml
15+
16+
cd ../sp-wsgi
17+
./sp.py conf &
18+
19+
cd ../idp2
20+
./idp.py idp_conf &
21+
22+
cd ..
23+
}
24+
25+
stopme() {
26+
pkill -f "sp.py"
27+
pkill -f "idp.py"
28+
}
29+
30+
case "$1" in
31+
start) startme ;;
32+
stop) stopme ;;
33+
restart) stopme; startme ;;
34+
*) echo "usage: $0 start|stop|restart" >&2
35+
exit 1
36+
;;
37+
esac

example/run.sh

Lines changed: 0 additions & 16 deletions
This file was deleted.

example/sp-wsgi/conf.py renamed to example/sp-wsgi/conf.py.example

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,5 @@
3535
"cert_file": "pki/mycert.pem",
3636
"xmlsec_binary": xmlsec_path,
3737
"metadata": {"local": ["../idp2/idp.xml"]},
38-
#"metadata": {"mdfile": ["./swamid2.md"]},
39-
#"metadata": {"local": ["./swamid-2.0.xml"]},
4038
"name_form": NAME_FORMAT_URI,
4139
}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def run_tests(self):
6666

6767
setup(
6868
name='pysaml2',
69-
version='2.0.0beta',
69+
version='2.0.1beta',
7070
description='Python implementation of SAML Version 2 to be used in a WSGI environment',
7171
# long_description = read("README"),
7272
author='Roland Hedberg',

src/saml2/assertion.py

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
from saml2 import saml
2525

2626
from saml2.time_util import instant, in_a_while
27-
from saml2.attribute_converter import from_local
27+
from saml2.attribute_converter import from_local, get_local_name
2828
from saml2.s_utils import sid, MissingValue
2929
from saml2.s_utils import factory
3030
from saml2.s_utils import assertion_factory
@@ -78,7 +78,7 @@ def _match(attr, ava):
7878
return None
7979

8080

81-
def filter_on_attributes(ava, required=None, optional=None):
81+
def filter_on_attributes(ava, required=None, optional=None, acs=None):
8282
""" Filter
8383
8484
:param ava: An attribute value assertion as a dictionary
@@ -93,27 +93,33 @@ def filter_on_attributes(ava, required=None, optional=None):
9393
if required is None:
9494
required = []
9595

96+
nform = "friendly_name"
9697
for attr in required:
97-
found = False
98-
nform = ""
99-
for nform in ["friendly_name", "name"]:
100-
try:
101-
_fn = _match(attr[nform], ava)
102-
except KeyError:
103-
pass
98+
try:
99+
_name = attr[nform]
100+
except KeyError:
101+
if nform == "friendly_name":
102+
_name = get_local_name(acs, attr["name"],
103+
attr["name_format"])
104104
else:
105-
if _fn:
106-
try:
107-
values = [av["text"] for av in attr["attribute_value"]]
108-
except KeyError:
109-
values = []
110-
res[_fn] = _filter_values(ava[_fn], values, True)
111-
found = True
112-
break
105+
continue
106+
107+
_fn = _match(_name, ava)
108+
if not _fn: # In the unlikely case that someone has provided us
109+
# with URIs as attribute names
110+
_fn = _match(attr["name"], ava)
113111

114-
if not found:
115-
raise MissingValue("Required attribute missing: '%s'" % (
116-
attr[nform],))
112+
if _fn:
113+
try:
114+
values = [av["text"] for av in attr["attribute_value"]]
115+
except KeyError:
116+
values = []
117+
res[_fn] = _filter_values(ava[_fn], values, True)
118+
continue
119+
else:
120+
desc = "Required attribute missing: '%s' (%s)" % (attr["name"],
121+
_name)
122+
raise MissingValue(desc)
117123

118124
if optional is None:
119125
optional = []
@@ -311,7 +317,8 @@ def __init__(self, restrictions=None):
311317
self.compile(restrictions)
312318
else:
313319
self._restrictions = None
314-
320+
self.acs = []
321+
315322
def compile(self, restrictions):
316323
""" This is only for IdPs or AAs, and it's about limiting what
317324
is returned to the SP.
@@ -484,7 +491,8 @@ def filter(self, ava, sp_entity_id, mdstore, required=None, optional=None):
484491
ava = filter_attribute_value_assertions(ava, _rest)
485492

486493
if required or optional:
487-
ava = filter_on_attributes(ava, required, optional)
494+
logger.debug("required: %s, optional: %s" % (required, optional))
495+
ava = filter_on_attributes(ava, required, optional, self.acs)
488496

489497
return ava
490498

@@ -540,8 +548,10 @@ class Assertion(dict):
540548

541549
def __init__(self, dic=None):
542550
dict.__init__(self, dic)
543-
544-
def _authn_context_decl(self, decl, authn_auth=None):
551+
self.acs = []
552+
553+
@staticmethod
554+
def _authn_context_decl(decl, authn_auth=None):
545555
"""
546556
Construct the authn context with a authn context declaration
547557
:param decl: The authn context declaration
@@ -726,6 +736,8 @@ def apply_policy(self, sp_entity_id, policy, metadata=None):
726736
:param metadata: Metadata to use
727737
:return: The resulting AVA after the policy is applied
728738
"""
739+
740+
policy.acs = self.acs
729741
ava = policy.restrict(self, sp_entity_id, metadata)
730742
self.update(ava)
731743
return ava

src/saml2/attribute_converter.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ def to_local_name(acs, attr):
255255
return attr.friendly_name
256256

257257

258+
def get_local_name(acs, attr, name_format):
259+
for aconv in acs:
260+
#print ac.format, name_format
261+
if aconv.name_format == name_format:
262+
return aconv._fro[attr]
263+
264+
258265
def d_to_local_name(acs, attr):
259266
"""
260267
:param acs: List of AttributeConverter instances

src/saml2/attributemaps/saml_uri.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@
177177
'edupersonaffiliation': EDUPERSON_OID+'1',
178178
'eduPersonPrincipalName': EDUPERSON_OID+'6',
179179
'edupersonprincipalname': EDUPERSON_OID+'6',
180+
'eppn': EDUPERSON_OID+'6',
180181
'localityName': X500ATTR_OID+'7',
181182
'owner': X500ATTR_OID+'32',
182183
'norEduOrgUnitUniqueNumber': NOREDUPERSON_OID+'2',

0 commit comments

Comments
 (0)