Skip to content
Snippets Groups Projects
Commit f694415e authored by lukasmatusiewicz's avatar lukasmatusiewicz
Browse files

Update PrivacyIDEA.php

parent 52f88d7f
No related branches found
No related tags found
No related merge requests found
...@@ -336,6 +336,7 @@ class PrivacyIDEA ...@@ -336,6 +336,7 @@ class PrivacyIDEA
return ""; return "";
} }
$params = array( $params = array(
"username" => $this->serviceAccountName, "username" => $this->serviceAccountName,
"password" => $this->serviceAccountPass "password" => $this->serviceAccountPass
...@@ -350,13 +351,48 @@ class PrivacyIDEA ...@@ -350,13 +351,48 @@ class PrivacyIDEA
if (!empty($response['result']['value'])) if (!empty($response['result']['value']))
{ {
return @$response['result']['value']['token'] ?: ""; // Ensure an admin account
if (!empty($response['result']['value']["token"]))
{
if ($this->findRecursive($response, "role") != 'admin')
{
$this->debugLog("Auth token was of a user without admin role.");
return "";
}
return $response['result']['value']["token"];
}
} }
$this->debugLog("/auth response did not contain the auth token."); $this->debugLog("/auth response did not contain the auth token.");
return ""; return "";
} }
/**
* Find key recursively in array.
*
* @param array $haystack The array which will be searched.
* @param string $needle Search string.
* @return mixed Result of key search.
*/
public function findRecursive(array $haystack, string $needle): mixed
{
assert(is_array($haystack));
assert(is_string($needle));
$iterator = new RecursiveArrayIterator($haystack);
$recursive = new RecursiveIteratorIterator(
$iterator,
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($recursive as $key => $value) {
if ($key === $needle) {
return $value;
}
}
return false;
}
/** /**
* Send requests to the endpoint with specified parameters and headers. * Send requests to the endpoint with specified parameters and headers.
* *
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment