-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
548 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
resources: | ||
Pimcore\Bundle\StudioApiBundle\Dto\Token: | ||
operations: | ||
ApiPlatform\Metadata\Post: | ||
processor: Pimcore\Bundle\StudioApiBundle\State\Token\PostProcessor | ||
output: Pimcore\Bundle\StudioApiBundle\Dto\Token\Output | ||
uriTemplate: '/token/create' | ||
openapiContext: | ||
summary: 'Creates and returns a token' | ||
|
||
ApiPlatform\Metadata\Put: | ||
processor: Pimcore\Bundle\StudioApiBundle\State\Token\PutProcessor | ||
input: Pimcore\Bundle\StudioApiBundle\Dto\Token\Refresh | ||
output: Pimcore\Bundle\StudioApiBundle\Dto\Token\Output | ||
uriTemplate: '/token/refresh' | ||
openapiContext: | ||
summary: 'Refreshes an existing token' | ||
|
||
normalizationContext: | ||
groups: [ 'token:read' ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Pimcore\Bundle\StudioApiBundle\Dto\Token\Output: | ||
attributes: | ||
token: | ||
groups: ['token:read'] | ||
username: | ||
groups: [ 'token:read' ] | ||
lifetime: | ||
groups: ['token:read'] | ||
validUntil: | ||
groups: ['token:read'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under following license: | ||
* - Pimcore Commercial License (PCL) | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioApiBundle\Dto; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class Token | ||
{ | ||
public function __construct( | ||
private string $username, | ||
private string $password | ||
) | ||
{ | ||
} | ||
|
||
public function getUsername(): string | ||
{ | ||
return $this->username; | ||
} | ||
|
||
public function getPassword(): string | ||
{ | ||
return $this->password; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under following license: | ||
* - Pimcore Commercial License (PCL) | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioApiBundle\Dto\Token; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class Info | ||
{ | ||
public function __construct( | ||
private string $token, | ||
private string $tmpStoreId, | ||
private string $username | ||
) | ||
{ | ||
} | ||
|
||
public function getToken(): string | ||
{ | ||
return $this->token; | ||
} | ||
|
||
public function getTmpStoreId(): string | ||
{ | ||
return $this->tmpStoreId; | ||
} | ||
|
||
public function getUsername(): string | ||
{ | ||
return $this->username; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under following license: | ||
* - Pimcore Commercial License (PCL) | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioApiBundle\Dto\Token; | ||
|
||
use Carbon\Carbon; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class Output | ||
{ | ||
public function __construct( | ||
private string $token, | ||
private int $lifetime, | ||
private string $username | ||
) | ||
{ | ||
} | ||
|
||
public function getToken(): string | ||
{ | ||
return $this->token; | ||
} | ||
|
||
public function getUsername(): string | ||
{ | ||
return $this->username; | ||
} | ||
|
||
public function getLifetime(): int | ||
{ | ||
return $this->lifetime; | ||
} | ||
|
||
public function validUntil(): string | ||
{ | ||
return Carbon::now()->addSeconds($this->lifetime)->toDateTimeString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under following license: | ||
* - Pimcore Commercial License (PCL) | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioApiBundle\Dto\Token; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class Refresh | ||
{ | ||
public function __construct( | ||
private string $token | ||
) | ||
{ | ||
} | ||
|
||
public function getToken(): string | ||
{ | ||
return $this->token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under following license: | ||
* - Pimcore Commercial License (PCL) | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioApiBundle\Service; | ||
|
||
use Pimcore\Bundle\StaticResolverBundle\Models\Tool\TmpStoreResolverInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final readonly class SecurityService implements SecurityServiceInterface | ||
{ | ||
public function __construct(private TmpStoreResolverInterface $tmpStoreResolver) | ||
{ | ||
} | ||
|
||
public function isAllowed(string $token): bool | ||
{ | ||
$userIds = $this->tmpStoreResolver->getIdsByTag($token); | ||
if(count($userIds) === 0 || count($userIds) > 1) { | ||
return false; | ||
} | ||
$entry = $this->tmpStoreResolver->get($userIds[0]); | ||
return $entry && $entry->getTag() === $token; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
/** | ||
* Pimcore | ||
* | ||
* This source file is available under following license: | ||
* - Pimcore Commercial License (PCL) | ||
* | ||
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org) | ||
* @license http://www.pimcore.org/license PCL | ||
*/ | ||
|
||
namespace Pimcore\Bundle\StudioApiBundle\Service; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface SecurityServiceInterface | ||
{ | ||
public function isAllowed(string $token): bool; | ||
} |
Oops, something went wrong.