Ejemplo n.º 1
0
 /**
  * @param Request $request
  * @param Closure $next
  *
  * @return array|mixed|string
  */
 public function handle($request, Closure $next)
 {
     //  Allow console requests through
     if (env('DF_IS_VALID_CONSOLE_REQUEST', false)) {
         return $next($request);
     }
     try {
         static::setExceptions();
         if (static::isAccessAllowed()) {
             return $next($request);
         } elseif (static::isException($request)) {
             //API key and/or (non-admin) user logged in, but if access is still not allowed then check for exception case.
             return $next($request);
         } else {
             $apiKey = Session::getApiKey();
             $token = Session::getSessionToken();
             if (empty($apiKey) && empty($token)) {
                 throw new BadRequestException('Bad request. No token or api key provided.');
             } elseif (true === Session::get('token_expired')) {
                 throw new UnauthorizedException(Session::get('token_expired_msg'));
             } elseif (!Session::isAuthenticated()) {
                 throw new UnauthorizedException('Unauthorized.');
             } else {
                 throw new ForbiddenException('Access Forbidden.');
             }
         }
     } catch (\Exception $e) {
         return ResponseFactory::getException($e, $request);
     }
 }
Ejemplo n.º 2
0
 public function testSystemLookupWithApiKey()
 {
     $app = App::find(1);
     $apiKey = $app->api_key;
     Lookup::create($this->systemLookup[0]);
     $this->call(Verbs::GET, '/api/v2/system/environment?api_key=' . $apiKey);
     $this->assertEquals(Arr::get($this->systemLookup, '0.value'), Session::get('lookup.host'));
 }
Ejemplo n.º 3
0
 public function testApiKeyUserRole()
 {
     $user = ['name' => 'John Doe', 'first_name' => 'John', 'last_name' => 'Doe', 'email' => '*****@*****.**', 'password' => 'test1234', 'security_question' => 'Make of your first car?', 'security_answer' => 'mazda', 'is_active' => true];
     $role = ['name' => 'test_role', 'is_active' => true, 'role_service_access_by_role_id' => [['service_id' => 1, 'component' => 'config', 'verb_mask' => 1, 'requestor_mask' => 1]]];
     $this->service = ServiceHandler::getService('system');
     $rs = $this->makeRequest(Verbs::POST, 'user', [], [$user]);
     $data = $rs->getContent();
     $userId = Arr::get($data, static::$wrapper . '.0.id');
     $this->service = ServiceHandler::getService('system');
     $rs = $this->makeRequest(Verbs::POST, 'role', [], [$role]);
     $data = $rs->getContent();
     $roleId = Arr::get($data, static::$wrapper . '.0.id');
     \DreamFactory\Core\Models\UserAppRole::create(['user_id' => $userId, 'app_id' => 1, 'role_id' => $roleId]);
     $app = App::find(1);
     $apiKey = $app->api_key;
     $myUser = User::find($userId);
     $token = JWTUtilities::makeJWTByUser($myUser->id, $myUser->email);
     $this->call(Verbs::GET, '/api/v2/system', [], [], [], ['HTTP_X_DREAMFACTORY_API_KEY' => $apiKey, 'HTTP_X_DREAMFACTORY_SESSION_TOKEN' => $token]);
     $this->assertFalse(Session::isSysAdmin());
     $this->assertEquals($roleId, Session::get('role.id'));
     $rsa = Session::get('role.services');
     $this->assertTrue(!empty($rsa));
 }
Ejemplo n.º 4
0
 public static function get($key, $default = null)
 {
     return \Session::get($key, $default);
 }