Skip to content

Commit 860e0ec

Browse files
authored
Merge pull request #40 from RRZE-Webteam/dev
Dev
2 parents 81368c4 + c5ceadf commit 860e0ec

File tree

3 files changed

+42
-37
lines changed

3 files changed

+42
-37
lines changed

includes/Authenticate.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,12 @@ public function authenticate($user, $userLogin)
160160
$userLogin = $userLogin ?: explode('@', $subjectId)[0];
161161

162162
$found = false;
163-
foreach (array_keys($identityProviders) as $idpName) {
164-
$idpName = sanitize_title($idpName);
165-
$domainScope = $this->options->domain_scope[$idpName] ?? '';
163+
foreach ($identityProviders as $idpKey => $idpName) {
164+
$idpKey = sanitize_title($idpKey);
165+
$idpName = sanitize_text_field($idpName);
166+
$domainScope = $this->options->domain_scope[$idpKey] ?? '';
166167
$domainScope = $domainScope ? '@' . $domainScope : $domainScope;
167-
if (sanitize_title($samlSpIdp) == $idpName) {
168+
if (sanitize_title($samlSpIdp) == $idpKey) {
168169
$found = true;
169170
$userLogin = $userLogin . $domainScope;
170171
break;

includes/SimpleSAML.php

+36-32
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function loaded()
5454
}
5555
$this->setAuthSimple()
5656
->setIdentityProviders();
57-
return true;
57+
return true;
5858
}
5959

6060
/**
@@ -94,40 +94,50 @@ public function getIdentityProviders()
9494
}
9595

9696
/**
97-
* Set the available Identity Providers list.
98-
* @return object This SimpleSAML object.
97+
* Get an array of available Identity Providers.
98+
* @return array array
9999
*/
100-
protected function setIdentityProviders()
100+
public function identityProviders()
101101
{
102-
if (!method_exists('\SimpleSAML\Configuration', 'getConfig')) {
103-
return $this;
104-
}
105-
106-
try {
107-
// Get the authsources file, which should contain the config.
108-
$authsource = \SimpleSAML\Configuration::getConfig('authsources.php');
109-
} catch (\Exception $e) {
110-
$error = new \WP_Error('simplesaml_configuration_error', $e->getMessage());
111-
$this->errorOnLoaded($error);
112-
return $this;
102+
// Initialize the metadata storage handler
103+
$metadataHandler = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
104+
105+
// Load all available metadata entities
106+
$entityList = $metadataHandler->getList();
107+
108+
// Array to store IdP metadata
109+
$idpMetadata = [];
110+
111+
foreach (array_keys($entityList) as $entityId) {
112+
try {
113+
// Fetch metadata for the entity from metarefresh cache
114+
$metadata = $metadataHandler->getMetaDataConfig($entityId, 'saml20-idp-remote');
115+
116+
// Store only IdP metadata
117+
if ($metadata !== null) {
118+
$idpMetadata[$entityId] = $metadata->toArray();
119+
}
120+
} catch (\Exception $e) {
121+
error_log("Error retrieving metadata for entity $entityId: " . $e->getMessage());
122+
}
113123
}
114124

115-
// Get just the specified authsource config values.
116-
$authsource = $authsource->toArray();
117-
$idp = $authsource[$this->options->simplesaml_auth_source]['idp'] ?? 'null';
125+
return $idpMetadata;
126+
}
118127

119-
$saml20IdpRemoteFile = dirname($this->simplesamlInclude, 2) . '/metadata/saml20-idp-remote.php';
120-
if (!file_exists($saml20IdpRemoteFile)) {
121-
return $this;
122-
}
123-
// Load $metadata array.
124-
require_once($saml20IdpRemoteFile);
128+
/**
129+
* Set the available Identity Providers list.
130+
* @return object This SimpleSAML object.
131+
*/
132+
protected function setIdentityProviders()
133+
{
134+
$idpMetadata = $this->identityProviders();
125135

126-
$metadata = $metadata ?? [];
127136
$locale = get_locale();
128137
$lang = explode('_', $locale)[0];
138+
129139
$idps = [];
130-
foreach ($metadata as $key => $value) {
140+
foreach ($idpMetadata as $key => $value) {
131141
if (isset($value['name'][$lang])) {
132142
$name = $value['name'][$lang];
133143
} elseif (isset($value['name']) && is_string($value['name'])) {
@@ -138,12 +148,6 @@ protected function setIdentityProviders()
138148
$idps[$key] = $name;
139149
}
140150

141-
if ($idp && isset($idps[$idp])) {
142-
$idps = [
143-
$idp => $idps[$idp]
144-
];
145-
}
146-
147151
$this->identityProviders = $idps;
148152
return $this;
149153
}

rrze-sso.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Plugin Name: RRZE SSO
55
Plugin URI: https://github.com/RRZE-Webteam/rrze-sso
6-
Version: 1.6.10
6+
Version: 1.6.11
77
Description: Single-Sign-On (SSO) SAML-Integrations-Plugin für WordPress.
88
Author: RRZE-Webteam
99
Author URI: https://blogs.fau.de/webworking/

0 commit comments

Comments
 (0)