/**
  * This runs all the security checks before a method call. The
  * security checks are determined by inspecting the controller method
  * annotations
  * @param string/Controller $controller the controllername or string
  * @param string $methodName the name of the method
  * @throws SecurityException when a security check fails
  */
 public function beforeController($controller, $methodName)
 {
     // get annotations from comments
     $annotationReader = new MethodAnnotationReader($controller, $methodName);
     // this will set the current navigation entry of the app, use this only
     // for normal HTML requests and not for AJAX requests
     $this->app->getServer()->getNavigationManager()->setActiveEntry($this->app->getAppName());
     // security checks
     $isPublicPage = $annotationReader->hasAnnotation('PublicPage');
     if (!$isPublicPage) {
         if (!$this->app->isLoggedIn()) {
             throw new SecurityException('Current user is not logged in', Http::STATUS_UNAUTHORIZED);
         }
         if (!$annotationReader->hasAnnotation('NoAdminRequired')) {
             if (!$this->app->isAdminUser()) {
                 throw new SecurityException('Logged in user must be an admin', Http::STATUS_FORBIDDEN);
             }
         }
     }
     if (!$annotationReader->hasAnnotation('NoCSRFRequired')) {
         if (!$this->request->passesCSRFCheck()) {
             throw new SecurityException('CSRF check failed', Http::STATUS_PRECONDITION_FAILED);
         }
     }
 }
Пример #2
0
 /**
  * Shortcut for rendering a template
  * @param string $templateName the name of the template
  * @param array $params the template parameters in key => value structure
  * @param string $renderAs user renders a full page, blank only your template
  *                          admin an entry in the admin settings
  * @param array $headers set additional headers in name/value pairs
  * @return \OCP\AppFramework\Http\TemplateResponse containing the page
  */
 public function render($templateName, array $params = array(), $renderAs = 'user', array $headers = array())
 {
     $response = new TemplateResponse($this->app->getAppName(), $templateName);
     $response->setParams($params);
     $response->renderAs($renderAs);
     foreach ($headers as $name => $value) {
         $response->addHeader($name, $value);
     }
     return $response;
 }
Пример #3
0
 public function testContainerAppName()
 {
     $this->app = new Application();
     $this->assertEquals('activity', $this->container->getAppName());
 }
Пример #4
0
 /**
  * @param IAppContainer $c
  */
 public function registerBackends(IAppContainer $c)
 {
     $l10n = $c->getServer()->getL10N($c->getAppName());
     // Local backend: Default database backend
     $this->backends->queue(function () use($c, $l10n) {
         return $this->backendFactory->createBackend('org.ownCloud.local', $this->backends, function () use($l10n) {
             return new Calendar\Backend\Local\Backend($l10n);
         }, function (Calendar\IBackend $backend) use($c) {
             $db = $c->getServer()->getDatabaseConnection();
             $factory = $c->query('CalendarFactory');
             return new Calendar\Backend\Local\Calendar($db, $backend, $factory);
         }, function (Calendar\ICalendar $calendar) use($c) {
             $db = $c->getServer()->getDatabaseConnection();
             $factory = $c->query('ObjectFactory');
             return new Calendar\Backend\Local\Object($db, $calendar, $factory);
         });
     });
     // Contacts backend: show contact's birthdays and anniversaries
     $contactsManager = $c->getServer()->getContactsManager();
     $this->backends->queue(function () use($c, $l10n, $contactsManager) {
         return $this->backendFactory->createBackend('org.ownCloud.contact', $this->backends, function () use($c, $contactsManager) {
             $appManager = $c->getServer()->getAppManager();
             return new Calendar\Backend\Contact\Backend($contactsManager, $appManager);
         }, function (Calendar\IBackend $backend) use($c, $contactsManager) {
             $l10n = $c->getServer()->getL10N('calendar');
             $calendarFactory = $c->query('CalendarFactory');
             return new Calendar\Backend\Contact\Calendar($contactsManager, $backend, $l10n, $calendarFactory);
         }, function (Calendar\ICalendar $calendar) use($c, $contactsManager) {
             $l10n = $c->getServer()->getL10N('calendar');
             $objectFactory = $c->query('ObjectFactory');
             return new Calendar\Backend\Contact\Object($contactsManager, $calendar, $l10n, $objectFactory);
         });
     });
     // Sharing backend: Enabling users to share calendars
     if (Share::isEnabled() && false) {
         $this->backends->queue(function () use($c, $l10n) {
             return $this->backendFactory->createBackend('org.ownCloud.sharing', $this->backends, function () {
                 return new Calendar\Backend\Sharing\Backend();
             }, function (Calendar\IBackend $backend) {
                 return new Calendar\Backend\Sharing\Calendar($backend);
             }, function (Calendar\ICalendar $calendar) {
                 return new Calendar\Backend\Sharing\Object($calendar);
             });
         });
     }
     // Webcal Backend: Show ICS files on the net
     if (function_exists('curl_init')) {
         $this->backends->queue(function () use($c, $l10n) {
             return $this->backendFactory->createBackend('org.ownCloud.webcal', $this->backends, function () use($c, $l10n) {
                 $subscriptions = $c->query('SubscriptionBusinessLayer');
                 $cacheFactory = $c->getServer()->getMemCacheFactory();
                 return new Calendar\Backend\WebCal\Backend($subscriptions, $l10n, $cacheFactory);
             }, function (Calendar\IBackend $backend) use($c, $l10n) {
                 $subscriptions = $c->query('SubscriptionBusinessLayer');
                 $cacheFactory = $c->getServer()->getMemCacheFactory();
                 $calendarFactory = $c->query('CalendarFactory');
                 return new Calendar\Backend\WebCal\Calendar($subscriptions, $l10n, $cacheFactory, $backend, $calendarFactory);
             }, function (Calendar\ICalendar $calendar) use($c, $l10n) {
                 $subscriptions = $c->query('SubscriptionBusinessLayer');
                 $cacheFactory = $c->getServer()->getMemCacheFactory();
                 $objectFactory = $c->query('ObjectFactory');
                 return new Calendar\Backend\WebCal\Object($subscriptions, $l10n, $cacheFactory, $calendar, $objectFactory);
             });
         });
     }
 }
 public function testContainerAppName()
 {
     $this->app = new Application();
     $this->assertEquals('announcementcenter', $this->container->getAppName());
 }