0

I'd like to understand how the security work with user providers. In security.yaml I can write :

   providers:
       entity_provider:
           entity:
               class: App\Entity\User
               property: userLogin
...
   firewalls:
...
           json_login:
               username_path: userLogin

And thus define "userLogin" as the proper field to use as "user name" for authentication. Is that correct? Then, why does it seems like my User class has to implement Symfony\Component\Security\Core\User\UserInterface::getUsername() ? What's supposed to happen if those functions return something different from the conf? In which cases one will be used and not the others?

1 Answer 1

2

THe methodSymfony\Component\Security\Core\User\UserInterface::getUsername() is used across symfony to check wich property is used as an identifier, it's used in the authenticator, the firewall... It will be used by all the authentication methods. In your case, you should write

/**
 * @return string
 */
public function getUsername(): ?string
{
    return $this->userLogin;
}

The property in the conf file will be looked at when you submit your login form in a regular web page. It's redundant.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok so they are indeed redundant... It's like symfony wants bugs to multiply.. My problem is that I have a userName field in User, with a doctrine generated getter getUserName, and php is not case sensitive so I would need to update my schema and fix all the necessary code.
@Shautieh, it's not like symphony want bugs to multiply, they mostly want retro-compatibility. That's how it worked before. For you userName field, yes, that's a collision, you can't do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.