Username Password Authenticator only returns UserInterface symfony

Symfony Feature - Custom Password Authenticator http://symfony.com/doc/current/cookbook/security/custom_password_authenticator.html

So this piece of code gets my service provider class defined in services.yml via UserProviderInterface

and returns UserInterface

.

public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
    try {
        $user = $userProvider->loadUserByUsername($token->getUsername());

      

My custom class provider implements AdvancedUserInterface

a few more functionality by default : http://api.symfony.com/2.6/Symfony/Component/Security/Core/User/AdvancedUserInterface.html

class Users implements AdvancedUserInterface, \Serializable

      

Question: How to implement AdvancedUserInterface

with UserProviderInterface

. Or do I just need to recreate these functions AdvancedUserInterface

manually and check manually after loading the custom object?

Thank. I hope you understand.

Revision: This is similar to functions in the AdvancedUser interface that are not automatically called in user authentication for passwords. So after the custom object has to manually call these functions

   try {
        $user = $userProvider->loadUserByUsername($token->getUsername());
        if ($user->isAccountNonExpired()){ throw new AuthenticationException('expired');}
        if ($user->isAccountNonLocked()){ throw new AuthenticationException('locked');}
        if ($user->isCredentialsNonExpired()){ throw new AuthenticationException('credExpired');}
        if (!$user->isEnabled()){ throw new AuthenticationException('disabled');}

      

+3


source to share


1 answer


You are probably confusing something.

AdvancedUserInterface

- specify a user instance and continues from UserInterface

.

UserProviderInterface

- specify suppliers for load users ( UserInterface

).

In the method, loadUserByUsername

you can return instances AdvancedUserInterface

.

As an example:



User:

class User implements AdvancedUserInterface
{
  // .. Some fields and functions
}

      

User Provider:

class MyUserProvider implements UserProviderInterface
{
  public function loadUserByUsername($username)
  {
     // Get the User instance from DB or another system
     return $user;
  }

  // Some functions
}

      

+2


source







All Articles