Почему я получаю сообщение об ошибке «Класс не существует» после входа в систему с помощью JWT - PullRequest
0 голосов
/ 14 мая 2019

Я настроил FOSUserBundle и LexikJWTAuthenticationBundle в Symfony4. Ранее я делал это успешно в Symfony 3 и ниже, но это впервые в Symfony4, и я получаю «Учетная запись класса« не существует »» из файла «vendor / doctrine / persistence / lib / Doctrine / Common /» Persistence / Mapping / MappingException.php "после входа в систему через кнопку NelmioApiDoc> Authorize и попытки получить информацию. Исключение уже было сгенерировано перед кодом в моем контроллере. Трассировка стека говорит мне, что происходит ошибка, когда пользовательский объект пытается прочитать обработчик аутентификации.

Я уже пробовал:

php bin/console doctrine:mapping:info

Результат:

Found 4 mapped entities:

 [OK]   App\Entity\AccountRefreshToken
 [OK]   App\Entity\Account
 [OK]   FOS\UserBundle\Model\Group
 [OK]   FOS\UserBundle\Model\User

Проверка моих конфигов: doctrine.yaml:

parameters:
    # Adds a fallback DATABASE_URL if the env var is not set.
    # This allows you to run cache:warmup even if your
    # environment variables are not available yet.
    # You should not need to change this value.
    env(DATABASE_URL): ''

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4
        default_table_options:
            charset: utf8mb4
            collate: utf8mb4_unicode_ci

        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: true
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

fos_user.yaml:

fos_user:
    db_driver: orm # other valid values are 'mongodb' and 'couchdb'
    firewall_name: main
    user_class: App\Entity\Account
    from_email:
        address: "iamanemail@address.ext"
        sender_name: "iamanemail@address.ext"

Account.php:

<?php


namespace App\Entity;


use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\User;
use Scheb\TwoFactorBundle\Model\Google\TwoFactorInterface;


/**
 * @ORM\Entity
 * @ORM\Table(name="account")
 * @ORM\HasLifecycleCallbacks
 */
class Account extends User implements TwoFactorInterface
{
    ...
}

composer.json

{
   "required": {
       "php": "^7.1.3",
        "ext-json": "*",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "friendsofsymfony/rest-bundle": "^2.5",
        "friendsofsymfony/user-bundle": "~2.0",
        "jms/serializer-bundle": "^3.3",
        "lexik/jwt-authentication-bundle": "^2.6",
        "monolog/monolog": "^2.0@dev",
        "nelmio/api-doc-bundle": "^3.4",
        "nelmio/cors-bundle": "^1.5",
        "scheb/two-factor-bundle": "^4.1",
        "sensio/framework-extra-bundle": "^5.3",
        "symfony/asset": "4.2.*",
        "symfony/console": "4.2.*",
        "symfony/flex": "^1.1",
        "symfony/framework-bundle": "4.2.*",
        "symfony/orm-pack": "^1.0",
        "symfony/swiftmailer-bundle": "^3.2",
        "symfony/translation": "4.2.*",
        "symfony/yaml": "4.2.*"
   }
   ...
   "autoload": {
        "psr-4": {
            "App\\": "src/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "App\\Tests\\": "tests/"
        }
    },
    ...
}

Я ожидал увидеть ответ вместо исключения сопоставления.

StackTrace:

