|
3 | 3 | import json
|
4 | 4 |
|
5 | 5 | from hashlib import sha1
|
| 6 | +from urllib import urlencode, quote_plus |
6 | 7 | from saml2.httpbase import HTTPBase
|
7 | 8 | from saml2.extension.idpdisc import BINDING_DISCO
|
8 | 9 | from saml2.extension.idpdisc import DiscoveryResponse
|
@@ -525,6 +526,51 @@ def load(self):
|
525 | 526 | self.entity[key] = item
|
526 | 527 |
|
527 | 528 |
|
| 529 | +class MetaDataMDX(MetaData): |
| 530 | + def __init__(self, onts, attrc, url, security, cert, http, **kwargs): |
| 531 | + """ |
| 532 | + :params onts: |
| 533 | + :params attrc: |
| 534 | + :params url: |
| 535 | + :params security: SecurityContext() |
| 536 | + :params cert: |
| 537 | + :params http: |
| 538 | + """ |
| 539 | + MetaData.__init__(self, onts, attrc, **kwargs) |
| 540 | + self.url = url |
| 541 | + self.security = security |
| 542 | + self.cert = cert |
| 543 | + self.http = http |
| 544 | + |
| 545 | + def load(self): |
| 546 | + pass |
| 547 | + |
| 548 | + def __getitem__(self, item): |
| 549 | + try: |
| 550 | + return self.entity[item] |
| 551 | + except KeyError: |
| 552 | + mdx_url = "%s/entities/%s" % (self.url, quote_plus(item)) |
| 553 | + response = self.http.send(mdx_url) |
| 554 | + if response.status_code == 200: |
| 555 | + node_name = self.node_name \ |
| 556 | + or "%s:%s" % (md.EntitiesDescriptor.c_namespace, |
| 557 | + md.EntitiesDescriptor.c_tag) |
| 558 | + |
| 559 | + _txt = response.text.encode("utf-8") |
| 560 | + if self.cert: |
| 561 | + if self.security.verify_signature(_txt, |
| 562 | + node_name=node_name, |
| 563 | + cert_file=self.cert): |
| 564 | + self.parse(_txt) |
| 565 | + return self.entity[item] |
| 566 | + else: |
| 567 | + self.parse(_txt) |
| 568 | + return self.entity[item] |
| 569 | + else: |
| 570 | + logger.info("Response status: %s" % response.status_code) |
| 571 | + raise KeyError |
| 572 | + |
| 573 | + |
528 | 574 | class MetadataStore(object):
|
529 | 575 | def __init__(self, onts, attrc, config, ca_certs=None,
|
530 | 576 | check_validity=True,
|
|
0 commit comments