-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* [REMOVE TMP DEPENDENCY] IBX-8482: Fixed lack of JWT stateless calls recognition * removed dev dependency
- Loading branch information
1 parent
a8e980c
commit ddbe28c
Showing
7 changed files
with
92 additions
and
34 deletions.
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
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,33 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Rest\Security; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\RequestMatcher; | ||
|
||
/** | ||
* @internal | ||
* | ||
* This class is mandatory for JWT REST calls recognition. It's used within security.firewalls.ibexa_jwt_rest.request_matcher configuration key. | ||
*/ | ||
final class JWTTokenCreationRESTRequestMatcher extends RequestMatcher | ||
{ | ||
public function matches(Request $request): bool | ||
{ | ||
if ($request->attributes->get('is_rest_request', false) !== true) { | ||
return false; | ||
} | ||
|
||
if ($request->attributes->get('_route') === 'ibexa.rest.create_token') { | ||
return parent::matches($request); | ||
} | ||
|
||
return false; | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
tests/contracts/Security/JWTTokenCreationRESTRequestMatcherTest.php
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,55 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Tests\Contracts\Rest\Security; | ||
|
||
use Ibexa\Rest\Security\JWTTokenCreationRESTRequestMatcher; | ||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\HttpFoundation\Request; | ||
|
||
final class JWTTokenCreationRESTRequestMatcherTest extends TestCase | ||
{ | ||
public function testDoesNotMatchNonRestRequests(): void | ||
{ | ||
$matcher = new JWTTokenCreationRESTRequestMatcher(); | ||
|
||
self::assertFalse($matcher->matches(new Request())); | ||
} | ||
|
||
public function testDoesNotMatchRestRequestsWithoutHeader(): void | ||
{ | ||
$matcher = new JWTTokenCreationRESTRequestMatcher(); | ||
|
||
$request = $this->createRequest([ | ||
'is_rest_request' => true, | ||
]); | ||
|
||
self::assertFalse($matcher->matches($request)); | ||
} | ||
|
||
public function testMatchesRestJwtCreationEndpoint(): void | ||
{ | ||
$matcher = new JWTTokenCreationRESTRequestMatcher(); | ||
|
||
$request = $this->createRequest([ | ||
'is_rest_request' => true, | ||
'_route' => 'ibexa.rest.create_token', | ||
]); | ||
|
||
self::assertTrue($matcher->matches($request)); | ||
} | ||
|
||
/** | ||
* @param array<string, mixed> $attributes | ||
* @param array<string, array<string>|string> $server | ||
*/ | ||
private function createRequest(array $attributes = [], array $server = []): Request | ||
{ | ||
return new Request([], [], $attributes, [], [], $server); | ||
} | ||
} |
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