public function testHandlesWhenUserIsNotAdmin()
 {
     $this->session->IsAdmin = false;
     $this->server->expects($this->at(0))->method('GetHeader')->with($this->equalTo(WebServiceHeaders::SESSION_TOKEN))->will($this->returnValue($this->sessionToken));
     $this->server->expects($this->at(1))->method('GetHeader')->with($this->equalTo(WebServiceHeaders::USER_ID))->will($this->returnValue($this->userId));
     $this->userSessionRepository->expects($this->once())->method('LoadBySessionToken')->with($this->equalTo($this->sessionToken))->will($this->returnValue($this->session));
     $wasHandled = $this->security->HandleSecureRequest($this->server, true);
     $this->assertFalse($wasHandled);
     $this->assertFalse($this->session->_SessionExtended);
 }
Exemple #2
0
$app = new \Slim\Slim();
$server = new SlimServer($app);
$registry = new SlimWebServiceRegistry($app);
RegisterHelp($registry, $app);
RegisterAuthentication($server, $registry);
RegisterReservations($server, $registry);
RegisterResources($server, $registry);
RegisterUsers($server, $registry);
RegisterSchedules($server, $registry);
RegisterAttributes($server, $registry);
RegisterGroups($server, $registry);
RegisterAccessories($server, $registry);
$app->hook('slim.before.dispatch', function () use($app, $server, $registry) {
    $routeName = $app->router()->getCurrentRoute()->getName();
    if ($registry->IsSecure($routeName)) {
        $security = new WebServiceSecurity(new UserSessionRepository());
        $wasHandled = $security->HandleSecureRequest($server, $registry->IsLimitedToAdmin($routeName));
        if (!$wasHandled) {
            $app->halt(RestResponse::UNAUTHORIZED_CODE, 'You must be authenticated in order to access this service.<br/>' . $server->GetFullServiceUrl(WebServices::Login));
        }
    }
});
$app->error(function (\Exception $e) use($app) {
    require_once ROOT_DIR . 'lib/Common/Logging/Log.php';
    Log::Error('Slim Exception. %s', $e);
    $app->response()->header('Content-Type', 'application/json');
    $app->response()->status(RestResponse::SERVER_ERROR);
    $app->response()->write('Exception was logged.');
});
$app->run();
function RegisterHelp(SlimWebServiceRegistry $registry, \Slim\Slim $app)