public function isAuthenticated() { if (($ret = parent::isAuthenticated()) === FALSE) { return FALSE; } if (($identity = $this->getIdentity()) === NULL) { return FALSE; } if ($identity instanceof UserEntity) { if (!isset($this->logins[$this->session->id][$identity->id])) { $this->logins[$this->session->id][$identity->id] = (bool) $this->loginRepository->findOneBy(array('user' => $identity->id, 'sessionId' => $this->session->id)); } return $this->logins[$this->session->id][$identity->id]; } else { if ($this->checkConnection->invoke()) { try { if (!isset($this->logins[$this->session->id][-1])) { $this->logins[$this->session->id][-1] = (bool) $this->loginRepository->findOneBy(array('user' => NULL, 'sessionId' => $this->session->id)); if (!$this->logins[$this->session->id][-1]) { $this->setAuthenticated(TRUE); } } return TRUE; } catch (DBALException $e) { } } } return $ret; }
/** * Returns and initializes $this->sessionSection. * @param bool * @return Nette\Http\SessionSection */ protected function getSessionSection($need) { $section = parent::getSessionSection($need); if ($section->authenticated && !$this->isIdentityValid($section->identity)) { $this->invalidateUser($section); } return $section; }
/** * @param \Nette\Security\IIdentity * @return UserStorage */ public function setIdentity(IIdentity $identity = NULL) { if (!($identity instanceof User || $identity === NULL)) { throw new InvalidArgumentException(__CLASS__ . '::' . __METHOD__ . ' needs instance of ' . User::class . ', got ' . get_class($identity)); } $this->identity = $identity; return parent::setIdentity($identity === NULL ? NULL : new Identity($identity->getId())); }
public function getIdentity() { $identity = parent::getIdentity(); if ($identity !== null && $identity->getId() == 'Facilis\\Users\\UserAggregate' && $identity instanceof Identity) { $identity = $this->entityManager->getRepository('Facilis\\Users\\UserAggregate')->find($identity->getData()['id']); } return $identity; }
/** * Returns current user identity, if any. * @return IIdentity|NULL */ public function getIdentity() { $identity = parent::getIdentity(); // if we have our fake identity, we now want to // convert it back into the real entity // returning reference provides potentially lazy behavior if ($identity instanceof FakeIdentity) { return $this->entityManager->getReference($identity->getClass(), $identity->getId()); } return $identity; }
/** * Returns current user identity, if any. * @return User|NULL */ public function getIdentity() { if ($this->identity) { return $this->identity; } $identity = parent::getIdentity(); if ($identity instanceof FakeIdentity) { $this->identity = $this->userRepository->get($identity->getId()); return $this->identity; } return $identity; }
/** * Returns and initializes $this->sessionSection. * @return Nette\Http\SessionSection */ protected function getSessionSection($need) { $ret = parent::getSessionSection($need); if (!is_null($ret)) { if ($ret->authenticated && $ret->identity->browser !== $this->browser->getName() && $ret->identity->browserVersion !== $this->browser->getVersion()) { $ret->authenticated = FALSE; $this->sessionHandler->regenerateId(); $ret->reason = static::MANUAL; $ret->authTime = NULL; } } return $ret; }
/** * Returns current user identity, if any. * @return IIdentity|NULL */ public function getIdentity() { $identity = parent::getIdentity(); // if we have our fake identity, we now want to // convert it back into the real entity if ($identity instanceof FakeIdentity) { return $this->cache->load(sprintf('user-%s', $identity->getId()), function () use($identity) { return $this->entityManager->createQuery('SELECT u, roles FROM ' . $identity->getClass() . ' u LEFT JOIN u.roles roles WHERE u.id = :id')->setParameter('id', $identity->getId())->getOneOrNullResult(); }); //return $this->entityManager->getReference($identity->getClass(), $identity->getId()); } return $identity; }
/** * @return bool * @throws InvalidStateException */ public function isAuthenticated() { $authenticated = parent::isAuthenticated(); if ($this->users === NULL) { throw new InvalidStateException('Service IUsers is not registered.'); } if ($this->authenticated === NULL || $this->authenticated !== $authenticated) { if ($authenticated === true) { $identity = $this->getIdentity(); if (!$this->users->validateToken($identity->getToken(), $identity->getUser())) { $this->getSessionSection(true)->remove(); // Logout $authenticated = false; } } $this->authenticated = $authenticated; } return $this->authenticated; }
/** * @param bool $need * @return SessionSection */ protected function getSessionSection($need) { if (!$this->sessionSection) { $section = parent::getSessionSection($need); if ($this->identityValidator && $section && $section->authenticated) { $identity = $this->identityValidator->validateIdentity($section->identity); if ($identity instanceof IIdentity) { $section->identity = $identity; } else { $section->authenticated = false; $section->reason = FirewallInterface::LOGOUT_INVALID_IDENTITY; if ($section->expireIdentity) { unset($section->identity); } unset($section->expireTime, $section->expireDelta, $section->expireIdentity, $section->expireBrowser, $section->browserCheck, $section->authTime); } } $this->sessionSection = $section; } return $this->sessionSection; }