当前位置: 首页>>代码示例>>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;未经允许,请勿转载。