You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * Find key recursivly in array (Adapted from GOsa core) * * @param array $haystack the array which will be searched * @param string $needle search string * @return mixed result of key search */publicfunctionfindRecursive($haystack, $needle): mixed
{
assert(is_array($haystack));
assert(is_string($needle));
$iterator = newRecursiveArrayIterator($haystack);
$recursive = newRecursiveIteratorIterator(
$iterator,
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($recursiveas$key => $value) {
if ($key === $needle) {
return$value;
}
}
returnfalse;
}
/** * This function was adapted from privacyidea-php-client. * This implementation checks if serviceAccount is an admin. * * Retrieves an auth token from the server using the service account. * An auth token is required for some requests to privacyIDEA. * * @return string the auth token or empty string if the response did not * contain a token or no service account is configured. * @throws PIBadRequestException if an error occurs during the request */publicfunctiongetAuthToken()
{
if (!$this->pi->serviceAccountAvailable()) {
$this->pi->errorLog("Cannot retrieve auth token without service account!");
return"";
}
$params = array(
"username" => $this->pi->serviceAccountName,
"password" => $this->pi->serviceAccountPass
);
if ($this->pi->serviceAccountRealm != null && $this->pi->serviceAccountRealm != "") {
$params["realm"] = $this->pi->serviceAccountRealm;
}
$response = json_decode($this->pi->sendRequest($params, array(''), 'POST', '/auth'), true);
if (isset($response['result']['value']['token']) && !empty($response['result']['value']['token'])) {
// Ensure we have an admin accountif ($this->findRecursive((array)$response, "role") != 'admin') {
$this->pi->debugLog("auth token was of a user without admin role.");
return"";
}
return$response['result']['value']["token"];
}
$this->pi->debugLog("/auth response did not contain a auth token.");
return"";
}
Check if the serviceAccount is of role admin. This fix/improvement comes from downstream.
https://github.com/gosa-project/gosa-plugins-privacyidea/
The text was updated successfully, but these errors were encountered: