Git Product home page Git Product logo

Comments (5)

a-menshchikov avatar a-menshchikov commented on May 27, 2024

Hello @likou31
Could you show your security settings (yaml) and your User class?

from onelogin-saml-bundle.

likou31 avatar likou31 commented on May 27, 2024

Actually I found a solution.

It was the provider's fault.

In the SamlUserProvider in loadUserByIdentifier(), it creates a new userClass everytime.
I created my own UserProvider that extends the SamlUserProvider, and I changed the method like this (I also changed the __construct method to add the repository) :

public function __construct(
        protected string $userClass,
        protected array $defaultRoles,
        protected UserRepository $repository,
        ManagerRegistry $doctrine
    ) {
        $this->repository = $doctrine->getManager()->getRepository('App:User');
        if (!is_a($userClass, UserInterface::class, true)) {
            throw new \InvalidArgumentException('The $userClass argument should be a class implementing the '.UserInterface::class.' interface.');
        }
    }

    public function loadUserByIdentifier(string $identifier): UserInterface
    {
        $user = $this->repository->loadUserByIdentifier($identifier);
        if ($user != null) {
            return $user;
        } else {
            return new $this->userClass($identifier, $this->defaultRoles);
        }
    }

If it can help anyone, I'll be happy !

from onelogin-saml-bundle.

a-menshchikov avatar a-menshchikov commented on May 27, 2024

In the SamlUserProvider in loadUserByIdentifier(), it creates a new userClass everytime.

It's exactly what it created for. If you want to load a user from database, the Entity User Provider might be suitable for you.

Also, I recommend you to read Just-in-time user provisioning section from README.

from onelogin-saml-bundle.

likou31 avatar likou31 commented on May 27, 2024

For my needs, I need to load it from the saml server, and persist the user. But not create each time a new user entity. (and I need to do the relation between others entities for example)

from onelogin-saml-bundle.

a-menshchikov avatar a-menshchikov commented on May 27, 2024

IIUC Just-in-time user provisioning is what you need. Use of the Saml User Factory is more convenient approach than the custom user provider which instantiates new User. But if it works for you and looks clearer, it's also good. =)

from onelogin-saml-bundle.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.