Exemple #1
0
 /**
  * Returns role info cached, or reads from db if not present.
  * Pass in a key to return a portion/index of the cached data.
  *
  * @param int         $id
  * @param null|string $key
  * @param null        $default
  *
  * @return mixed|null
  */
 public static function getCachedInfo($id, $key = null, $default = null)
 {
     $cacheKey = 'role:' . $id;
     try {
         $result = \Cache::remember($cacheKey, \Config::get('df.default_cache_ttl'), function () use($id) {
             $role = Role::with(['role_lookup_by_role_id', 'role_service_access_by_role_id', 'service_by_role_service_access'])->whereId($id)->first();
             if (empty($role)) {
                 throw new NotFoundException("Role not found.");
             }
             $roleInfo = $role->toArray();
             $services = ArrayUtils::get($roleInfo, 'service_by_role_service_access');
             unset($roleInfo['service_by_role_service_access']);
             foreach ($roleInfo['role_service_access_by_role_id'] as $key => $value) {
                 $serviceName = ArrayUtils::findByKeyValue($services, 'id', ArrayUtils::get($value, 'service_id'), 'name');
                 $component = ArrayUtils::get($value, 'component');
                 $roleInfo['role_service_access_by_role_id'][$key]['service'] = $serviceName;
                 $roleInfo['role_service_access_by_role_id'][$key]['component'] = trim($component, '/');
             }
             return $roleInfo;
         });
         if (is_null($result)) {
             return $default;
         }
     } catch (ModelNotFoundException $ex) {
         return $default;
     }
     if (is_null($key)) {
         return $result;
     }
     return isset($result[$key]) ? $result[$key] : $default;
 }
Exemple #2
0
 /** @inheritdoc */
 public function getRole()
 {
     if (ArrayUtils::get($this->config, 'map_group_to_role', false)) {
         $groups = $this->driver->getGroups();
         $primaryGroupDn = ArrayUtils::findByKeyValue($groups, 'primary', true, 'dn');
         $role = RoleADLdap::whereDn($primaryGroupDn)->first();
         if (empty($role)) {
             foreach ($groups as $group) {
                 $groupDn = ArrayUtils::get($group, 'dn');
                 $role = RoleADLdap::whereDn($groupDn)->first();
                 if (!empty($role)) {
                     return $role->role_id;
                 }
             }
             return $this->defaultRole;
         }
         return $role->role_id;
     }
     return $this->defaultRole;
 }
Exemple #3
0
 /**
  * @param array $resources
  *
  * @return bool|mixed
  * @throws BadRequestException
  * @throws InternalServerErrorException
  * @throws NotFoundException
  */
 protected function handleResource(array $resources)
 {
     $found = ArrayUtils::findByKeyValue($resources, 'name', $this->resource);
     if (isset($found, $found['class_name'])) {
         $className = $found['class_name'];
         if (!class_exists($className)) {
             throw new InternalServerErrorException('Service configuration class name lookup failed for resource ' . $this->resourcePath);
         }
         /** @var ResourceInterface $resource */
         $resource = $this->instantiateResource($className, $found);
         $newPath = $this->resourceArray;
         array_shift($newPath);
         $newPath = implode('/', $newPath);
         return $resource->handleRequest($this->request, $newPath);
     }
     throw new NotFoundException("Resource '{$this->resource}' not found for service '{$this->name}'.");
 }