Giter Club home page Giter Club logo

Comments (7)

Maks3w avatar Maks3w commented on July 30, 2024

I've to admit that branch of the code is a mistery for me.

I was following the same code of DaoAuthenticationProvider but it's truth getPassword is empty or is a hashed password so the return value won't be valid in any case.

So the question is How we can re authenticate an already logged user?

from fr3dldapbundle.

Maks3w avatar Maks3w commented on July 30, 2024

What is the return value of $token->getCredentials()?

from fr3dldapbundle.

Saaha avatar Saaha commented on July 30, 2024

$token->getCredentials() return the password filled by the user while the process of authentication starts (before redirect). I actually tried to replace $currentUser->getPassword() by $token->getCredentials() but no change. I my opinion the problem is deeper in the process.

When the User is authenticated, the condition ($currentUser instanceof UserInterface) is true and the User is rebind from the informations returned by the token (aka getUser() and getCredentials()). The User returned by getCredentials() is free of password (by default, it's empty because it's overrided on hydrate method on LdapManager : the password is set to blank.
I tried to set the password on the instance User in checkAuthentication but no change too. Seems when the token is re-recreated the password is lost...

from fr3dldapbundle.

Saaha avatar Saaha commented on July 30, 2024

Here is the solution !

Change $currentUser->getPassword() to $token->getCredentials() in LdapAuthenticationProvider, and turn off the property erase_credentials in security.yml.
The generated token keeps the password after login and the bind method is working correctly. I don't know if it's the really waited behaviour or just a bad way to resolve it.

I notice a strange thing btw, the Zend/Ldap driver is called twice, the first time is when the default connection defined in config.yml with username and password are used. The second one is when the bind method is directly called to authenticate User. In this case, I trace all the workflow to show up how it behaves : an Exception is correctly thrown (because username is filled, password is empty and AllowEmptyPassword is false) but in UserAuthenticationProvider the code below does not throw the Exception to the caller class (AuthenticationProviderManager) :

try {
      $this->userChecker->checkPreAuth($user);
      $this->checkAuthentication($user, $token);
      $this->userChecker->checkPostAuth($user);
} catch (BadCredentialsException $e) {
      if ($this->hideUserNotFoundExceptions) {
            throw new BadCredentialsException('Bad credentials', 0, $e);
      }
      throw $e;
}

I don't know why and when the Exception is catched. This issue messed up my brain !

from fr3dldapbundle.

Maks3w avatar Maks3w commented on July 30, 2024

Do you want create a PR with the fix?

About the driver called twice:
a) The first one is the user provider part. (Symfony expects to provider a user object, so you can provide a user from bd but later authenticate against ldap)
b) The second is the user authentication.

from fr3dldapbundle.

Saaha avatar Saaha commented on July 30, 2024

I am not sure if the fix is correct, I gonna make new tests with fresh installation and chaining providers to be sure it does not bring regression.

from fr3dldapbundle.

Maks3w avatar Maks3w commented on July 30, 2024

The change will make a BC Break with objects retrieved from BD. But this have to be fixed as you proposed.

from fr3dldapbundle.

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.