Skip to content

Commit 14506c0

Browse files
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
1 parent 59604b6 commit 14506c0

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

src/saml2/entity.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,40 @@ def __init__(self, entity_type, config=None, config_file="",
203203

204204
self.msg_cb = msg_cb
205205

206+
def reload_metadata(self, metadata_conf):
207+
"""
208+
Reload metadata configuration.
209+
210+
Load a new metadata configuration as defined by metadata_conf (by
211+
passing this to Config.load_metadata) and make this entity (as well as
212+
subordinate objects with own metadata reference) use the new metadata.
213+
214+
The structure of metadata_conf is the same as the 'metadata' entry in
215+
the configuration passed to saml2.Config.
216+
217+
param metadata_conf: Metadata configuration as passed to Config.load_metadata
218+
return: True if successfully reloaded
219+
"""
220+
logger.debug("Loading new metadata")
221+
try:
222+
new_metadata = self.config.load_metadata(metadata_conf)
223+
except Exception as ex:
224+
logger.error("Loading metadata failed", exc_info=ex)
225+
return False
226+
227+
logger.debug("Applying new metadata to main config")
228+
( self.metadata, self.sec.metadata, self.config.metadata ) = [new_metadata]*3
229+
for typ in ["aa", "idp", "sp", "pdp", "aq"]:
230+
policy = getattr(self.config, "_%s_policy" % typ, None)
231+
if policy and policy.metadata_store:
232+
logger.debug("Applying new metadata to %s policy", typ)
233+
policy.metadata_store = self.metadata
234+
235+
logger.debug("Applying new metadata source_id")
236+
self.sourceid = self.metadata.construct_source_id()
237+
238+
return True
239+
206240
def _issuer(self, entityid=None):
207241
""" Return an Issuer instance """
208242
if entityid:

0 commit comments

Comments
 (0)