Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Task] Update schema require #95

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
49f27b2
Initial refactor to session auth.
martineiber Jun 5, 2024
cc31e97
Merge branch '1.x' into 110-auth-to-session
martineiber Jun 5, 2024
ffab95a
Apply php-cs-fixer changes
martineiber Jun 5, 2024
2e22276
Refactor path checker for the scan path on open api.
martineiber Jun 5, 2024
2afc7a4
Merge remote-tracking branch 'origin/110-auth-to-session' into 110-au…
martineiber Jun 5, 2024
13dd544
Apply php-cs-fixer changes
martineiber Jun 5, 2024
b6f30b9
Remove Security Schema.
martineiber Jun 5, 2024
d5676d8
use RuntimeException.
martineiber Jun 5, 2024
defebbf
Fix to long line.
martineiber Jun 5, 2024
2f20b1f
Remove SECURITY_SCHEME
martineiber Jun 5, 2024
412d054
Adapt SecurityServiceTest.
martineiber Jun 6, 2024
cdce286
Apply php-cs-fixer changes
martineiber Jun 6, 2024
c4f0752
Add installation Guide for firewall to docs.
martineiber Jun 6, 2024
0051993
Fix Exception Handling.
martineiber Jun 6, 2024
372bfac
Apply php-cs-fixer changes
martineiber Jun 6, 2024
befb378
Use named Routing.
martineiber Jun 6, 2024
172e4b5
Rename to EventSubscriber
martineiber Jun 6, 2024
a0f7a94
Switch to empty response on logout.
martineiber Jun 6, 2024
54d323e
Add DefaultResponses to login.
martineiber Jun 6, 2024
c4494f9
Add throws block.
martineiber Jun 6, 2024
95420e3
Update Login Schema.
martineiber Jun 6, 2024
93f36e6
Refactor SecurityService.
martineiber Jun 6, 2024
ac536be
Add required to schema. Small clean up.
martineiber Jun 6, 2024
d269457
Apply php-cs-fixer changes
martineiber Jun 6, 2024
0dab2ff
Update Readme.
martineiber Jun 6, 2024
2af49c5
Remove unused Property
martineiber Jun 6, 2024
fa0357a
Update schemas
mattamon Jun 6, 2024
3102b88
Update asset
mattamon Jun 6, 2024
c761043
update other schemas
lukmzig Jun 7, 2024
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
5 changes: 3 additions & 2 deletions config/authorization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ services:
tags: [ 'controller.service_arguments' ]


Pimcore\Bundle\StudioBackendBundle\Authorization\Service\TokenServiceInterface:
class: Pimcore\Bundle\StudioBackendBundle\Authorization\Service\TokenService
Pimcore\Bundle\StudioBackendBundle\Authorization\EventSubscriber\LogoutSubscriber:
tags:
- { name: 'kernel.event_subscriber', dispatcher: 'security.event_dispatcher.pimcore_studio' }
4 changes: 4 additions & 0 deletions config/pimcore/config.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
imports:
- { resource: security.yaml }
- { resource: firewall.yaml }

pimcore:
translations:
domains:
Expand Down
14 changes: 14 additions & 0 deletions config/pimcore/firewall.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
pimcore_studio_backend:
security_firewall:
pattern: ^/studio/api(/.*)?$
user_checker: Pimcore\Security\User\UserChecker
context: pimcore_admin
provider: pimcore_studio_backend
stateless: false
login_throttling:
max_attempts: 3
interval: '5 minutes'
logout:
path: pimcore_studio_api_logout
json_login:
check_path: pimcore_studio_api_login
4 changes: 4 additions & 0 deletions config/pimcore/security.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
security:
providers:
pimcore_studio_backend:
id: Pimcore\Security\User\UserProvider
15 changes: 14 additions & 1 deletion doc/01_Installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,17 @@ bin/console pimcore:bundle:install PimcoreStudioBackendBundle
## Setting up generic data index
Pimcore Studio Backend also requires the installation and setup of the generic data index.
The bundle is required by default and also automatically enabled in the bundles.
To install the generic data index refer to [Generic-Data-Index](https://github.com/pimcore/generic-data-index-bundle?tab=readme-ov-file)
To install the generic data index refer to [Generic-Data-Index](https://github.com/pimcore/generic-data-index-bundle?tab=readme-ov-file)

## Enable Firewall settings

To enable the firewall settings, add the following configuration to your `config/packages/security.yaml` file:

```yaml
security:
firewalls:
pimcore_studio: '%pimcore_studio_backend.firewall_settings%'
access_control:
- { path: ^/studio/api/(docs|docs.json|translations)$, roles: PUBLIC_ACCESS }
- { path: ^/studio, roles: ROLE_PIMCORE_USER }
```
1 change: 1 addition & 0 deletions src/Asset/Attributes/Request/UpdateAssetRequestBody.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function __construct()
parent::__construct(
required: true,
content: new JsonContent(
required: ['data'],
properties: [
new Property('data',
properties: [
Expand Down
1 change: 0 additions & 1 deletion src/Asset/Controller/CollectionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ public function __construct(
operationId: 'getAssets',
description: 'Get paginated assets',
summary: 'Get all assets',
security: self::SECURITY_SCHEME,
tags: [Tags::Assets->name]
)]
#[PageParameter]
Expand Down
1 change: 0 additions & 1 deletion src/Asset/Controller/CustomSettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public function __construct(
operationId: 'getAssetCustomSettingsById',
description: 'Get custom settings of an asset by its id by path parameter',
summary: 'Get custom settings of an asset by id',
security: self::SECURITY_SCHEME,
tags: [Tags::Assets->name]
)]
#[IdParameter(type: 'asset')]
Expand Down
1 change: 0 additions & 1 deletion src/Asset/Controller/Data/TextController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public function __construct(
path: self::API_PATH . '/assets/{id}/text',
operationId: 'getAssetDataTextById',
summary: 'Get asset data in text UTF8 representation by id',
security: self::SECURITY_SCHEME,
tags: [Tags::Assets->name]
)]
#[IdParameter(type: 'asset')]
Expand Down
1 change: 0 additions & 1 deletion src/Asset/Controller/GetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function __construct(
operationId: 'getAssetById',
description: 'Get assets by id by path parameter',
summary: 'Get assets by id',
security: self::SECURITY_SCHEME,
tags: [Tags::Assets->name]
)]
#[IdParameter(type: 'asset')]
Expand Down
1 change: 0 additions & 1 deletion src/Asset/Controller/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ public function __construct(
operationId: 'updateAssetById',
description: 'Update assets by id',
summary: 'Update asset',
security: self::SECURITY_SCHEME,
tags: [Tags::Assets->name]
)]
#[IdParameter(type: 'asset')]
Expand Down
10 changes: 10 additions & 0 deletions src/Asset/Schema/Asset.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
*/
#[Schema(
title: 'Asset',
required: [
'iconName',
'hasChildren',
'type',
'filename',
'mimeType',
'metaData',
'hasWorkflowWithPermissions',
'fullPath'
],
type: 'object'
)]
class Asset extends Element implements AdditionalAttributesInterface
Expand Down
1 change: 1 addition & 0 deletions src/Asset/Schema/CustomSettings/FixedCustomSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
#[Schema(
title: 'FixedCustomSettings',
required: ['embeddedMetaData', 'embeddedMetaDataExtracted'],
type: 'object'
)]
final readonly class FixedCustomSettings
Expand Down
4 changes: 4 additions & 0 deletions src/Asset/Schema/Type/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#[Schema(
title: 'Document',
required: [
'pageCount',
'imageThumbnailPath'
],
type: 'object'
)]
class Document extends Asset
Expand Down
8 changes: 8 additions & 0 deletions src/Asset/Schema/Type/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@

