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