From 14506c065274cee44eb435338f291f6774cd635d Mon Sep 17 00:00:00 2001 From: Vlad Mencl Date: Fri, 11 Jun 2021 10:53:30 +1200 Subject: 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 --- src/saml2/entity.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) 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: -- cgit v1.2.1