#0 /vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php(24): Doctrine\\Common\\Persistence\\Mapping\\MappingException::nonExistingClass('Account')\n#1 /vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(250): Doctrine\\Common\\Persistence\\Mapping\\RuntimeReflectionService->getParentClasses('Account')\n#2 /vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(283): Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->getParentClasses('Account')\n#3 /vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php(78): Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->loadMetadata('Account')\n#4 /vendor/doctrine/persistence/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php(183): Doctrine\\ORM\\Mapping\\ClassMetadataFactory->loadMetadata('Account')\n#5 /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(283): Doctrine\\Common\\Persistence\\Mapping\\AbstractClassMetadataFactory->getMetadataFor('Account')\n#6 /vendor/doctrine/doctrine-bundle/Repository/ContainerRepositoryFactory.php(45): Doctrine\\ORM\\EntityManager->getClassMetadata('Account')\n#7 /vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php(713): Doctrine\\Bundle\\DoctrineBundle\\Repository\\ContainerRepositoryFactory->getRepository(Object(Doctrine\\ORM\\EntityManager), 'Account')\n#8 /vendor/friendsofsymfony/user-bundle/Doctrine/UserManager.php(114): Doctrine\\ORM\\EntityManager->getRepository('Account')\n#9 /vendor/friendsofsymfony/user-bundle/Doctrine/UserManager.php(76): FOS\\UserBundle\\Doctrine\\UserManager->getRepository()\n#10 /vendor/friendsofsymfony/user-bundle/Model/UserManager.php(58): FOS\\UserBundle\\Doctrine\\UserManager->findUserBy(Array)\n#11 /vendor/friendsofsymfony/user-bundle/Security/UserProvider.php(93): FOS\\UserBundle\\Model\\UserManager->findUserByUsername('admin')\n#12 /vendor/friendsofsymfony/user-bundle/Security/UserProvider.php(43): FOS\\UserBundle\\Security\\UserProvider->findUser('admin')\n#13 /vendor/lexik/jwt-authentication-bundle/Security/Guard/JWTTokenAuthenticator.php(288): FOS\\UserBundle\\Security\\UserProvider->loadUserByUsername('admin')\n#14 /vendor/lexik/jwt-authentication-bundle/Security/Guard/JWTTokenAuthenticator.php(156): Lexik\\Bundle\\JWTAuthenticationBundle\\Security\\Guard\\JWTTokenAuthenticator->loadUser(Object(FOS\\UserBundle\\Security\\UserProvider), Array, 'admin')\n#15 /vendor/symfony/security-guard/Provider/GuardAuthenticationProvider.php(102): Lexik\\Bundle\\JWTAuthenticationBundle\\Security\\Guard\\JWTTokenAuthenticator->getUser(Object(Lexik\\Bundle\\JWTAuthenticationBundle\\Security\\Authentication\\Token\\PreAuthenticationJWTUserToken), Object(FOS\\UserBundle\\Security\\UserProvider))\n#16 /vendor/symfony/security-guard/Provider/GuardAuthenticationProvider.php(96): Symfony\\Component\\Security\\Guard\\Provider\\GuardAuthenticationProvider->authenticateViaGuard(Object(Lexik\\Bundle\\JWTAuthenticationBundle\\Security\\Guard\\JWTTokenAuthenticator), Object(Symfony\\Component\\Security\\Guard\\Token\\PreAuthenticationGuardToken))\n#17 /vendor/scheb/two-factor-bundle/Security/Authentication/Provider/AuthenticationProviderDecorator.php(65): Symfony\\Component\\Security\\Guard\\Provider\\GuardAuthenticationProvider->authenticate(Object(Symfony\\Component\\Security\\Guard\\Token\\PreAuthenticationGuardToken))\n#18 /vendor/symfony/security-core/Authentication/AuthenticationProviderManager.php(76): Scheb\\TwoFactorBundle\\Security\\Authentication\\Provider\\AuthenticationProviderDecorator->authenticate(Object(Symfony\\Component\\Security\\Guard\\Token\\PreAuthenticationGuardToken))\n#19 /vendor/symfony/security-guard/Firewall/GuardAuthenticationListener.php(130): Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationProviderManager->authenticate(Object(Symfony\\Component\\Security\\Guard\\Token\\PreAuthenticationGuardToken))\n#20 /vendor/symfony/security-guard/Firewall/GuardAuthenticationListener.php(82): Symfony\\Component\\Security\\Guard\\Firewall\\GuardAuthenticationListener->executeGuardAuthenticator('api_0', Object(Lexik\\Bundle\\JWTAuthenticationBundle\\Security\\Guard\\JWTTokenAuthenticator), Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent))\n#21 /vendor/symfony/security-bundle/Debug/WrappedListener.php(46): Symfony\\Component\\Security\\Guard\\Firewall\\GuardAuthenticationListener->handle(Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent))\n#22 /vendor/symfony/security-bundle/Debug/TraceableFirewallListener.php(35): Symfony\\Bundle\\SecurityBundle\\Debug\\WrappedListener->handle(Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent))\n#23 /vendor/symfony/security-http/Firewall.php(90): Symfony\\Bundle\\SecurityBundle\\Debug\\TraceableFirewallListener->handleRequest(Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent), Object(Generator))\n#24 /vendor/symfony/security-bundle/EventListener/FirewallListener.php(48): Symfony\\Component\\Security\\Http\\Firewall->onKernelRequest(Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent))\n#25 /vendor/symfony/event-dispatcher/Debug/WrappedListener.php(115): Symfony\\Bundle\\SecurityBundle\\EventListener\\FirewallListener->onKernelRequest(Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent), 'kernel.request', Object(Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher))\n#26 /vendor/symfony/event-dispatcher/EventDispatcher.php(212): Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener->__invoke(Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent), 'kernel.request', Object(Symfony\\Component\\HttpKernel\\Debug\\TraceableEventDispatcher))\n#27 /vendor/symfony/event-dispatcher/EventDispatcher.php(44): Symfony\\Component\\EventDispatcher\\EventDispatcher->doDispatch(Array, 'kernel.request', Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent))\n#28 /vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php(145): Symfony\\Component\\EventDispatcher\\EventDispatcher->dispatch('kernel.request', Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent))\n#29 /vendor/symfony/http-kernel/HttpKernel.php(126): Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher->dispatch('kernel.request', Object(Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent))\n#30 /vendor/symfony/http-kernel/HttpKernel.php(67): Symfony\\Component\\HttpKernel\\HttpKernel->handleRaw(Object(Symfony\\Component\\HttpFoundation\\Request), 1)\n#31 /vendor/symfony/http-kernel/Kernel.php(198): Symfony\\Component\\HttpKernel\\HttpKernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request), 1, true)\n#32 /public/index.php(25): Symfony\\Component\\HttpKernel\\Kernel->handle(Object(Symfony\\Component\\HttpFoundation\\Request))\n#33 {main}

Я думаю, проблема в том, что вместо Doctrine\\ORM\\EntityManager->getRepository('Account') он должен загрузить Doctrine\\ORM\\EntityManager->getRepository('App\Entity\Account'), но я не знаю, как это изменить.

Кто-нибудь из вас имеет опыт с этим? И, надеюсь, решение?

...