#[Schema(
title: 'Image',
required: [
'format',
'width',
'height',
'isVectorGraphic',
'isAnimated',
'imageThumbnailPath'
],
type: 'object'
)]
final class Image extends Asset
Expand Down
4 changes: 4 additions & 0 deletions src/Asset/Schema/Type/Image/FocalPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
*/
#[Schema(
title: 'FocalPoint',
required: [
'x',
'y'
],
type: 'object'
)]
final readonly class FocalPoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,25 @@
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Authorization\Attributes\Request;
namespace Pimcore\Bundle\StudioBackendBundle\Authorization\Attributes\Response;

use Attribute;
use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\RequestBody;
use Pimcore\Bundle\StudioBackendBundle\Authorization\Schema\Refresh;
use OpenApi\Attributes\Response;
use Pimcore\Bundle\StudioBackendBundle\Authorization\Schema\InvalidCredentials;

/**
* @internal
*/
#[Attribute(Attribute::TARGET_METHOD)]
final class TokenRequestBody extends RequestBody
final class InvalidCredentialsResponse extends Response
{
public function __construct()
{
parent::__construct(
required: true,
content: new JsonContent(ref: Refresh::class)
response: 401,
description: 'Invalid credentials Response',
content: new JsonContent(ref: InvalidCredentials::class)
);
}
}
111 changes: 0 additions & 111 deletions src/Authorization/Controller/AuthorizationController.php

This file was deleted.

59 changes: 59 additions & 0 deletions src/Authorization/Controller/LoginController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioBackendBundle\Authorization\Controller;

use OpenApi\Attributes\JsonContent;
use OpenApi\Attributes\Post;
use Pimcore\Bundle\StudioBackendBundle\Authorization\Attributes\Request\CredentialsRequestBody;
use Pimcore\Bundle\StudioBackendBundle\Authorization\Attributes\Response\InvalidCredentialsResponse;
use Pimcore\Bundle\StudioBackendBundle\Authorization\Schema\LoginSuccess;
use Pimcore\Bundle\StudioBackendBundle\Controller\AbstractApiController;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\DefaultResponses;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Attributes\Response\SuccessResponse;
use Pimcore\Bundle\StudioBackendBundle\OpenApi\Config\Tags;
use Pimcore\Security\User\User;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\CurrentUser;

/**
* @internal
*/
final class LoginController extends AbstractApiController
{
#[Route('/login', name: 'pimcore_studio_api_login', methods: ['POST'])]
#[Post(
path: self::API_PATH . '/login',
operationId: 'login',
summary: 'Login with user credentials and get access token',
tags: [Tags::Authorization->name]
)]
#[CredentialsRequestBody]
#[SuccessResponse(
description: 'Login successful',
content: new JsonContent(ref: LoginSuccess::class)
)]
#[InvalidCredentialsResponse]
#[DefaultResponses]
public function login(#[CurrentUser] User $user): JsonResponse
{
return $this->jsonResponse([
'username' => $user->getUserIdentifier(),
'roles' => $user->getRoles(),
]);
}
}
Loading
Loading