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

IBX-8356: Reworked Ibexa\Core\MVC\Symfony\Security\Authentication\AuthenticatorInterface usages to comply with Symfony-based authentication #67

Merged
merged 6 commits into from
Jul 1, 2024
Merged
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
30 changes: 0 additions & 30 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -325,31 +325,6 @@ parameters:
count: 1
path: src/lib/Mapper/ContentImageAssetMapperStrategy.php

-
message: "#^Cannot access property \\$attributes on Symfony\\\\Component\\\\HttpFoundation\\\\Request\\|null\\.$#"
count: 2
path: src/lib/Mutation/Authentication.php

-
message: "#^Method Ibexa\\\\GraphQL\\\\Mutation\\\\Authentication\\:\\:createToken\\(\\) has parameter \\$args with no type specified\\.$#"
count: 1
path: src/lib/Mutation/Authentication.php

-
message: "#^Method Ibexa\\\\GraphQL\\\\Mutation\\\\Authentication\\:\\:createToken\\(\\) return type has no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Mutation/Authentication.php

-
message: "#^Parameter \\#1 \\$request of method Ibexa\\\\Core\\\\MVC\\\\Symfony\\\\Security\\\\Authentication\\\\AuthenticatorInterface\\:\\:authenticate\\(\\) expects Symfony\\\\Component\\\\HttpFoundation\\\\Request, Symfony\\\\Component\\\\HttpFoundation\\\\Request\\|null given\\.$#"
count: 1
path: src/lib/Mutation/Authentication.php

-
message: "#^Parameter \\#1 \\$wrappedUser of class Ibexa\\\\GraphQL\\\\Security\\\\JWTUser constructor expects Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface, Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\|null given\\.$#"
count: 1
path: src/lib/Mutation/Authentication.php

-
message: "#^Method Ibexa\\\\GraphQL\\\\Mutation\\\\InputHandler\\\\FieldType\\\\BinaryFile\\:\\:toFieldValue\\(\\) has parameter \\$input with no type specified\\.$#"
count: 1
Expand Down Expand Up @@ -2330,11 +2305,6 @@ parameters:
count: 1
path: src/lib/Schema/Worker.php

-
message: "#^Method Ibexa\\\\GraphQL\\\\Security\\\\NonAdminGraphQLRequestMatcher\\:\\:__construct\\(\\) has parameter \\$siteAccessGroups with no value type specified in iterable type array\\.$#"
count: 1
path: src/lib/Security/NonAdminGraphQLRequestMatcher.php

-
message: "#^Cannot cast object to string\\.$#"
count: 1
Expand Down
4 changes: 1 addition & 3 deletions src/bundle/Resources/config/services/resolvers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ services:
tags:
- { name: overblog_graphql.resolver, alias: "Thumbnail", method: "resolveThumbnail" }

Ibexa\GraphQL\Mutation\Authentication:
arguments:
$authenticator: '@?ibexa.rest.session_authenticator'
Ibexa\GraphQL\Mutation\AuthenticationMutation:
tags:
- { name: overblog_graphql.mutation, alias: "CreateToken", method: "createToken" }

Expand Down
76 changes: 0 additions & 76 deletions src/lib/Mutation/Authentication.php

This file was deleted.

64 changes: 64 additions & 0 deletions src/lib/Mutation/AuthenticationMutation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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\GraphQL\Mutation;

use Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException;
use Ibexa\Contracts\Core\Repository\UserService;
use Ibexa\Core\MVC\Symfony\Security\User;
use Lexik\Bundle\JWTAuthenticationBundle\Services\JWTTokenManagerInterface;
use Overblog\GraphQLBundle\Definition\Argument;

final readonly class AuthenticationMutation
{
public function __construct(
private JWTTokenManagerInterface $tokenManager,
private UserService $userService
) {
}

/**
* @return array<string, ?string>
*
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\NotFoundException
*/
public function createToken(Argument $args): array
{
if (!isset($args['username'], $args['password'])) {
return [
'message' => 'Missing username or password',
'token' => null,
];
}

try {
$user = $this->userService->loadUserByLogin($args['username']);
} catch (NotFoundException) {
return $this->getWrongCredentialsErrorMessage();
}

if (!$this->userService->checkUserCredentials($user, $args['password'])) {
return $this->getWrongCredentialsErrorMessage();
}

return [
'token' => $this->tokenManager->create(new User($user)),
];
}

/**
* @return array<string, ?string>
*/
private function getWrongCredentialsErrorMessage(): array
{
return [
'message' => 'Wrong username or password',
'token' => null,
];
}
}
56 changes: 0 additions & 56 deletions src/lib/Security/JWTUser.php

This file was deleted.

17 changes: 10 additions & 7 deletions src/lib/Security/NonAdminGraphQLRequestMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@
* Security request matcher that excludes admin+graphql requests.
* Needed because the admin uses GraphQL without a JWT.
*/
class NonAdminGraphQLRequestMatcher implements RequestMatcherInterface
final readonly class NonAdminGraphQLRequestMatcher implements RequestMatcherInterface
{
/** @var string[][] */
private $siteAccessGroups;

public function __construct(array $siteAccessGroups)
{
$this->siteAccessGroups = $siteAccessGroups;
/**
* @param string[][] $siteAccessGroups
*/
public function __construct(
private array $siteAccessGroups
) {
}

/**
* @throws \Ibexa\AdminUi\Exception\InvalidArgumentException
*/
public function matches(Request $request): bool
{
return
Expand Down
Loading