Skip to content

Commit ebd0298

Browse files
committedJun 24, 2016
Statically store the SP metadata and refresh on config changes
1 parent 7c37d58 commit ebd0298

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed
 

‎auth.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -363,10 +363,18 @@ public function validate_form($form, &$err) {
363363
* @param object $config
364364
*/
365365
public function process_config($config) {
366+
$haschanged = false;
367+
366368
foreach ($this->defaults as $key => $value) {
367-
set_config($key, $config->$key, 'auth_saml2');
369+
if ($config->$key != $this->config->$key) {
370+
set_config($key, $config->$key, 'auth_saml2');
371+
$haschanged = true;
372+
}
368373
}
369-
return true;
374+
375+
if ($haschanged) {
376+
$file = $this->certdir . $this->spname . '.xml';
377+
@unlink($file);
370378
}
371379

372380
/**

‎locallib.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ function auth_saml2_get_sp_metadata() {
3535

3636
global $saml2auth, $CFG;
3737

38-
$auth = new SimpleSAML_Auth_Simple($saml2auth->spname);
39-
$config = SimpleSAML_Configuration::getInstance();
4038
$sourceId = $saml2auth->spname;
39+
40+
$file = $saml2auth->certdir . $saml2auth->spname . '.xml';
41+
if (file_exists($file)) {
42+
$xml = file_get_contents($file);
43+
return $xml;
44+
}
45+
46+
$auth = new SimpleSAML_Auth_Simple($sourceId);
47+
$config = SimpleSAML_Configuration::getInstance();
4148
$source = SimpleSAML_Auth_Source::getById($sourceId);
4249
if ($source === NULL) {
4350
throw new SimpleSAML_Error_NotFound('Could not find authentication source with id ' . $sourceId);
@@ -265,6 +272,9 @@ function auth_saml2_get_sp_metadata() {
265272
/* Sign the metadata if enabled. */
266273
$xml = SimpleSAML_Metadata_Signer::sign($xml, $spconfig->toArray(), 'SAML 2 SP');
267274

275+
// Store the file so it is exactly the same next time.
276+
file_put_contents($file, $xml);
277+
268278
return $xml;
269279
}
270280

‎regenerate.php

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@
5454
$saml2auth = new auth_plugin_saml2();
5555
$error = create_certificates($saml2auth, $dn, $numberofdays);
5656

57+
// Also refresh the SP metadata as well.
58+
$file = $saml2auth->certdir . $saml2auth->spname . '.xml';
59+
@unlink($file);
60+
5761
if (empty($error)) {
5862
redirect("$CFG->wwwroot/admin/auth_config.php?auth=saml2");
5963
}

0 commit comments

Comments
 (0)
Please sign in to comment.