コード例 #1
0
 /**
  * This function gets the current user object and needs to validate its access against the required roles.
  * The function must either return ACCESS_GRANTED, ACCESS_ABSTAIN or ACCESS_DENIED.
  *
  * @param UserAbstract $user           Current user instance.
  * @param array        $requestedRoles An array of requested roles for the current access map.
  *
  * @return integer ACCESS_GRANTED, ACCESS_ABSTAIN or ACCESS_DENIED.
  */
 public function vote(UserAbstract $user, array $requestedRoles)
 {
     $result = self::ACCESS_DENIED;
     if ($user->isAuthenticated()) {
         $result = self::ACCESS_GRANTED;
     }
     return $result;
 }
コード例 #2
0
 /**
  * Stores user data into an array, encrypts it and returns the encrypted string.
  *
  * @param UserAbstract $user Instance of UserAbstract class that holds the pre-filled object from user provider.
  *
  * @return string
  */
 public function encryptUserData(UserAbstract $user)
 {
     // extract the roles
     $roles = $user->getRoles();
     $roleArray = [];
     foreach ($roles as $r) {
         $roleArray[] = $r->getRole();
     }
     // data (we use short syntax to reduce the size of the cookie or session)
     $data = ['u' => $user->getUsername(), 'r' => $roleArray, 'vu' => time() + 86400 * 30, 'sid' => $this->httpSession()->getSessionId(), 'ap' => $user->getAuthProviderName()];
     // build and add token to $data
     return $this->getCrypt()->encrypt($this->jsonEncode($data), $this->getEncryptionKey());
 }
コード例 #3
0
ファイル: RoleVoter.php プロジェクト: Nkelliny/Framework
 /**
  * This function gets the current user object and needs to validate its access against the required roles.
  * The function must either return ACCESS_GRANTED, ACCESS_ABSTAIN or ACCESS_DENIED.
  *
  * @param UserAbstract $user           Current user instance.
  * @param array        $requestedRoles An array of requested roles for the current access map.
  *
  * @return integer ACCESS_GRANTED, ACCESS_ABSTAIN or ACCESS_DENIED.
  */
 public function vote(UserAbstract $user, array $requestedRoles)
 {
     $result = self::ACCESS_ABSTAIN;
     $userRoles = $user->getRoles();
     foreach ($requestedRoles as $role) {
         if (!$this->supportsRole($role)) {
             continue;
         }
         $result = self::ACCESS_DENIED;
         foreach ($userRoles as $ur) {
             /**
              * @var $ur Role
              */
             if ($role->getRole() === $ur->getRole()) {
                 return self::ACCESS_GRANTED;
             }
         }
     }
     return $result;
 }
コード例 #4
0
ファイル: AnonymousUser.php プロジェクト: Nkelliny/Framework
 /**
  * Base constructor.
  */
 public function __construct()
 {
     parent::populate('anonymous', '', [], false);
 }
コード例 #5
0
ファイル: Firewall.php プロジェクト: Nkelliny/Framework
 /**
  * Sets roles for current user.
  */
 private function setUserRoles()
 {
     $this->initRoleHierarchy();
     $this->user->setRoles($this->roleHierarchy->getAccessibleRoles($this->user->getRoles()));
 }