当前位置: 首页>>代码示例>>PHP>>正文


PHP TokenInterface::isAuthenticated方法代码示例

本文整理汇总了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());
 }
开发者ID:dragosprotung,项目名称:AclBundle,代码行数:10,代码来源:AbstractSecurityTest.php

示例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.');
 }
开发者ID:GCth,项目名称:crowd-auth-bundle,代码行数:10,代码来源:CrowdProvider.php

示例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;
 }
开发者ID:modera,项目名称:foundation,代码行数:15,代码来源:Authenticator.php

示例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) {
             }
         }
     }
 }
开发者ID:athlan,项目名称:revive-symfony-security-bundle,代码行数:16,代码来源:LogoutHandler.php

示例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;
 }
开发者ID:koanreview,项目名称:laravel-security-1,代码行数:17,代码来源:AuthVoter.php

示例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');
 }
开发者ID:joeflack4,项目名称:OpitHrm,代码行数:55,代码来源:LdapAuthenticator.php

示例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();
 }
开发者ID:dongilbert,项目名称:mautic,代码行数:11,代码来源:AuthenticationEvent.php

示例8: showMenu

 private function showMenu()
 {
     return $this->token && $this->token->isAuthenticated() and $this->acl->isGranted("ROLE_USER");
 }
开发者ID:PhilippeGeek,项目名称:adhesion,代码行数:4,代码来源:MenuBuilder.php


注:本文中的Symfony\Component\Security\Core\Authentication\Token\TokenInterface::isAuthenticated方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。