當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。