Skip to content
Snippets Groups Projects
Commit 4c468456 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

auth-debug: use the new muxer to get a list of attributes

This now shows the same data the bundles fetch in the expressions.
parent ce8d8501
Branches
No related tags found
No related merge requests found
Pipeline #209184 passed
......@@ -23,15 +23,29 @@ class AuthorizationDataMuxer
private function loadUserAttributesFromAuthorizationProvider(?string $userIdentifier, AuthorizationDataProviderInterface $authorizationDataProvider): void
{
$userAttributes = [];
$userAttributes = $authorizationDataProvider->getUserAttributes($userIdentifier);
if ($userIdentifier !== null) {
$userAttributes = $authorizationDataProvider->getUserAttributes($userIdentifier);
foreach ($authorizationDataProvider->getAvailableAttributes() as $availableAttribute) {
if (array_key_exists($availableAttribute, $userAttributes)) {
$this->customAttributes[$availableAttribute] = $userAttributes[$availableAttribute];
}
}
}
foreach ($authorizationDataProvider->getAvailableAttributes() as $availableAttribute) {
$this->customAttributes[$availableAttribute] = $userAttributes[$availableAttribute] ?? null;
/**
* Returns an array of available attributes.
*
* @return string[]
*/
public function getAvailableAttributes(): array
{
$res = [];
foreach ($this->authorizationDataProviders as $authorizationDataProvider) {
$availableAttributes = $authorizationDataProvider->getAvailableAttributes();
$res = array_merge($res, $availableAttributes);
}
return $res;
}
/**
......
......@@ -37,32 +37,26 @@ class DebugCommand extends Command implements LoggerAwareInterface
protected function execute(InputInterface $input, OutputInterface $output): int
{
$username = $input->getArgument('username');
if ($username === null) {
// No username, list all providers
$output->writeln("<fg=blue;options=bold>Attributes available for all provider</>\n");
$providers = $this->provider->getAuthorizationDataProviders();
foreach ($providers as $provider) {
$output->writeln('<fg=green;options=bold>['.get_class($provider).']</>');
foreach ($provider->getAvailableAttributes() as $attr) {
$output->writeln($attr);
}
$output->writeln('');
}
// TODO: list all attributes
} else {
// get all available attributes for a user per provider
$output->writeln('<fg=blue;options=bold>Attributes for user "'.$username."\":</>\n");
$providers = $this->provider->getAuthorizationDataProviders();
foreach ($providers as $provider) {
$output->writeln('<fg=green;options=bold>['.get_class($provider).']</>');
foreach ($provider->getUserAttributes($username) as $attr => $value) {
$output->writeln($attr.'='.json_encode($value));
}
$output->writeln('');
}
// Fetch all attributes first (to get potential log spam first)
$providers = $this->provider->getAuthorizationDataProviders();
$mux = new AuthorizationDataMuxer($providers);
$attrs = $mux->getAvailableAttributes();
$all = [];
$default = new \stdClass();
sort($attrs, SORT_STRING | SORT_FLAG_CASE);
foreach ($attrs as $attr) {
$all[$attr] = $mux->getCustomAttribute($username, $attr, $default);
}
// TODO: list all attributes
// Now print them out
$output->writeln('<fg=blue;options=bold>[Authorization attributes]</>');
foreach ($all as $attr => $value) {
if ($value === $default) {
$output->writeln('<fg=green;options=bold>'.$attr.'</> = <fg=magenta;options=bold>\<N/A\></>');
} else {
$output->writeln('<fg=green;options=bold>'.$attr.'</> = '.json_encode($value));
}
}
return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment