Ejemplo n.º 1
0
 /**
  * @param string|null
  * @return mixed
  */
 public function getHeaders()
 {
     $headers = $this->cache->fetch('unittest_headers');
     if (isset($headers['HTTP_x-access-token']) && !empty($headers['HTTP_x-access-token'])) {
         $user = $this->accessTokenService->getUserByAccessToken($headers['HTTP_x-access-token']);
         if ($user == false) {
             /**
              * refresh access token because cached one is non-valid.
              */
             unset($headers['HTTP_x-access-token']);
         }
     }
     if ((!isset($headers['HTTP_x-access-token']) || empty($headers['HTTP_x-access-token'])) && !empty($this->username)) {
         $user = $this->authService->checkUsernamePassword($this->username, $this->password);
         if ($user !== false) {
             $accessToken = md5(random_bytes(32));
             $this->accessTokenService->insertAccessToken($accessToken, $user);
         }
         $headers['HTTP_x-access-token'] = $accessToken;
         $this->cache->save('unittest_headers', $headers);
     }
     return $headers;
 }
Ejemplo n.º 2
0
 /**
  * Loads the user for the given username.
  *
  * This method must throw UsernameNotFoundException if the user is not
  * found.
  *
  * @param string $username The username
  *
  * @return UserInterface
  *
  * @see UsernameNotFoundException
  *
  * @throws UsernameNotFoundException if the user is not found
  */
 public function loadUserByUsername($username)
 {
     return $this->authService->getUserByUsername($username);
 }