hslavich / OneloginSamlBundle

OneLogin SAML Bundle for Symfony
MIT License
149 stars 94 forks source link

2.3.2 assumes the User objects are Doctrine entities, when they may not be #168

Closed junowilderness closed 3 years ago

junowilderness commented 3 years ago
Doctrine\Persistence\Mapping\MappingException:
The class 'App\Component\User\User' was not found in the chain configured namespaces App\Entity

  at vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/MappingException.php:23
  at Doctrine\Persistence\Mapping\MappingException::classNotFoundInNamespaces('App\\Component\\User\\User', array('App\\Entity'))
     (vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/Driver/MappingDriverChain.php:91)
  at Doctrine\Persistence\Mapping\Driver\MappingDriverChain->loadMetadataForClass('App\\Component\\User\\User', object(ClassMetadata))
     (vendor/doctrine/doctrine-bundle/Mapping/MappingDriver.php:45)
  at Doctrine\Bundle\DoctrineBundle\Mapping\MappingDriver->loadMetadataForClass('App\\Component\\User\\User', object(ClassMetadata))
     (vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:156)
  at Doctrine\ORM\Mapping\ClassMetadataFactory->doLoadMetadata(object(ClassMetadata), null, false, array())
     (vendor/doctrine/doctrine-bundle/Mapping/ClassMetadataFactory.php:19)
  at Doctrine\Bundle\DoctrineBundle\Mapping\ClassMetadataFactory->doLoadMetadata(object(ClassMetadata), null, false, array())
     (vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:382)
  at Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->loadMetadata('App\\Component\\User\\User')
     (vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:85)
  at Doctrine\ORM\Mapping\ClassMetadataFactory->loadMetadata('App\\Component\\User\\User')
     (vendor/doctrine/persistence/lib/Doctrine/Persistence/Mapping/AbstractClassMetadataFactory.php:251)
  at Doctrine\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor('App\\Component\\User\\User')
     (vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:293)
  at Doctrine\ORM\EntityManager->getClassMetadata('App\\Component\\User\\User')
     (vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1789)
  at Doctrine\ORM\UnitOfWork->doPersist(object(User), array('000000006f7ecf8700000000299d9133' => object(User)))
     (vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php:1764)
  at Doctrine\ORM\UnitOfWork->persist(object(User))
     (vendor/doctrine/orm/lib/Doctrine/ORM/EntityManager.php:629)
  at Doctrine\ORM\EntityManager->persist(object(User))
     (var/cache/dev/Container22YYWQa/EntityManager_9a5be93.php:171)
  at Container22YYWQa\EntityManager_9a5be93->persist(object(User))
     (vendor/hslavich/oneloginsaml-bundle/Security/Http/Authenticator/SamlAuthenticator.php:142)
  at Hslavich\OneloginSamlBundle\Security\Http\Authenticator\SamlAuthenticator->Hslavich\OneloginSamlBundle\Security\Http\Authenticator\{closure}('cjm')
     (vendor/symfony/security-http/Authenticator/Passport/Badge/UserBadge.php:66)
  at Symfony\Component\Security\Http\Authenticator\Passport\Badge\UserBadge->getUser()
     (vendor/symfony/security-http/Authenticator/Passport/Passport.php:56)
  at Symfony\Component\Security\Http\Authenticator\Passport\Passport->getUser()
     (vendor/symfony/security-http/EventListener/UserCheckerListener.php:43)
  at Symfony\Component\Security\Http\EventListener\UserCheckerListener->preCheckCredentials(object(CheckPassportEvent), 'Symfony\\Component\\Security\\Http\\Event\\CheckPassportEvent', object(EventDispatcher))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:270)
  at Symfony\Component\EventDispatcher\EventDispatcher::Symfony\Component\EventDispatcher\{closure}(object(CheckPassportEvent), 'Symfony\\Component\\Security\\Http\\Event\\CheckPassportEvent', object(EventDispatcher))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(Closure), object(Closure), object(Closure), object(Closure), object(Closure)), 'Symfony\\Component\\Security\\Http\\Event\\CheckPassportEvent', object(CheckPassportEvent))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(CheckPassportEvent))
     (vendor/symfony/security-http/Authentication/AuthenticatorManager.php:175)
  at Symfony\Component\Security\Http\Authentication\AuthenticatorManager->executeAuthenticator(object(SamlAuthenticator), object(Request))
     (vendor/symfony/security-http/Authentication/AuthenticatorManager.php:152)
  at Symfony\Component\Security\Http\Authentication\AuthenticatorManager->executeAuthenticators(array(object(SamlAuthenticator)), object(Request))
     (vendor/symfony/security-http/Authentication/AuthenticatorManager.php:132)
  at Symfony\Component\Security\Http\Authentication\AuthenticatorManager->authenticateRequest(object(Request))
     (vendor/symfony/security-http/Firewall/AuthenticatorManagerListener.php:40)
  at Symfony\Component\Security\Http\Firewall\AuthenticatorManagerListener->authenticate(object(RequestEvent))
     (vendor/symfony/security-bundle/Debug/WrappedLazyListener.php:49)
  at Symfony\Bundle\SecurityBundle\Debug\WrappedLazyListener->authenticate(object(RequestEvent))
     (vendor/symfony/security-http/Firewall/AbstractListener.php:26)
  at Symfony\Component\Security\Http\Firewall\AbstractListener->__invoke(object(RequestEvent))
     (vendor/symfony/security-bundle/Debug/TraceableFirewallListener.php:62)
  at Symfony\Bundle\SecurityBundle\Debug\TraceableFirewallListener->callListeners(object(RequestEvent), object(Generator))
     (vendor/symfony/security-http/Firewall.php:86)
  at Symfony\Component\Security\Http\Firewall->onKernelRequest(object(RequestEvent), 'kernel.request', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/Debug/WrappedListener.php:117)
  at Symfony\Component\EventDispatcher\Debug\WrappedListener->__invoke(object(RequestEvent), 'kernel.request', object(TraceableEventDispatcher))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:230)
  at Symfony\Component\EventDispatcher\EventDispatcher->callListeners(array(object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener), object(WrappedListener)), 'kernel.request', object(RequestEvent))
     (vendor/symfony/event-dispatcher/EventDispatcher.php:59)
  at Symfony\Component\EventDispatcher\EventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
     (vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php:151)
  at Symfony\Component\EventDispatcher\Debug\TraceableEventDispatcher->dispatch(object(RequestEvent), 'kernel.request')
     (vendor/symfony/http-kernel/HttpKernel.php:133)
  at Symfony\Component\HttpKernel\HttpKernel->handleRaw(object(Request), 1)
     (vendor/symfony/http-kernel/HttpKernel.php:79)
  at Symfony\Component\HttpKernel\HttpKernel->handle(object(Request), 1, true)
     (vendor/symfony/http-kernel/Kernel.php:199)
  at Symfony\Component\HttpKernel\Kernel->handle(object(Request))
     (public/index.php:30)   
junowilderness commented 3 years ago

In short, User implements SamlUserInterface but it is not a Doctrine Entity.

hslavich commented 3 years ago

Hi, it seems there is a bug here: https://github.com/hslavich/OneloginSamlBundle/blob/7038f6e617c1a4d54bb1a47b1e106fc28d85f248/Security/Http/Authenticator/SamlAuthenticator.php#L141

User should be persisted only if $this->options['persist_user'] is true. This will be fixed soon

Could you edit this and confirm if this fix your error?

Thanks

junowilderness commented 3 years ago

@hslavich I patched with #169 and it looks good now.

a-menshchikov commented 3 years ago

@hslavich I think we should separate the new user persistence and the persistence of existing user after setSamlAttributes.

yalefresne commented 3 years ago

Hi there,

Do you plan to push the fix on the v1.5 ? There is the same issue on the v1.5.3

a-menshchikov commented 3 years ago

@yalefresne this bug will be fixed in both branches (1.x and 2.x).