summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Mencl <vladimir.mencl@reannz.co.nz>2021-06-11 10:53:30 +1200
committerVlad Mencl <vladimir.mencl@reannz.co.nz>2021-06-11 10:53:30 +1200
commit14506c065274cee44eb435338f291f6774cd635d (patch)
tree17244615d4b7eefaccca1db54abfe6ca95978d5f
parent59604b6980bc3cc2d7a1a2b5a3aed515e9b1df17 (diff)
downloadpysaml2-14506c065274cee44eb435338f291f6774cd635d.tar.gz
new: saml2.Entity: support reloading metadata
Support reloading metadata by adding a reload_metadata method to saml2.Entity. This method gets the metadata configuration in the same format as the 'metadata' entry in the configuration passed to saml2.Config. To keep metadata refreshed, this method needs to be periodically explicitly called. For a metadata refresh with the same configuration, the calling application should keep a copy of the original configuration to pass to this method. Resolves #808
-rw-r--r--src/saml2/entity.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/saml2/entity.py b/src/saml2/entity.py
index 1a07807c..44596272 100644
--- a/src/saml2/entity.py
+++ b/src/saml2/entity.py
@@ -203,6 +203,40 @@ class Entity(HTTPBase):
self.msg_cb = msg_cb
+ def reload_metadata(self, metadata_conf):
+ """
+ Reload metadata configuration.
+
+ Load a new metadata configuration as defined by metadata_conf (by
+ passing this to Config.load_metadata) and make this entity (as well as
+ subordinate objects with own metadata reference) use the new metadata.
+
+ The structure of metadata_conf is the same as the 'metadata' entry in
+ the configuration passed to saml2.Config.
+
+ param metadata_conf: Metadata configuration as passed to Config.load_metadata
+ return: True if successfully reloaded
+ """
+ logger.debug("Loading new metadata")
+ try:
+ new_metadata = self.config.load_metadata(metadata_conf)
+ except Exception as ex:
+ logger.error("Loading metadata failed", exc_info=ex)
+ return False
+
+ logger.debug("Applying new metadata to main config")
+ ( self.metadata, self.sec.metadata, self.config.metadata ) = [new_metadata]*3
+ for typ in ["aa", "idp", "sp", "pdp", "aq"]:
+ policy = getattr(self.config, "_%s_policy" % typ, None)
+ if policy and policy.metadata_store:
+ logger.debug("Applying new metadata to %s policy", typ)
+ policy.metadata_store = self.metadata
+
+ logger.debug("Applying new metadata source_id")
+ self.sourceid = self.metadata.construct_source_id()
+
+ return True
+
def _issuer(self, entityid=None):
""" Return an Issuer instance """
if entityid: