Skip to content

Commit 144248f

Browse files
author
ivan
committed
Add eIDAS SPType node support
1 parent 701bdac commit 144248f

File tree

7 files changed

+106
-2
lines changed

7 files changed

+106
-2
lines changed

src/saml2/client_base.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from saml2.samlp import AttributeQuery
1919
from saml2.samlp import AuthzDecisionQuery
2020
from saml2.samlp import AuthnRequest
21+
from saml2.samlp import Extensions
22+
from saml2.extension import sp_type
2123

2224
import saml2
2325
import time
@@ -347,6 +349,14 @@ def create_authn_request(self, destination, vorg="", scoping=None,
347349
if force_authn:
348350
args['force_authn'] = 'true'
349351

352+
conf_sp_type = self.config.getattr('sp_type', 'sp')
353+
conf_sp_type_in_md = self.config.getattr('sp_type_in_metadata', 'sp')
354+
if conf_sp_type and conf_sp_type_in_md is False:
355+
if not extensions:
356+
extensions = Extensions()
357+
item = sp_type.SPType(text=conf_sp_type)
358+
extensions.add_extension_element(item)
359+
350360
if kwargs:
351361
_args, extensions = self._filter_args(AuthnRequest(), extensions,
352362
**kwargs)

src/saml2/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
"requested_attribute_name_format",
7979
"hide_assertion_consumer_service",
8080
"force_authn",
81+
"sp_type",
82+
"sp_type_in_metadata",
8183
]
8284

8385
AA_IDP_ARGS = [

src/saml2/extension/sp_type.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/usr/bin/env python
2+
3+
#
4+
# Generated Tue Jul 18 15:03:44 2017 by parse_xsd.py version 0.5.
5+
#
6+
7+
import saml2
8+
from saml2 import SamlBase
9+
10+
11+
NAMESPACE = 'http://eidas.europa.eu/saml-extensions'
12+
13+
class SPTypeType_(SamlBase):
14+
"""The http://eidas.europa.eu/saml-extensions:SPTypeType element """
15+
16+
c_tag = 'SPTypeType'
17+
c_namespace = NAMESPACE
18+
c_value_type = {'base': 'xsd:string', 'enumeration': ['public', 'private']}
19+
c_children = SamlBase.c_children.copy()
20+
c_attributes = SamlBase.c_attributes.copy()
21+
c_child_order = SamlBase.c_child_order[:]
22+
c_cardinality = SamlBase.c_cardinality.copy()
23+
24+
def sp_type_type__from_string(xml_string):
25+
return saml2.create_class_from_xml_string(SPTypeType_, xml_string)
26+
27+
28+
class SPType(SPTypeType_):
29+
"""The http://eidas.europa.eu/saml-extensions:SPType element """
30+
31+
c_tag = 'SPType'
32+
c_namespace = NAMESPACE
33+
c_children = SPTypeType_.c_children.copy()
34+
c_attributes = SPTypeType_.c_attributes.copy()
35+
c_child_order = SPTypeType_.c_child_order[:]
36+
c_cardinality = SPTypeType_.c_cardinality.copy()
37+
38+
def sp_type_from_string(xml_string):
39+
return saml2.create_class_from_xml_string(SPType, xml_string)
40+
41+
42+
ELEMENT_FROM_STRING = {
43+
SPType.c_tag: sp_type_from_string,
44+
SPTypeType_.c_tag: sp_type_type__from_string,
45+
}
46+
47+
ELEMENT_BY_TAG = {
48+
'SPType': SPType,
49+
'SPTypeType': SPTypeType_,
50+
}
51+
52+
53+
def factory(tag, **kwargs):
54+
return ELEMENT_BY_TAG[tag](**kwargs)

src/saml2/metadata.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from saml2.extension import idpdisc
1010
from saml2.extension import shibmd
1111
from saml2.extension import mdattr
12+
from saml2.extension import sp_type
1213
from saml2.saml import NAME_FORMAT_URI
1314
from saml2.saml import AttributeValue
1415
from saml2.saml import Attribute
@@ -722,7 +723,8 @@ def entity_descriptor(confd):
722723
entd.contact_person = do_contact_person_info(confd.contact_person)
723724

724725
if confd.entity_category:
725-
entd.extensions = md.Extensions()
726+
if not entd.extensions:
727+
entd.extensions = md.Extensions()
726728
ava = [AttributeValue(text=c) for c in confd.entity_category]
727729
attr = Attribute(attribute_value=ava,
728730
name="http://macedir.org/entity-category")
@@ -734,6 +736,14 @@ def entity_descriptor(confd):
734736
entd.extensions = md.Extensions()
735737
entd.extensions.add_extension_element(item)
736738

739+
conf_sp_type = confd.getattr('sp_type', 'sp')
740+
conf_sp_type_in_md = confd.getattr('sp_type_in_metadata', 'sp')
741+
if conf_sp_type and conf_sp_type_in_md is True:
742+
if not entd.extensions:
743+
entd.extensions = md.Extensions()
744+
item = sp_type.SPType(text=conf_sp_type)
745+
entd.extensions.add_extension_element(item)
746+
737747
serves = confd.serves
738748
if not serves:
739749
raise SAMLError(

tests/sp_mdext_conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"description": "My own SP",
77
"service": {
88
"sp": {
9+
"sp_type": "public",
10+
"sp_type_in_metadata": True,
911
"endpoints": {
1012
"assertion_consumer_service": [
1113
"http://lingon.catalogix.se:8087/"],

tests/test_83_md_extensions.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from saml2.config import Config
22
from saml2.metadata import entity_descriptor
3+
from saml2.extension.sp_type import SPType
34

45
__author__ = 'roland'
56

@@ -14,4 +15,13 @@
1415
assert len(ed.spsso_descriptor.extensions.extension_elements) == 3
1516

1617
assert ed.extensions
17-
assert len(ed.extensions.extension_elements) > 1
18+
assert len(ed.extensions.extension_elements) > 1
19+
20+
assert any(e.tag is SPType.c_tag for e in ed.extensions.extension_elements)
21+
22+
cnf.setattr('sp', 'sp_type_in_metadata', False)
23+
ed = entity_descriptor(cnf)
24+
25+
print(ed)
26+
27+
assert all(e.tag is not SPType.c_tag for e in ed.extensions.extension_elements)

tools/data/sp_type.xsd

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsd:schema
3+
xmlns="http://eidas.europa.eu/saml-extensions"
4+
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
5+
targetNamespace="http://eidas.europa.eu/saml-extensions"
6+
elementFormDefault="qualified"
7+
attributeFormDefault="unqualified"
8+
version="1">
9+
<xsd:element name="SPType" type="SPTypeType"/>
10+
<xsd:simpleType name="SPTypeType">
11+
<xsd:restriction base="xsd:string">
12+
<xsd:enumeration value="public"/>
13+
<xsd:enumeration value="private"/>
14+
</xsd:restriction>
15+
</xsd:simpleType>
16+
</xsd:schema>

0 commit comments

Comments
 (0)