當前位置: 首頁>>代碼示例>>PHP>>正文


PHP TokenInterface::getUser方法代碼示例

本文整理匯總了PHP中Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getUser方法的典型用法代碼示例。如果您正苦於以下問題:PHP TokenInterface::getUser方法的具體用法?PHP TokenInterface::getUser怎麽用?PHP TokenInterface::getUser使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Security\Core\Authentication\Token\TokenInterface的用法示例。


在下文中一共展示了TokenInterface::getUser方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getUser

 /**
  * {@inheritDoc}
  */
 public function getUser()
 {
     if (is_object($user = $this->token->getUser())) {
         return $user;
     }
     return null;
 }
開發者ID:scheb,項目名稱:two-factor-bundle,代碼行數:10,代碼來源:AuthenticationContext.php

示例2: vote

 public function vote(TokenInterface $token, $object, array $attributes)
 {
     if ($object instanceof ResourceCollection) {
         $granted = false;
         $user = null;
         if ($token->getUser() instanceof User) {
             $user = $token->getUser();
         }
         if ($this->manager->hasTemporaryAccessOnSomeResources($user)) {
             foreach ($attributes as $attribute) {
                 if ($this->supportsAttribute($attribute) && $this->supportsClass($object)) {
                     foreach ($object->getResources() as $resource) {
                         if ($this->manager->hasTemporaryAccess($resource, $user)) {
                             $granted = true;
                             break;
                         }
                     }
                 }
             }
         }
         if ($granted) {
             return VoterInterface::ACCESS_GRANTED;
         } else {
             return VoterInterface::ACCESS_DENIED;
         }
     }
     return VoterInterface::ACCESS_ABSTAIN;
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:28,代碼來源:TemporaryAccessResourceVoter.php

示例3: vote

 /**
  * {@inheritdoc}
  */
 public function vote(TokenInterface $token, $object, array $attributes)
 {
     if (!$token->getUser() instanceof User) {
         return VoterInterface::ACCESS_ABSTAIN;
     }
     return $token->getUser()->hasRole('ROLE_SUPER_ADMIN') ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_ABSTAIN;
 }
開發者ID:kalamu,項目名稱:admin-bundle,代碼行數:10,代碼來源:SuperAdminVoter.php

示例4: voteOnAttribute

 /**
  * @param string $attribute
  * @param CourseLearningMaterialInterface $material
  * @param TokenInterface $token
  * @return bool
  */
 protected function voteOnAttribute($attribute, $material, TokenInterface $token)
 {
     $user = $token->getUser();
     if (!$user instanceof UserInterface) {
         return false;
     }
     $course = $material->getCourse();
     if (!$course) {
         return false;
     }
     switch ($attribute) {
         case self::VIEW:
             $granted = $this->isViewGranted($course->getId(), $course->getSchool()->getId(), $user);
             // prevent access if associated LM is in draft, and the current user has no elevated privileges.
             if ($granted) {
                 $granted = $this->userHasRole($token->getUser(), ['Faculty', 'Course Director', 'Developer']) || LearningMaterialStatusInterface::IN_DRAFT !== $material->getLearningMaterial()->getStatus()->getId();
             }
             return $granted;
             break;
         case self::CREATE:
         case self::EDIT:
         case self::DELETE:
             // prevent any sort of write operation (create/edit/delete) if the parent course is locked or archived.
             if ($course->isLocked() || $course->isArchived()) {
                 return false;
             }
             return $this->isWriteGranted($course->getId(), $course->getSchool()->getId(), $user);
             break;
     }
     return false;
 }
開發者ID:stopfstedt,項目名稱:ilios,代碼行數:37,代碼來源:CourseLearningMaterialVoter.php

示例5: onAuthenticationSuccess

 /**
  * @param Request $request
  * @param TokenInterface $token
  *
  * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response
  */
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     $token->getUser()->setLastlogin(new \DateTime());
     $token->getUser()->save();
     $log = new UserLog();
     $log->setIpSource($request->getClientIp());
     $token->getUser()->addUserLog($log);
     $token->getUser()->save();
     /** @var SecurityContext $securityContext */
     $securityContext = $this->container->get('security.context');
     if ($securityContext->isGranted('ROLE_SUPER_ADMIN')) {
         return new RedirectResponse($this->container->get('router')->generate('sonata_admin_dashboard'));
     }
     if ($securityContext->isGranted('ROLE_ADMIN')) {
         return new RedirectResponse($this->container->get('router')->generate('pgs_admin_dashboard'));
     }
     if ($securityContext->isGranted('ROLE_OFFICE')) {
         return new RedirectResponse($this->container->get('router')->generate('pgs_office_dashboard'));
     }
     if ($securityContext->isGranted('ROLE_PRINCIPAL')) {
         return new RedirectResponse($this->container->get('router')->generate('pgs_principal_dashboard'));
     }
     if ($securityContext->isGranted('ROLE_SALES')) {
         return new RedirectResponse($this->container->get('router')->generate('pgs_sales_dashboard'));
     }
     if ($securityContext->isGranted('ROLE_USER')) {
         return new RedirectResponse($this->container->get('router')->generate('homepage'));
     }
 }
開發者ID:peterAK,項目名稱:pgs-sts,代碼行數:35,代碼來源:AuthenticationHandler.php

示例6: vote

 /**
  * Returns the vote for the given parameters.
  *
  * This method must return one of the following constants:
  * ACCESS_GRANTED, ACCESS_DENIED, or ACCESS_ABSTAIN.
  *
  * @param TokenInterface $token A TokenInterface instance
  * @param object $object The object to secure
  * @param array $attributes An array of attributes associated with the method being invoked
  *
  * @return integer either ACCESS_GRANTED, ACCESS_ABSTAIN, or ACCESS_DENIED
  */
 public function vote(TokenInterface $token, $object, array $attributes)
 {
     $result = VoterInterface::ACCESS_ABSTAIN;
     if (!$this->supportsClass(get_class($object))) {
         return $result;
     }
     foreach ($attributes as $attribute) {
         if (!$this->supportsAttribute($attribute)) {
             continue;
         }
         $result = VoterInterface::ACCESS_DENIED;
         switch ($attribute) {
             case Product::PRODUCT_OWNER:
                 if ($token->getUser() === $object->getUser()) {
                     return VoterInterface::ACCESS_GRANTED;
                 }
                 break;
             case Product::PRODUCT_LIKE:
                 #echo '<pre>'; var_dump($object->getLikers()); exit;
                 if ($token->getUser() !== $object->getUser() && !$object->getLikers()->contains($token->getUser())) {
                     return VoterInterface::ACCESS_GRANTED;
                 }
                 break;
         }
     }
     return $result;
 }
開發者ID:alexislefebvre,項目名稱:symfony-kickstarter,代碼行數:39,代碼來源:ProductVoter.php

示例7: vote

 public function vote(TokenInterface $token, $object, array $attributes)
 {
     if (0 === strpos($attributes[0], 'ROLE_')) {
         if ($token->getUser() instanceof User && in_array('ROLE_SUPER_ADMIN', $token->getUser()->getRoles())) {
             return self::ACCESS_GRANTED;
         }
     }
     return self::ACCESS_ABSTAIN;
 }
開發者ID:enhavo,項目名稱:enhavo,代碼行數:9,代碼來源:SuperAdminVoter.php

示例8: 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

示例9: onAuthenticationSuccess

 /**
  * Redirige une authentification OAuth réussie vers le formulaire de demande d'authorisation
  * @param Request $request
  * @param TokenInterface $token
  * @return RedirectResponse
  */
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     if (!is_null($token->getUser()->getOauthClient())) {
         $client = $token->getUser()->getOauthClient();
         $redirection = new RedirectResponse($this->router->generate('fos_oauth_server_authorize', array('client_id' => $client->getPublicId(), 'response_type' => 'code', 'redirect_uri' => $client->getRedirectUris()[0])));
     } else {
         $redirection = new RedirectResponse('/');
     }
     return $redirection;
 }
開發者ID:studiocaramia,項目名稱:redking_OAuthBundle,代碼行數:16,代碼來源:AfterLoginRedirection.php

示例10: canDelete

 /**
  * Удалять могут: Пользователь-Владелец, Администратор
  */
 private function canDelete(User $user, TokenInterface $token)
 {
     if (!$token->getUser() instanceof User) {
         return false;
     }
     if ($token->getUser() === $user) {
         return true;
     }
     return $this->decisionManager->decide($token, array('ROLE_ADMIN'));
 }
開發者ID:Gemorroj,項目名稱:forum,代碼行數:13,代碼來源:UserVoter.php

示例11: logout

 /**
  * {@inheritdoc}
  * @see user_logout()
  */
 public function logout(Request $request, Response $response, TokenInterface $token)
 {
     $user = $token->getUser();
     if (is_a($user, 'Bangpound\\Bundle\\DrupalBundle\\Security\\User\\User')) {
         /** @var \Bangpound\Bundle\DrupalBundle\Security\User\User $user */
         $user = $token->getUser()->getDrupalUser();
         watchdog('user', 'Session closed for %name.', array('%name' => $user->name));
         module_invoke_all('user_logout', $user);
         $GLOBALS['user'] = drupal_anonymous_user();
     }
 }
開發者ID:bangpound,項目名稱:drupal-bundle,代碼行數:15,代碼來源:LogoutHandler.php

示例12: isGranted

 /**
  * @inheritdoc
  */
 public function isGranted($attributes, $object = null)
 {
     if (!is_array($attributes)) {
         $attributes = [$attributes];
     }
     if (null === $object) {
         $object = $this->token->getUser();
     }
     $acceptedRoles = array_intersect($attributes, $object->getRoles());
     return 0 !== count($acceptedRoles);
 }
開發者ID:treehouselabs,項目名稱:base-api-bundle,代碼行數:14,代碼來源:SecurityContext.php

示例13: vote

 /**
  * {@inheritdoc}
  */
 public function vote(TokenInterface $token, $page, array $attributes)
 {
     foreach ($attributes as $attribute) {
         if ($this->supportsAttribute($attribute) && $this->supportsClass($page)) {
             $userClass = $this->userClass;
             if ($token->getUser() instanceof $userClass && $token->getUser()->hasRole('ROLE_VICTOIRE') || $page->getAuthor() === $token->getUser()) {
                 return VoterInterface::ACCESS_GRANTED;
             }
         }
     }
     return VoterInterface::ACCESS_DENIED;
 }
開發者ID:global01,項目名稱:victoire,代碼行數:15,代碼來源:PageOwnerVoter.php

示例14: authenticateToken

 /**
  * {@inheritdoc}
  */
 public function authenticateToken(TokenInterface $token, UserProviderInterface $userProvider, $providerKey)
 {
     if (is_subclass_of($token->getUser(), $this->userClass)) {
         return new PreAuthenticatedToken($token->getUser(), $token->getCredentials(), $providerKey, $token->getUser()->getRoles());
     }
     $ssoToken = $this->tokenRepository->find($token->getCredentials());
     if (!$ssoToken) {
         throw new AuthenticationException();
     }
     $user = $userProvider->loadUserByUsername($ssoToken->getUsername());
     return new PreAuthenticatedToken($user, $token->getCredentials(), $providerKey, $user->getRoles());
 }
開發者ID:phppro,項目名稱:sso,代碼行數:15,代碼來源:SsoPreAuthenticator.php

示例15: setUp

 public function setUp()
 {
     $this->user = $this->prophesize(UserInterface::class);
     $this->token = $this->prophesize(TokenInterface::class);
     $this->token->getUser()->willReturn($this->user);
     $this->accessControlManager = $this->prophesize(AccessControlManagerInterface::class);
     $this->tokenStorage = $this->prophesize(TokenStorageInterface::class);
     $this->tokenStorage->getToken()->willReturn($this->token->reveal());
     $this->securedEntitySubscriber = new SecuredEntitySubscriber($this->accessControlManager->reveal(), $this->tokenStorage->reveal());
     $this->visitor = $this->prophesize(GenericSerializationVisitor::class);
     $this->objectEvent = $this->prophesize(ObjectEvent::class);
     $this->objectEvent->getVisitor()->willReturn($this->visitor);
 }
開發者ID:Silwereth,項目名稱:sulu,代碼行數:13,代碼來源:SecuredEntitySubscriberTest.php


注:本文中的Symfony\Component\Security\Core\Authentication\Token\TokenInterface::getUser方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。