summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan@grnet.gr>2017-07-14 17:23:29 +0300
committerivan <ivan@grnet.gr>2017-10-08 19:47:24 +0300
commit144248f968603c1483c56fcbbddab0edfd61613f (patch)
treeec8e84431d4b6855001633699f2d2a40c4c439aa
parent701bdacd43bdc3a0a15a6097b9c0b9ae4064993a (diff)
downloadpysaml2-144248f968603c1483c56fcbbddab0edfd61613f.tar.gz
Add eIDAS SPType node support
-rw-r--r--src/saml2/client_base.py10
-rw-r--r--src/saml2/config.py2
-rw-r--r--src/saml2/extension/sp_type.py54
-rw-r--r--src/saml2/metadata.py12
-rw-r--r--tests/sp_mdext_conf.py2
-rw-r--r--tests/test_83_md_extensions.py12
-rw-r--r--tools/data/sp_type.xsd16
7 files changed, 106 insertions, 2 deletions
diff --git a/src/saml2/client_base.py b/src/saml2/client_base.py
index 50b457d1..88a9bd11 100644
--- a/src/saml2/client_base.py
+++ b/src/saml2/client_base.py
@@ -18,6 +18,8 @@ from saml2.samlp import NameIDMappingRequest
from saml2.samlp import AttributeQuery
from saml2.samlp import AuthzDecisionQuery
from saml2.samlp import AuthnRequest
+from saml2.samlp import Extensions
+from saml2.extension import sp_type
import saml2
import time
@@ -347,6 +349,14 @@ class Base(Entity):
if force_authn:
args['force_authn'] = 'true'
+ conf_sp_type = self.config.getattr('sp_type', 'sp')
+ conf_sp_type_in_md = self.config.getattr('sp_type_in_metadata', 'sp')
+ if conf_sp_type and conf_sp_type_in_md is False:
+ if not extensions:
+ extensions = Extensions()
+ item = sp_type.SPType(text=conf_sp_type)
+ extensions.add_extension_element(item)
+
if kwargs:
_args, extensions = self._filter_args(AuthnRequest(), extensions,
**kwargs)
diff --git a/src/saml2/config.py b/src/saml2/config.py
index e508a954..3c8618f4 100644
--- a/src/saml2/config.py
+++ b/src/saml2/config.py
@@ -78,6 +78,8 @@ SP_ARGS = [
"requested_attribute_name_format",
"hide_assertion_consumer_service",
"force_authn",
+ "sp_type",
+ "sp_type_in_metadata",
]
AA_IDP_ARGS = [
diff --git a/src/saml2/extension/sp_type.py b/src/saml2/extension/sp_type.py
new file mode 100644
index 00000000..8ffb2cea
--- /dev/null
+++ b/src/saml2/extension/sp_type.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+#
+# Generated Tue Jul 18 15:03:44 2017 by parse_xsd.py version 0.5.
+#
+
+import saml2
+from saml2 import SamlBase
+
+
+NAMESPACE = 'http://eidas.europa.eu/saml-extensions'
+
+class SPTypeType_(SamlBase):
+ """The http://eidas.europa.eu/saml-extensions:SPTypeType element """
+
+ c_tag = 'SPTypeType'
+ c_namespace = NAMESPACE
+ c_value_type = {'base': 'xsd:string', 'enumeration': ['public', 'private']}
+ c_children = SamlBase.c_children.copy()
+ c_attributes = SamlBase.c_attributes.copy()
+ c_child_order = SamlBase.c_child_order[:]
+ c_cardinality = SamlBase.c_cardinality.copy()
+
+def sp_type_type__from_string(xml_string):
+ return saml2.create_class_from_xml_string(SPTypeType_, xml_string)
+
+
+class SPType(SPTypeType_):
+ """The http://eidas.europa.eu/saml-extensions:SPType element """
+
+ c_tag = 'SPType'
+ c_namespace = NAMESPACE
+ c_children = SPTypeType_.c_children.copy()
+ c_attributes = SPTypeType_.c_attributes.copy()
+ c_child_order = SPTypeType_.c_child_order[:]
+ c_cardinality = SPTypeType_.c_cardinality.copy()
+
+def sp_type_from_string(xml_string):
+ return saml2.create_class_from_xml_string(SPType, xml_string)
+
+
+ELEMENT_FROM_STRING = {
+ SPType.c_tag: sp_type_from_string,
+ SPTypeType_.c_tag: sp_type_type__from_string,
+}
+
+ELEMENT_BY_TAG = {
+ 'SPType': SPType,
+ 'SPTypeType': SPTypeType_,
+}
+
+
+def factory(tag, **kwargs):
+ return ELEMENT_BY_TAG[tag](**kwargs)
diff --git a/src/saml2/metadata.py b/src/saml2/metadata.py
index 50ec0bae..de2e6e75 100644
--- a/src/saml2/metadata.py
+++ b/src/saml2/metadata.py
@@ -9,6 +9,7 @@ from saml2.extension import mdui
from saml2.extension import idpdisc
from saml2.extension import shibmd
from saml2.extension import mdattr
+from saml2.extension import sp_type
from saml2.saml import NAME_FORMAT_URI
from saml2.saml import AttributeValue
from saml2.saml import Attribute
@@ -722,7 +723,8 @@ def entity_descriptor(confd):
entd.contact_person = do_contact_person_info(confd.contact_person)
if confd.entity_category:
- entd.extensions = md.Extensions()
+ if not entd.extensions:
+ entd.extensions = md.Extensions()
ava = [AttributeValue(text=c) for c in confd.entity_category]
attr = Attribute(attribute_value=ava,
name="http://macedir.org/entity-category")
@@ -734,6 +736,14 @@ def entity_descriptor(confd):
entd.extensions = md.Extensions()
entd.extensions.add_extension_element(item)
+ conf_sp_type = confd.getattr('sp_type', 'sp')
+ conf_sp_type_in_md = confd.getattr('sp_type_in_metadata', 'sp')
+ if conf_sp_type and conf_sp_type_in_md is True:
+ if not entd.extensions:
+ entd.extensions = md.Extensions()
+ item = sp_type.SPType(text=conf_sp_type)
+ entd.extensions.add_extension_element(item)
+
serves = confd.serves
if not serves:
raise SAMLError(
diff --git a/tests/sp_mdext_conf.py b/tests/sp_mdext_conf.py
index 67e33414..b1f0cf42 100644
--- a/tests/sp_mdext_conf.py
+++ b/tests/sp_mdext_conf.py
@@ -6,6 +6,8 @@ CONFIG = {
"description": "My own SP",
"service": {
"sp": {
+ "sp_type": "public",
+ "sp_type_in_metadata": True,
"endpoints": {
"assertion_consumer_service": [
"http://lingon.catalogix.se:8087/"],
diff --git a/tests/test_83_md_extensions.py b/tests/test_83_md_extensions.py
index 71f98868..dace10a5 100644
--- a/tests/test_83_md_extensions.py
+++ b/tests/test_83_md_extensions.py
@@ -1,5 +1,6 @@
from saml2.config import Config
from saml2.metadata import entity_descriptor
+from saml2.extension.sp_type import SPType
__author__ = 'roland'
@@ -14,4 +15,13 @@ assert ed.spsso_descriptor.extensions
assert len(ed.spsso_descriptor.extensions.extension_elements) == 3
assert ed.extensions
-assert len(ed.extensions.extension_elements) > 1 \ No newline at end of file
+assert len(ed.extensions.extension_elements) > 1
+
+assert any(e.tag is SPType.c_tag for e in ed.extensions.extension_elements)
+
+cnf.setattr('sp', 'sp_type_in_metadata', False)
+ed = entity_descriptor(cnf)
+
+print(ed)
+
+assert all(e.tag is not SPType.c_tag for e in ed.extensions.extension_elements)
diff --git a/tools/data/sp_type.xsd b/tools/data/sp_type.xsd
new file mode 100644
index 00000000..dbb1418d
--- /dev/null
+++ b/tools/data/sp_type.xsd
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsd:schema
+ xmlns="http://eidas.europa.eu/saml-extensions"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://eidas.europa.eu/saml-extensions"
+ elementFormDefault="qualified"
+ attributeFormDefault="unqualified"
+ version="1">
+ <xsd:element name="SPType" type="SPTypeType"/>
+ <xsd:simpleType name="SPTypeType">
+ <xsd:restriction base="xsd:string">
+ <xsd:enumeration value="public"/>
+ <xsd:enumeration value="private"/>
+ </xsd:restriction>
+ </xsd:simpleType>
+</xsd:schema>