Added a MDX client as a Metadata class.
This commit is contained in:
@@ -3,6 +3,7 @@ import sys
|
||||
import json
|
||||
|
||||
from hashlib import sha1
|
||||
from urllib import urlencode, quote_plus
|
||||
from saml2.httpbase import HTTPBase
|
||||
from saml2.extension.idpdisc import BINDING_DISCO
|
||||
from saml2.extension.idpdisc import DiscoveryResponse
|
||||
@@ -525,6 +526,51 @@ class MetaDataMD(MetaData):
|
||||
self.entity[key] = item
|
||||
|
||||
|
||||
class MetaDataMDX(MetaData):
|
||||
def __init__(self, onts, attrc, url, security, cert, http, **kwargs):
|
||||
"""
|
||||
:params onts:
|
||||
:params attrc:
|
||||
:params url:
|
||||
:params security: SecurityContext()
|
||||
:params cert:
|
||||
:params http:
|
||||
"""
|
||||
MetaData.__init__(self, onts, attrc, **kwargs)
|
||||
self.url = url
|
||||
self.security = security
|
||||
self.cert = cert
|
||||
self.http = http
|
||||
|
||||
def load(self):
|
||||
pass
|
||||
|
||||
def __getitem__(self, item):
|
||||
try:
|
||||
return self.entity[item]
|
||||
except KeyError:
|
||||
mdx_url = "%s/entities/%s" % (self.url, quote_plus(item))
|
||||
response = self.http.send(mdx_url)
|
||||
if response.status_code == 200:
|
||||
node_name = self.node_name \
|
||||
or "%s:%s" % (md.EntitiesDescriptor.c_namespace,
|
||||
md.EntitiesDescriptor.c_tag)
|
||||
|
||||
_txt = response.text.encode("utf-8")
|
||||
if self.cert:
|
||||
if self.security.verify_signature(_txt,
|
||||
node_name=node_name,
|
||||
cert_file=self.cert):
|
||||
self.parse(_txt)
|
||||
return self.entity[item]
|
||||
else:
|
||||
self.parse(_txt)
|
||||
return self.entity[item]
|
||||
else:
|
||||
logger.info("Response status: %s" % response.status_code)
|
||||
raise KeyError
|
||||
|
||||
|
||||
class MetadataStore(object):
|
||||
def __init__(self, onts, attrc, config, ca_certs=None,
|
||||
check_validity=True,
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import datetime
|
||||
import re
|
||||
from saml2.httpbase import HTTPBase
|
||||
|
||||
from saml2.mdstore import MetadataStore
|
||||
from saml2.mdstore import MetadataStore, MetaDataMDX
|
||||
from saml2.mdstore import destinations
|
||||
from saml2.mdstore import name
|
||||
|
||||
@@ -223,5 +225,18 @@ def test_metadata_file():
|
||||
print len(mds.keys())
|
||||
assert len(mds.keys()) == 560
|
||||
|
||||
|
||||
def test_mdx():
|
||||
sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
|
||||
http = HTTPBase(verify=False, ca_bundle=None)
|
||||
|
||||
mdx = MetaDataMDX(ONTS.values(), ATTRCONV, "http://pyff-test.nordu.net",
|
||||
sec_config, None, http)
|
||||
foo = mdx.service("https://idp.umu.se/saml2/idp/metadata.php",
|
||||
"idpsso_descriptor", "single_sign_on_service")
|
||||
|
||||
assert len(foo) == 1
|
||||
assert foo.keys()[0] == BINDING_HTTP_REDIRECT
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_swami_1()
|
||||
test_mdx()
|
||||
|
||||
Reference in New Issue
Block a user