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
No related branches found
No related tags found
No related merge requests found
Pipeline #209184 passed
...@@ -23,15 +23,29 @@ class AuthorizationDataMuxer ...@@ -23,15 +23,29 @@ class AuthorizationDataMuxer
private function loadUserAttributesFromAuthorizationProvider(?string $userIdentifier, AuthorizationDataProviderInterface $authorizationDataProvider): void private function loadUserAttributesFromAuthorizationProvider(?string $userIdentifier, AuthorizationDataProviderInterface $authorizationDataProvider): void
{ {
$userAttributes = [];
if ($userIdentifier !== null) {
$userAttributes = $authorizationDataProvider->getUserAttributes($userIdentifier); $userAttributes = $authorizationDataProvider->getUserAttributes($userIdentifier);
}
foreach ($authorizationDataProvider->getAvailableAttributes() as $availableAttribute) { foreach ($authorizationDataProvider->getAvailableAttributes() as $availableAttribute) {
$this->customAttributes[$availableAttribute] = $userAttributes[$availableAttribute] ?? null; if (array_key_exists($availableAttribute, $userAttributes)) {
$this->customAttributes[$availableAttribute] = $userAttributes[$availableAttribute];
}
}
} }
/**
* 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 ...@@ -37,32 +37,26 @@ class DebugCommand extends Command implements LoggerAwareInterface
protected function execute(InputInterface $input, OutputInterface $output): int protected function execute(InputInterface $input, OutputInterface $output): int
{ {
$username = $input->getArgument('username'); $username = $input->getArgument('username');
if ($username === null) {
// No username, list all providers // Fetch all attributes first (to get potential log spam first)
$output->writeln("<fg=blue;options=bold>Attributes available for all provider</>\n");
$providers = $this->provider->getAuthorizationDataProviders(); $providers = $this->provider->getAuthorizationDataProviders();
foreach ($providers as $provider) { $mux = new AuthorizationDataMuxer($providers);
$output->writeln('<fg=green;options=bold>['.get_class($provider).']</>'); $attrs = $mux->getAvailableAttributes();
foreach ($provider->getAvailableAttributes() as $attr) { $all = [];
$output->writeln($attr); $default = new \stdClass();
} sort($attrs, SORT_STRING | SORT_FLAG_CASE);
$output->writeln(''); 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 { } else {
// get all available attributes for a user per provider $output->writeln('<fg=green;options=bold>'.$attr.'</> = '.json_encode($value));
$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('');
}
// TODO: list all attributes
} }
return 0; return 0;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment