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


PHP TokenInterface::getRoles方法代碼示例

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


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

示例1: createUser

 public function createUser(TokenInterface $token)
 {
     $username = $token->getUser();
     $attributes = $token->getAttributes();
     if (is_null($token->getRoles())) {
         $roles = isset($attributes['roles']) ? $attributes['roles'] : null;
         unset($attributes['roles']);
     } else {
         $roles = $token->getRoles();
     }
     return new SpawnedUser($username, $attributes, $roles);
 }
開發者ID:AlejandroHerr,項目名稱:EsnGalaxy,代碼行數:12,代碼來源:SpawnedUserProvider.php

示例2: vote

 public function vote(TokenInterface $token, Location $object, array $attributes)
 {
     if (in_array('ROLE_LOCATION_MODERATOR', $token->getRoles())) {
         return VoterInterface::ACCESS_GRANTED;
     }
     return VoterInterface::ACCESS_ABSTAIN;
 }
開發者ID:rickogden,項目名稱:craftbeeruk,代碼行數:7,代碼來源:LocationVoter.php

示例3: vote

 public function vote(TokenInterface $token, $group, array $attributes)
 {
     // check if class of this object is supported by this voter
     if (!$this->supportsClass(get_class($group))) {
         return VoterInterface::ACCESS_ABSTAIN;
     }
     // check if the given attribute is covered by this voter
     if (!$this->supportsAttribute($attributes[0])) {
         return VoterInterface::ACCESS_ABSTAIN;
     }
     // get current logged in user
     $user = $token->getUser();
     //allow the token to have ROLE_SUPER_ADMIN before we check the user, for testing
     if (in_array(new Role("ROLE_SUPER_ADMIN"), $token->getRoles())) {
         return VoterInterface::ACCESS_GRANTED;
     }
     // make sure there is a user object (i.e. that the user is logged in)
     if (!$user instanceof User) {
         return VoterInterface::ACCESS_DENIED;
     }
     switch ($attributes[0]) {
         case self::VIEW:
             if ($user->hasGroup($group->getName())) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
         case self::EDIT:
             if ($user->hasGroup($group->getName()) && $user->hasRole("ROLE_ADMIN")) {
                 return VoterInterface::ACCESS_GRANTED;
             }
             break;
     }
     return VoterInterface::ACCESS_DENIED;
 }
開發者ID:amyboyd,項目名稱:overwatch,代碼行數:34,代碼來源:TestGroupVoter.php

示例4: getRoles

 /**
  * Returns the roles (an array of string) of the $token.
  *
  * @todo remove this $method
  *
  * @param \Symfony\Component\Security\Core\Authentication\Token\TokenInterface $token
  *
  * @return array
  */
 public function getRoles(TokenInterface $token)
 {
     $roles = array();
     foreach ($token->getRoles() as $role) {
         $roles[] = $role->getRole();
     }
     return $roles;
 }
開發者ID:claroline,項目名稱:distribution,代碼行數:17,代碼來源:Utilities.php

示例5: isAdmin

 protected function isAdmin(TokenInterface $token)
 {
     foreach ($token->getRoles() as $role) {
         if (PlatformRoles::ADMIN === $role->getRole()) {
             return true;
         }
     }
     return false;
 }
開發者ID:ngydat,項目名稱:CoreBundle,代碼行數:9,代碼來源:AdministratorVoter.php

示例6: getVariables

 private function getVariables(TokenInterface $token, $object)
 {
     if (null !== $this->roleHierarchy) {
         $roles = $this->roleHierarchy->getReachableRoles($token->getRoles());
     } else {
         $roles = $token->getRoles();
     }
     $variables = array('token' => $token, 'user' => $token->getUser(), 'object' => $object, 'roles' => array_map(function ($role) {
         return $role->getRole();
     }, $roles), 'trust_resolver' => $this->trustResolver);
     // this is mainly to propose a better experience when the expression is used
     // in an access control rule, as the developer does not know that it's going
     // to be handled by this voter
     if ($object instanceof Request) {
         $variables['request'] = $object;
     }
     return $variables;
 }
開發者ID:kchhainarong,項目名稱:chantuchP,代碼行數:18,代碼來源:ExpressionVoter.php

示例7: onAuthenticationSuccess

 /**
  * @param Request        $request
  * @param TokenInterface $token
  *
  * @return RedirectResponse
  */
 public function onAuthenticationSuccess(Request $request, TokenInterface $token)
 {
     foreach ($token->getRoles() as $role) {
         if ('ROLE_ADMIN' == $role->getRole()) {
             return new RedirectResponse($this->router->generate('admin_start'));
         }
     }
     return new RedirectResponse($this->router->generate('homepage'));
 }
開發者ID:erickr,項目名稱:Kompisbyran,代碼行數:15,代碼來源:SuccessHandler.php

示例8: isIddqd

 protected function isIddqd(TokenInterface $token)
 {
     foreach ($token->getRoles() as $role) {
         if (in_array($role->getRole(), $this->iddqdAliases, true)) {
             return true;
         }
     }
     return false;
 }
開發者ID:rvdbogerd,項目名稱:JMSSecurityExtraBundle,代碼行數:9,代碼來源:IddqdVoter.php

示例9: isIddqd

 protected function isIddqd(TokenInterface $token)
 {
     foreach ($token->getRoles() as $role) {
         if ('IS_IDDQD' === $role->getRole()) {
             return true;
         }
     }
     return false;
 }
開發者ID:artz20,項目名稱:Tv-shows-zone,代碼行數:9,代碼來源:IddqdVoter.php

示例10: authenticate

 public function authenticate(TokenInterface $token)
 {
     $user = $token->getUser();
     if ($user) {
         $authenticatedToken = new WordpressUserToken($token->getRoles());
         $authenticatedToken->setUser($user);
         return $authenticatedToken;
     }
     throw new AuthenticationException('Wordpress authentication failed.');
 }
開發者ID:bangpound,項目名稱:wordpress-silex-extension,代碼行數:10,代碼來源:WordpressAuthenticationProvider.php

示例11: getRoles

 /**
  * Retrieves roles from user and appends SwitchUserRole if original token contained one.
  *
  * @param UserInterface  $user  The user
  * @param TokenInterface $token The token
  *
  * @return array The user roles
  */
 private function getRoles(UserInterface $user, TokenInterface $token)
 {
     $roles = $user->getRoles();
     foreach ($token->getRoles() as $role) {
         if ($role instanceof SwitchUserRole) {
             $roles[] = $role;
             break;
         }
     }
     return $roles;
 }
開發者ID:shirone,項目名稱:security-jwt-service-provider,代碼行數:19,代碼來源:JWTProvider.php

示例12: hasRole

 /**
  * Utility function to find role in token
  *
  * @param TokenInterface $token
  * @param $role
  * @return bool
  */
 public static function hasRole(TokenInterface $token, $role)
 {
     if (is_string($role)) {
         $role = new Role($role);
     }
     foreach ($token->getRoles() as $tokenRole) {
         if ($role->getRole() == $tokenRole->getRole()) {
             return true;
         }
     }
 }
開發者ID:dstansby,項目名稱:camdram,代碼行數:18,代碼來源:TokenUtilities.php

示例13: getObjectIdsForRole

 /**
  *
  * @param TokenInterface $token - Array of ACL objects to check
  * @param string $inputRole     - Requested Role
  * 
  * @return array
  */
 public function getObjectIdsForRole(TokenInterface $token, $inputRole)
 {
     $object_ids = array();
     $reachable = $this->getRoleHierarchy()->getReachableRoles($token->getRoles());
     foreach ($token->getUser()->getAcls() as $acl) {
         // found an object id for this role
         if ($acl->getType()->equal($inputRole) || $this->findInMap($acl, $reachable)) {
             $object_ids[] = $acl->getObjectId();
         }
     }
     return $object_ids;
 }
開發者ID:NobletSolutions,項目名稱:SecurityBundle,代碼行數:19,代碼來源:ACLConverter.php

示例14: voteOnAttribute

 /**
  * Perform a single access check operation on a given attribute, subject and token.
  *
  * @param string         $attribute
  * @param mixed          $subject
  * @param TokenInterface $token
  *
  * @return bool
  */
 protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
 {
     /* @var $subject SecuredAccessInterface */
     if ($subject->isUsernameAllowed($token->getUsername(), $attribute)) {
         return true;
     }
     foreach ($token->getRoles() as $role) {
         if ($subject->isRoleAllowed($role->getRole(), $attribute)) {
             return true;
         }
     }
     return false;
 }
開發者ID:mlukman,項目名稱:securilex,代碼行數:22,代碼來源:SecuredAccessVoter.php

示例15:

 function it_should_log_event(FilterControllerEvent $event, ApiControllerInterface $ctrl, LoggerInterface $logger, SecurityContext $security, Request $request, TokenInterface $token)
 {
     $logger->info('API call', Argument::type('array'))->shouldBeCalled();
     $token->getRoles()->willReturn([]);
     $token->getUsername()->willReturn('anon.');
     $security->getToken()->willReturn($token);
     $this->setContext($security);
     $this->setLogger($logger);
     $request->getRequestUri()->willReturn('/api/user/1');
     $request->getMethod()->willReturn('GET');
     $event->getController()->willReturn([$ctrl, 'someAction']);
     $event->getRequest()->willReturn($request);
     $this->onKernelController($event);
 }
開發者ID:Im0rtality,項目名稱:rest-api-bundle,代碼行數:14,代碼來源:LoggingListenerSpec.php


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