当前位置: 首页>>代码示例>>PHP>>正文


PHP UserInterface::getRoles方法代码示例

本文整理汇总了PHP中Symfony\Component\Security\Core\User\UserInterface::getRoles方法的典型用法代码示例。如果您正苦于以下问题:PHP UserInterface::getRoles方法的具体用法?PHP UserInterface::getRoles怎么用?PHP UserInterface::getRoles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Symfony\Component\Security\Core\User\UserInterface的用法示例。


在下文中一共展示了UserInterface::getRoles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: isGranted

 /**
  * 
  * @param string $attribute
  * @param Club $club
  * @param UserInterface $user
  * @return boolean
  */
 protected function isGranted($attribute, $club, $user = null)
 {
     switch ($attribute) {
         case self::VIEW:
             if (!$club->isPrivate()) {
                 return true;
             }
             // make sure there is a user object (i.e. that the user is logged in)
             if (!$user instanceof UserInterface) {
                 return false;
             }
             if (in_array('ROLE_ADMIN', $user->getRoles())) {
                 return true;
             }
             break;
         case self::EDIT:
             // make sure there is a user object (i.e. that the user is logged in)
             if (!$user instanceof UserInterface) {
                 return false;
             }
             foreach ($club->getAdministrators() as $administrator) {
                 if ($administrator->getId() == $user->getId()) {
                     return true;
                 }
             }
             if (in_array('ROLE_ADMIN', $user->getRoles())) {
                 return true;
             }
             return false;
         case self::CREATE:
             break;
     }
     return false;
 }
开发者ID:oesteve,项目名称:grupeta,代码行数:41,代码来源:ClubVoter.php

示例2: isEqualTo

 public function isEqualTo(UserInterface $user)
 {
     if ($user instanceof User) {
         // Check that the roles are the same, in any order
         $isEqual = count($this->getRoles()) == count($user->getRoles());
         if ($isEqual) {
             foreach ($this->getRoles() as $role) {
                 $isEqual = $isEqual && in_array($role, $user->getRoles());
             }
         }
         return $isEqual;
     }
     return false;
 }
开发者ID:Jujuwar,项目名称:bruminator2.0,代码行数:14,代码来源:User.php

示例3: authenticateUser

 private function authenticateUser(UserInterface $user)
 {
     $providerKey = 'secured_area';
     // your firewall name
     $token = new UsernamePasswordToken($user, null, $providerKey, $user->getRoles());
     $this->getSecurityContext()->setToken($token);
 }
开发者ID:bamper,项目名称:symfony2-ep4,代码行数:7,代码来源:RegisterController.php

示例4: logUser

 private function logUser(UserInterface $user, $password)
 {
     $token = new UsernamePasswordToken($user, $password, 'secured_area', $user->getRoles());
     $request = $this->getRequest();
     $session = $request->getSession();
     $session->set('_security_secured_area', serialize($token));
 }
开发者ID:astrakel,项目名称:web,代码行数:7,代码来源:UHUSecurityController.php

示例5: isEqualTo

 public function isEqualTo(UserInterface $user)
 {
     if (!$user instanceof LdapUser || $user->getUsername() !== $this->username || $user->getEmail() !== $this->email || count(array_diff($user->getRoles(), $this->roles)) > 0 || $user->getDn() !== $this->dn) {
         return false;
     }
     return true;
 }
开发者ID:redventures-oss,项目名称:LdapBundle,代码行数:7,代码来源:LdapUser.php

示例6: processRecord

 /**
  * @param array $record
  *
  * @return array
  */
 public function processRecord(array $record)
 {
     if (is_null($this->user)) {
         /* @var TokenStorageInterface $securityTokenStorage */
         $securityTokenStorage = $this->container->get('security.token_storage');
         if ($securityTokenStorage !== null && $securityTokenStorage->getToken() !== null && $securityTokenStorage->getToken()->getUser() instanceof \Symfony\Component\Security\Core\User\AdvancedUserInterface) {
             $this->user = $securityTokenStorage->getToken()->getUser();
             $this->record['extra']['user']['username'] = $this->user->getUsername();
             $this->record['extra']['user']['roles'] = $this->user->getRoles();
             $this->record['extra']['user']['is_account_non_expired'] = $this->user->isAccountNonExpired();
             $this->record['extra']['user']['is_account_non_locked'] = $this->user->isAccountNonLocked();
             $this->record['extra']['user']['is_credentials_non_expired'] = $this->user->isCredentialsNonExpired();
             $this->record['extra']['user']['is_enabled'] = $this->user->isEnabled();
         }
     }
     return array_merge($record, $this->record);
 }
开发者ID:BranchBit,项目名称:KunstmaanBundlesCMS,代码行数:22,代码来源:UserProcessor.php

示例7: check

 /**
  * Check whether a user is granted a specific role, respecting the role hierarchy.
  *
  * @param UserInterface $user
  * @param $requiredRole
  * @return bool Whether this user is granted the $requiredRole
  */
 public function check(UserInterface $user, $requiredRole)
 {
     $roles = array();
     foreach ($user->getRoles() as $roleName) {
         $roles[] = new Role($roleName);
     }
     $token = new AnonymousToken('dummy', 'dummy', $roles);
     return static::ACCESS_GRANTED == $this->vote($token, null, array($requiredRole));
 }
