|
6 | 6 |
|
7 | 7 | use SimpleSAML\Module\oidc\Admin\Authorization; |
8 | 8 | use SimpleSAML\Module\oidc\Codebooks\RoutesEnum; |
| 9 | +use SimpleSAML\Module\oidc\Entities\Interfaces\ClientEntityInterface; |
| 10 | +use SimpleSAML\Module\oidc\Exceptions\OidcException; |
9 | 11 | use SimpleSAML\Module\oidc\Factories\TemplateFactory; |
| 12 | +use SimpleSAML\Module\oidc\Repositories\AllowedOriginRepository; |
| 13 | +use SimpleSAML\Module\oidc\Repositories\ClientRepository; |
| 14 | +use SimpleSAML\Module\oidc\Services\AuthContextService; |
| 15 | +use Symfony\Component\HttpFoundation\Request; |
10 | 16 | use Symfony\Component\HttpFoundation\Response; |
11 | 17 |
|
12 | 18 | class ClientController |
13 | 19 | { |
14 | 20 | public function __construct( |
15 | 21 | protected readonly TemplateFactory $templateFactory, |
16 | 22 | protected readonly Authorization $authorization, |
| 23 | + protected readonly ClientRepository $clientRepository, |
| 24 | + protected readonly AllowedOriginRepository $allowedOriginRepository, |
17 | 25 | ) { |
18 | | - $this->authorization->requireSspAdmin(true); |
| 26 | + $this->authorization->requireAdminOrUserWithPermission(AuthContextService::PERM_CLIENT); |
19 | 27 | } |
20 | | - public function index(): Response |
| 28 | + |
| 29 | + /** |
| 30 | + * @throws \SimpleSAML\Module\oidc\Server\Exceptions\OidcServerException |
| 31 | + * @throws \JsonException |
| 32 | + * @throws \SimpleSAML\Module\oidc\Exceptions\OidcException |
| 33 | + */ |
| 34 | + protected function getClientFromRequest(Request $request): ClientEntityInterface |
21 | 35 | { |
| 36 | + ($clientId = $request->query->getString('client_id')) |
| 37 | + || throw new OidcException('Client ID not provided.'); |
| 38 | + |
| 39 | + $authedUserId = $this->authorization->isAdmin() ? null : $this->authorization->getUserId(); |
| 40 | + |
| 41 | + return $this->clientRepository->findById($clientId, $authedUserId) ?? |
| 42 | + throw new OidcException('Client not found.'); |
| 43 | + } |
| 44 | + |
| 45 | + public function index(Request $request): Response |
| 46 | + { |
| 47 | + $page = $request->query->getInt('page', 1); |
| 48 | + $query = $request->query->getString('q', ''); |
| 49 | + $authedUserId = $this->authorization->isAdmin() ? null : $this->authorization->getUserId(); |
| 50 | + |
| 51 | + $pagination = $this->clientRepository->findPaginated($page, $query, $authedUserId); |
| 52 | + |
| 53 | + |
22 | 54 | return $this->templateFactory->build( |
23 | 55 | 'oidc:clients.twig', |
24 | 56 | [ |
25 | | - // |
| 57 | + 'clients' => $pagination['items'], |
| 58 | + 'numPages' => $pagination['numPages'], |
| 59 | + 'currentPage' => $pagination['currentPage'], |
| 60 | + 'query' => $query, |
| 61 | + ], |
| 62 | + RoutesEnum::AdminClients->value, |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + /** |
| 67 | + * @throws \SimpleSAML\Module\oidc\Exceptions\OidcException |
| 68 | + */ |
| 69 | + public function show(Request $request): Response |
| 70 | + { |
| 71 | + $client = $this->getClientFromRequest($request); |
| 72 | + $allowedOrigins = $this->allowedOriginRepository->get($client->getIdentifier()); |
| 73 | + |
| 74 | + // TODO mivanci rename *-ssp.twig templates after removing old ones. |
| 75 | + return $this->templateFactory->build( |
| 76 | + 'oidc:clients/show-ssp.twig', |
| 77 | + [ |
| 78 | + 'client' => $client, |
| 79 | + 'allowedOrigins' => $allowedOrigins, |
26 | 80 | ], |
27 | 81 | RoutesEnum::AdminClients->value, |
28 | 82 | ); |
|
0 commit comments