src/Security/UserProvider.php line 64

Open in your IDE?
  1. <?php
  2. namespace App\Security;
  3. use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
  4. use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
  5. use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;
  6. use Symfony\Component\Security\Core\User\UserInterface;
  7. use Symfony\Component\Security\Core\User\UserProviderInterface;
  8. use Smt\CoreBundle\Service\SmtAuth;
  9. use Smt\CoreBundle\Service\SmtApi;
  10. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  11. class UserProvider implements UserProviderInterfacePasswordUpgraderInterface
  12. {
  13.     private $Lo_SmtApi;
  14.     private $o_Session;
  15.     public function __construct(SmtApi $Ao_SmtApiSessionInterface $session){
  16.         $this->Lo_SmtApi $Ao_SmtApi;
  17.         $this->o_Session $session;
  18.     }
  19.   /**
  20.    * @required
  21.    */
  22.   public function setSmtApi(SmtApi $smtapi){
  23.     $this->Lo_SmtApi $smtapi;
  24.   }
  25. /**
  26.      * Symfony calls this method if you use features like switch_user
  27.      * or remember_me.
  28.      *
  29.      * If you're not using these features, you do not need to implement
  30.      * this method.
  31.      *
  32.      * @return UserInterface
  33.      *
  34.      * @throws UsernameNotFoundException if the user is not found
  35.      */
  36.     public function loadUserByUsername($credencials)
  37.     {
  38.         // Load a User object from your data source or throw UsernameNotFoundException.
  39.         // The $username argument may not actually be a username:
  40.         // it is whatever value is being returned by the getUsername()
  41.         // method in your User class.
  42.         $user = new User;
  43.         $Lo_SmtAuth = new SmtAuth($this->Lo_SmtApi);
  44.         $La_Result $Lo_SmtAuth->authentication($credencials['email'], $credencials['password'], $this->o_Session);
  45.         //$Lo_ApiController = new ApiController;
  46.         //$La_Result = $Lo_ApiController->authSmt($credencials['email'], $credencials['password']);
  47.         if (!$La_Result['b_Success']) {
  48.             // fail authentication with a custom error
  49.             throw new UsernameNotFoundException();
  50.         }
  51.         $user->setEmail($credencials['email']);
  52.         $user->setPersonID($La_Result['i_SSP_PersonID']);
  53.         $user->setFirstName($La_Result['s_FirstName']);
  54.         $user->setLastName($La_Result['s_LastName']);
  55.         //$user->setSetCookie($La_Result['LoginHeaders']['Set-Cookie']);
  56.         $this->o_Session->set('core/a_Person/LoginHeaders/Set-Cookie'$La_Result['LoginHeaders']['Set-Cookie']);
  57.         $user->setRoles($La_Result['a_ADRoles']);
  58.         $user->setFAKNumber($La_Result['s_FAKNumber']);
  59.         $user->setBirthdate($La_Result['s_Birthdate']);
  60.         $user->setAddressRole($La_Result['a_AddressRole']);
  61.         $user->setProperties($La_Result['o_Properties']);
  62.         return $user;
  63.     }
  64.     /**
  65.      * Refreshes the user after being reloaded from the session.
  66.      *
  67.      * When a user is logged in, at the beginning of each request, the
  68.      * User object is loaded from the session and then this method is
  69.      * called. Your job is to make sure the user's data is still fresh by,
  70.      * for example, re-querying for fresh User data.
  71.      *
  72.      * If your firewall is "stateless: true" (for a pure API), this
  73.      * method is not called.
  74.      *
  75.      * @return UserInterface
  76.      */
  77.     public function refreshUser(UserInterface $user)
  78.     {
  79.         if (!$user instanceof User) {
  80.             throw new UnsupportedUserException(sprintf('Invalid user class "%s".'get_class($user)));
  81.         }
  82.         /* $Lo_SmtAuth = new SmtAuth($this->Lo_SmtApi);
  83.         $La_Result = $Lo_SmtAuth->validateSession($user->getSetCookie(), $user->getPersonID());
  84.         // Return a User object after making sure its data is "fresh".
  85.         // Or throw a UsernameNotFoundException if the user no longer exists.
  86.         if(!$La_Result){
  87.           throw new UsernameNotFoundException(sprintf("Session ungültig oder abgelaufen."));
  88.         } */
  89.         return $user;
  90.     }
  91.     /**
  92.      * Tells Symfony to use this provider for this User class.
  93.      */
  94.     public function supportsClass($class)
  95.     {
  96.         return User::class === $class;
  97.     }
  98.     /**
  99.      * Upgrades the encoded password of a user, typically for using a better hash algorithm.
  100.      */
  101.     public function upgradePassword(UserInterface $userstring $newEncodedPassword): void
  102.     {
  103.         // TODO: when encoded passwords are in use, this method should:
  104.         // 1. persist the new password in the user storage
  105.         // 2. update the $user object with $user->setPassword($newEncodedPassword);
  106.     }
  107. }