开发者ID:Wolframcheg,项目名称:symfonyblog,代码行数:16,代码来源:RoleHierarchyChecker.php

示例8: __construct

 public function __construct(UserInterface $user, $providerKey)
 {
     parent::__construct($user->getRoles());
     if (empty($providerKey)) {
         throw new \InvalidArgumentException('$providerKey must not be empty.');
     }
     $this->providerKey = $providerKey;
     $this->setUser($user);
     parent::setAuthenticated(true);
 }
开发者ID:Giant-Peach-Design,项目名称:LiipMagentoBundle,代码行数:10,代码来源:MagentoToken.php

示例9: __construct

 public function __construct($providerKey, UserInterface $user = null)
 {
     if ($user) {
         parent::__construct($user->getRoles());
         $this->setUser($user);
     } else {
         parent::__construct();
     }
     $this->providerKey = $providerKey;
 }
开发者ID:xphere,项目名称:one-time-access-bundle,代码行数:10,代码来源:Token.php

示例10: isGranted

 /**
  * Returns true if $user is granted $requiredRole
  * @param $requiredRole
  * @param UserInterface $user
  * @return bool
  */
 public function isGranted($requiredRole, UserInterface $user)
 {
     $requiredRole = new Role($requiredRole);
     foreach ($user->getRoles() as $role) {
         $hierarchy = $this->roleHierarchy->getReachableRoles([new Role($role)]);
         if (in_array($requiredRole, $hierarchy)) {
             return true;
         }
     }
     return false;
 }
开发者ID:NathanVss,项目名称:oauth-extension-bundle,代码行数:17,代码来源:RoleGrant.php

示例11: getSecurityRole

 /**
  * Get security role depending on the roles of the user
  *
  * @param \Symfony\Component\Security\Core\User\UserInterface $user
  * @return string
  */
 protected function getSecurityRole(UserInterface $user)
 {
     $securityRole = 'ROLE_SYSTEM_ADMIN';
     foreach ($user->getRoles() as $role) {
         if (in_array($role, $this->adminRoles)) {
             $securityRole = 'ROLE_ADMIN';
             break;
         }
     }
     return $securityRole;
 }
开发者ID:joeflack4,项目名称:OpitHrm,代码行数:17,代码来源:UserACLCommand.php

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

示例13: processRecord

 /**
  * @param array $record
  *
  * @return array
  */
 public function processRecord(array $record)
 {
     if (is_null($this->user)) {
         /* @var SecurityContextInterface $securityContext */
         $securityContext = null;
         try {
             $this->container->get("security.context");
         } catch (ServiceCircularReferenceException $e) {
             //since the securitycontext is deprecated getting the context from the container results in a log line which tries to use this method again....
         }
         if ($securityContext !== null && $securityContext->getToken() !== null && $securityContext->getToken()->getUser() instanceof \Symfony\Component\Security\Core\User\AdvancedUserInterface) {
             $this->user = $securityContext->getToken()->getUser();
             $this->record['extra']['user']['username'] = $this->user->getUsername();
             $this->record['extra']['user']['roles'] = $this->user->getRoles();
             $this->record['extra']['user']['is_account_non_expired'] = $this->user->isAccountNonExpired();
             $this->record['extra']['user']['is_account_non_locked'] = $this->user->isAccountNonLocked();
             $this->record['extra']['user']['is_credentials_non_expired'] = $this->user->isCredentialsNonExpired();
             $this->record['extra']['user']['is_enabled'] = $this->user->isEnabled();
         }
     }
     return array_merge($record, $this->record);
 }
开发者ID:axelvnk,项目名称:KunstmaanBundlesCMS,代码行数:27,代码来源:UserProcessor.php

示例14: authenticate

 /**
  * Creates an authenticated client against a firewall.
  *
  * @param Symfony\Component\Security\Core\User\UserInterface $user
  * @param string $firewall
  * @return Symfony\Bundle\FrameworkBundle\Client
  */
 protected function authenticate(UserInterface $user, $firewall)
 {
     $securityKey = sprintf('_security_%s', $firewall);
     $client = $this->getClient();
     $client->followRedirects(false);
     $session = $client->getContainer()->get('session');
     $session->start();
     $cookie = new Cookie($session->getName(), $session->getId());
     $client->getCookieJar()->set($cookie);
     $token = new UsernamePasswordToken($user, null, $firewall, $user->getRoles());
     $session->set($securityKey, serialize($token));
     $session->save();
     return $client;
 }
开发者ID:brightmarch,项目名称:testing-bundle,代码行数:21,代码来源:TestCase.php

示例15: equals

 public function equals(UserInterface $user)
 {
     if (!$user instanceof LdapUser) {
         return false;
     }
     if ($user->getUsername() !== $this->username) {
         return false;
     }
     if ($user->getEmail() !== $this->email) {
         return false;
     }
     if ($user->getRoles() !== $this->roles) {
         return false;
     }
     if ($user->getDn() !== $this->dn) {
         return false;
     }
     return true;
 }
开发者ID:rtoledof,项目名称:LdapBundle,代码行数:19,代码来源:LdapUser.php


注:本文中的Symfony\Component\Security\Core\User\UserInterface::getRoles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。