Skip to content

Commit

Permalink
PS-591 add admin role per service
Browse files Browse the repository at this point in the history
  • Loading branch information
4rthem committed Dec 11, 2023
1 parent 4c3ed07 commit 22bed63
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public function configure(OutputInterface $output): void
{
$this->configureRealm();

foreach ($this->symfonyApplications as $app) {
$this->keycloakManager->createRole($app.'-admin', sprintf('Admin access for %s', ucwords($app)));
}

foreach ([
KeycloakInterface::ROLE_ADMIN => 'Can do anything',
KeycloakInterface::ROLE_TECH => 'Access to Dev/Ops Operations',
Expand Down
3 changes: 2 additions & 1 deletion lib/php/auth-bundle/Resources/config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ services:
Alchemy\AuthBundle\Security\JwtValidator: ~
Alchemy\AuthBundle\Security\JwtValidatorInterface: '@Alchemy\AuthBundle\Security\JwtValidator'
Alchemy\AuthBundle\Security\OAuthAuthorizationAuthenticator: ~
Alchemy\AuthBundle\Security\RoleMapper: ~
Alchemy\AuthBundle\Security\RoleMapper:
$appName: '%alchemy_core.app_name%'

Alchemy\AuthBundle\Controller\OAuthProxyController:
public: true
Expand Down
11 changes: 8 additions & 3 deletions lib/php/auth-bundle/Security/RoleMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@
final readonly class RoleMapper
{
public function __construct(
private string $appName,
private array $mapping = [
'admin' => 'ROLE_ADMIN',
]
],
)
{
}

public function getRoles(array $idpRoles): array
{
return array_filter(array_map(function (string $role): ?string {
return array_values(array_unique(array_filter(array_map(function (string $role): ?string {
if ($role === sprintf('%s-admin', $this->appName)) {
return 'ROLE_ADMIN';
}

return $this->mapping[$role] ?? null;
}, $idpRoles));
}, $idpRoles))));
}
}

0 comments on commit 22bed63

Please sign in to comment.