Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/packages/security.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ security:
- Chamilo\CoreBundle\Security\Authenticator\Ldap\LdapAuthenticator

access_control:
- { path: ^/scim/v2, roles: PUBLIC_ACCESS }
- { path: ^/login/token/check, roles: PUBLIC_ACCESS }
- { path: ^/login, roles: PUBLIC_ACCESS }
- { path: ^/api/authentication_token, roles: PUBLIC_ACCESS }
2 changes: 2 additions & 0 deletions public/main/install/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@
'{{PACKAGER}}' => 'chamilo',
'{{DEFAULT_TEMPLATE}}' => 'default',
'{{ADMIN_CHAMILO_ANNOUNCEMENTS_DISABLE}}' => '0',
'{{SCIM_TOKEN}}' => bin2hex(random_bytes(64)),
];
error_log('Update env file');
updateEnvFile($distFile, $envFile, $params);
Expand Down Expand Up @@ -612,6 +613,7 @@
'{{PACKAGER}}' => 'chamilo',
'{{DEFAULT_TEMPLATE}}' => 'default',
'{{ADMIN_CHAMILO_ANNOUNCEMENTS_DISABLE}}' => '0',
'{{SCIM_TOKEN}}' => bin2hex(random_bytes(64)),
];

updateEnvFile($distFile, $envFile, $params);
Expand Down
35 changes: 35 additions & 0 deletions src/CoreBundle/Controller/Scim/AbstractScimController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

/* For licensing terms, see /license.txt */

declare(strict_types=1);

namespace Chamilo\CoreBundle\Controller\Scim;

use Chamilo\CoreBundle\Exception\ScimException;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;

use const JSON_ERROR_NONE;

abstract class AbstractScimController extends AbstractController
{
public const SCIM_CONTENT_TYPE = 'application/scim+json';

protected function getAndValidateJson(Request $request): array
{
$content = $request->getContent();

if (empty($content)) {
throw new ScimException('No content');
}

$data = json_decode($content, true);

if (JSON_ERROR_NONE !== json_last_error()) {
throw new ScimException('Invalid JSON: '.json_last_error_msg());
}

return $data;
}
}
76 changes: 76 additions & 0 deletions src/CoreBundle/Controller/Scim/ResourceTypeController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

/* For licensing terms, see /license.txt */

declare(strict_types=1);

namespace Chamilo\CoreBundle\Controller\Scim;

use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

#[Route('/scim/v2/ResourceTypes')]
class ResourceTypeController extends AbstractScimController
{
#[Route('', name: 'scim_resource_types', methods: ['GET'])]
public function listResourceTypes(): JsonResponse
{
$resourceTypes = [
'schemas' => ['urn:ietf:params:scim:api:messages:2.0:ListResponse'],
'totalResults' => 1,
'itemsPerPage' => 1,
'startIndex' => 1,
'Resources' => [
$this->getUserResource(),
],
];

return new JsonResponse(
$resourceTypes,
Response::HTTP_OK,
['Content-Type' => self::SCIM_CONTENT_TYPE]
);
}

#[Route('/{resourceType}', name: 'scim_resource_type', methods: ['GET'])]
public function resourceType(string $resourceType): JsonResponse
{
if ('User' !== $resourceType) {
throw $this->createNotFoundException('Resource Type not supported');
}

$userResourceType = $this->getUserResource();

return new JsonResponse(
$userResourceType,
Response::HTTP_OK,
['Content-Type' => self::SCIM_CONTENT_TYPE]
);
}

private function getUserResource(): array
{
$location = $this->generateUrl(
'scim_resource_types',
['resourceType' => 'User'],
UrlGeneratorInterface::ABSOLUTE_URL
);

return [
'schemas' => [
'urn:ietf:params:scim:schemas:core:2.0:ResourceType',
],
'id' => 'User',
'name' => 'User',
'endpoint' => '/Users',
'description' => 'User Account',
'schema' => 'urn:ietf:params:scim:schemas:core:2.0:User',
'meta' => [
'resourceType' => 'ResourceType',
'location' => $location,
],
];
}
}
Loading