/** * Try to auth the User * * @return Result */ public function authenticate() { try { $user = $this->provider->getByUsername($this->username); } catch (UserNotFound $e) { return new Result(Result::FAILURE_IDENTITY_NOT_FOUND, null, array('identity not found in the specified User Provider')); } catch (UserProviderException $e) { return new Result(Result::FAILURE_UNCATEGORIZED, null, array($e->getMessage())); } if (!$user instanceof PasswordAware) { throw new AuthenticationException('User must implements PasswordAware interface to use this ' . 'Authtentication Adapter.'); } $crypted = $user->getPassword(); if (false === $crypted) { return new Result(Result::FAILURE_UNCATEGORIZED, null, array('invalid $passwordProperty defined')); } if (is_callable($this->saltClosure)) { $computedSalt = true; $this->generator->setSalt(call_user_func_array($this->saltClosure, array($user))); } $verify = $this->generator->verify($this->password, $crypted); if (isset($computedSalt)) { $this->generator->clearSalt(); } if ($verify === true) { return new Result(Result::SUCCESS, array('identifier' => $user->getIdentifier(), 'username' => $user->getUsername()), array()); } return new Result(Result::FAILURE_CREDENTIAL_INVALID, null, array('invalid credentials')); }
/** * * @return User * @throws AuthenticationRequired If authentication is required .. */ public function getUser(Request $request = null) { if (!isset($this->user)) { if (!($identity = $this->authenticationManager->getIdentity())) { throw new AuthenticationRequired(); } if (isset($identity['identifier']) && !empty($identity['identifier'])) { $user = $this->userProvider->getById($identity['identifier']); } elseif (isset($identity['username'])) { $user = $this->userProvider->getByUsername($identity['username'], true); } else { return null; } $this->user = $user; $this->notifyEvent(Events::USER_LOADED, array('user' => $user)); } return $this->user; }