本文整理汇总了PHP中Symfony\Component\Security\Core\Authentication\Token\TokenInterface::isAuthenticated方法的典型用法代码示例。如果您正苦于以下问题:PHP TokenInterface::isAuthenticated方法的具体用法?PHP TokenInterface::isAuthenticated怎么用?PHP TokenInterface::isAuthenticated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Security\Core\Authentication\Token\TokenInterface
的用法示例。
在下文中一共展示了TokenInterface::isAuthenticated方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: authenticateUser
/**
* @param UserInterface $user
*/
protected function authenticateUser(UserInterface $user)
{
$this->token = $this->createToken($user);
$tokenStorage = $this->container->has('security.token_storage') ? $this->container->get('security.token_storage') : $this->container->get('security.context');
$tokenStorage->setToken($this->token);
$this->assertTrue($this->token->isAuthenticated());
}
示例2: authenticate
public function authenticate(TokenInterface $token)
{
$user = $this->userProvider->loadUserByUsername($token->getUsername());
if ($user && ($token->isAuthenticated() || $this->crowd->isauthenticationvalid($token->getUsername(), $token->getCredentials()))) {
$authenticatedToken = new CrowdToken($user->getRoles());
$authenticatedToken->setUser($user);
return $authenticatedToken;
}
throw new AuthenticationException('The Crowd authentication failed.');
}
示例3: getAuthenticationResponse
/**
* @param TokenInterface $token
*
* @return array
*/
public static function getAuthenticationResponse(TokenInterface $token)
{
$response = array('success' => false);
if ($token->isAuthenticated() && $token->getUser() instanceof User) {
/* @var User $user */
$user = $token->getUser();
$response = array('success' => true, 'profile' => self::userToArray($user));
}
return $response;
}
示例4: logout
/**
* @inheritdoc
*/
public function logout(Request $request, Response $response, TokenInterface $token)
{
if ($token instanceof ReviveAuthenticationToken) {
if ($token->isAuthenticated()) {
$sessionId = $token->getSessionId();
try {
$this->userSessionRepository->invalidateSession($sessionId);
} catch (RepositoryInfrastructureException $ignored) {
} catch (\InvalidArgumentException $ignored) {
}
}
}
}
示例5: vote
/**
* {@inheritdoc}
*/
public function vote(TokenInterface $token, $object, array $attributes)
{
$result = VoterInterface::ACCESS_ABSTAIN;
foreach ($attributes as $attribute) {
if (!$this->supportsAttribute($attribute)) {
continue;
}
$result = VoterInterface::ACCESS_DENIED;
if ((self::IS_AUTHENTICATED === $attribute or self::AUTH === $attribute) && $token->isAuthenticated()) {
return VoterInterface::ACCESS_GRANTED;
}
}
return $result;
}
示例6: authenticateToken
/**
* Function used for user authentication based on token object
*
* @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token
* @param \Symfony\Component\Security\Core\User\UserProviderInterface $userProvider
* @param type $providerKey
* @return \Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken
* @throws BadCredentialsException
*/
public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
{
$passwordValid = false;
// Loda user object
try {
$user = $userProvider->loadUserByUsername($token->getUsername());
} catch (UsernameNotFoundException $e) {
throw new BadCredentialsException('Invalid username or password', 0, $e);
}
// Check if ldap extension is enabled and user's ldap flag is set.
if (null !== $this->ldapManager && $user->isLdapEnabled()) {
try {
$this->ldapManager->bind($token->getUsername(), $token->getCredentials());
$passwordValid = (bool) $this->ldapManager->getBoundUser();
if (null !== $this->logger && !$token->isAuthenticated()) {
$this->logger->info("[LdapAuthenticator] Ldap authentication successful.", array('user' => $this->ldapManager->getBoundUser()));
}
} catch (\Zend\Ldap\Exception\LdapException $e) {
throw new BadCredentialsException('Invalid username or password', 0, $e);
}
} else {
$currentUser = $token->getUser();
if ($currentUser instanceof UserInterface) {
if ($currentUser->getPassword() !== $user->getPassword()) {
throw new BadCredentialsException('The credentials were changed from another session.');
} else {
$passwordValid = true;
}
} else {
if ("" === ($presentedPassword = $token->getCredentials())) {
throw new BadCredentialsException('Invalid username or password.');
}
if (!($passwordValid = $this->encoderFactory->getEncoder($user)->isPasswordValid($user->getPassword(), $presentedPassword, $user->getSalt()))) {
throw new BadCredentialsException('Invalid username or password.');
}
}
if (null !== $this->logger && !$token->isAuthenticated()) {
$this->logger->info("[LdapAuthenticator] Local authentication successful.", array('user' => $user->getUsername()));
}
}
// Set the authenticated token
if ($passwordValid) {
return new UsernamePasswordToken($user, $user->getPassword(), $providerKey, $user->getRoles());
}
throw new BadCredentialsException('Invalid username or password');
}
示例7: setToken
/**
* @param $service
* @param TokenInterface $token
*/
public function setToken($service, TokenInterface $token)
{
$this->token = $token;
$this->authenticatingService = $service;
$this->isAuthenticated = $token->isAuthenticated();
$this->stopPropagation();
}
示例8: showMenu
private function showMenu()
{
return $this->token && $this->token->isAuthenticated() and $this->acl->isGranted("ROLE_USER");
}