Overview

Namespaces

  • Mapbender
    • Component
      • HTTP
    • CoreBundle
      • Command
      • Component
        • Exception
      • Controller
      • DataFixtures
        • ORM
      • DependencyInjection
      • Element
        • Type
      • Entity
      • EventListener
      • Extension
      • Form
        • DataTransformer
        • EventListener
        • Type
      • Security
      • Template
    • KmlBundle
      • Element
    • ManagerBundle
      • Controller
      • Form
        • DataTransformer
        • Type
    • MonitoringBundle
      • Command
      • Component
      • Controller
      • DependencyInjection
      • Entity
      • EventListener
      • Form
    • PrintBundle
      • Component
      • Controller
    • WmcBundle
      • Component
        • Exception
      • Element
        • Type
      • Entity
      • Form
        • Type
    • WmsBundle
      • Component
        • Exception
      • Controller
      • DependencyInjection
      • Element
        • Type
      • Entity
      • Event
      • Form
        • EventListener
        • Type
    • WmtsBundle
      • Component
        • Exception
      • Controller
      • Entity
      • Form
        • Type
  • None
  • PHP

Classes

  • ApplicationController
  • GroupController
  • ProxyController
  • TranslationController
  • WelcomeController
  • Overview
  • Namespace
  • Class
  • Tree
  • Deprecated
  • Todo
  • Download
  1: <?php
  2: 
  3: /**
  4:  * TODO: License
  5:  */
  6: 
  7: namespace Mapbender\CoreBundle\Controller;
  8: 
  9: use Mapbender\CoreBundle\Component\Application;
 10: use Mapbender\CoreBundle\Entity\Application as ApplicationEntity;
 11: use Symfony\Bundle\FrameworkBundle\Controller\Controller;
 12: use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
 13: use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
 14: use Symfony\Component\Security\Core\Exception\AccessDeniedException;
 15: use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
 16: use Symfony\Component\HttpFoundation\Response;
 17: 
 18: /**
 19:  * Application controller.
 20:  *
 21:  * @author Christian Wygoda
 22:  */
 23: class ApplicationController extends Controller {
 24:     /**
 25:      * Get runtime URLs
 26:      *
 27:      * @param string $slug
 28:      * @return array
 29:      */
 30:     private function getUrls($slug) {
 31:         return array(
 32:             'base' => $this->get('request')->getBaseUrl(),
 33:             // @TODO: Can this be done less hack-ish?
 34:             'asset' => rtrim($this->get('templating.helper.assets')
 35:                 ->getUrl('.'), '.'),
 36:             'element' => $this->get('router')
 37:                 ->generate('mapbender_core_application_element', array(
 38:                     'slug' => $slug)),
 39:             'trans' => $this->get('router')
 40:                 ->generate('mapbender_core_translation_trans'),
 41:             'proxy' => $this->get('router')
 42:             ->generate('owsproxy3_core_owsproxy_entrypoint'));
 43:     }
 44: 
 45:     /**
 46:      * Asset controller.
 47:      *
 48:      * Dumps the assets for the given application and type. These are up to
 49:      * date and this controller will be used during development mode.
 50:      *
 51:      * @Route("/application/{slug}/assets/{type}")
 52:      */
 53:     public function assetsAction($slug, $type) {
 54:         $response = new Response();
 55:         $application = $this->getApplication($slug);
 56:         $assets = $application->getAssets($type);
 57:         $asset_modification_time = new \DateTime();
 58:         $asset_modification_time->setTimestamp($assets->getLastModified());
 59: 
 60:         // @TODO: Make filters part of the bundle configuration
 61:         // @TODO: I'd like to have source maps support in here for easier
 62:         //      debugging of minified code, see
 63:         //      http://www.thecssninja.com/javascript/source-mapping
 64:         $filters = array(
 65:             'js' => array(),
 66:             'css' => array($this->container->get('assetic.filter.cssrewrite')));
 67: 
 68:         // Set target path for CSS rewrite to work
 69:         // Replace backward slashes (Windows paths) with forward slashes...
 70:         $target = str_replace('\\', '/', $this->get('request')->server->get('SCRIPT_FILENAME')
 71:             . $this->get('request')->server->get('PATH_INFO'));
 72: 
 73:         $mimetypes = array(
 74:             'css' => 'text/css',
 75:             'js' => 'application/javascript');
 76: 
 77:         $application_update_time = new \DateTime();
 78:         $application_entity = $this->getApplication($slug)->getEntity();
 79: 
 80:         // Determine last-modified timestamp for both DB- and YAML-based apps
 81:         if($application->getEntity()->getSource() === ApplicationEntity::SOURCE_DB) {
 82:             $updateTime = max($application->getEntity()->getUpdated(),
 83:                 $asset_modification_time);
 84:         } else {
 85:             $cacheUpdateTime = new \DateTime($this->container->getParameter('mapbender.cache_creation'));
 86:             $updateTime = max($cacheUpdateTime, $asset_modification_time);
 87:         }
 88: 
 89:         $response->setLastModified($updateTime);
 90:         if($response->isNotModified($this->get('request'))) {
 91:             return $response;
 92:         }
 93: 
 94:         // @TODO: I'd rather use $assets->dump, but that clones each asset
 95:         // which assigns a new weird targetPath. Gotta check that some time.
 96:         $parts = array();
 97:         foreach($assets->all() as $asset) {
 98:             foreach($filters[$type] as $filter) {
 99:                 $asset->ensureFilter($filter);
100:             }
101:             $asset->setTargetPath($target);
102:             $parts[] = $asset->dump();
103:         }
104: 
105: 
106:         $response->headers->set('Content-Type', $mimetypes[$type]);
107:         $response->setContent(implode("\n", $parts));
108:         return $response;
109:     }
110: 
111:     /**
112:      * Element action controller.
113:      *
114:      * Passes the request to the element's httpAction.
115:      * @Route("/application/{slug}/element/{id}/{action}",
116:      *     defaults={ "id" = null, "action" = null },
117:      *     requirements={ "action" = ".+" })
118:      */
119:     public function elementAction($slug, $id, $action) {
120:         $element = $this->getApplication($slug)->getElement($id);
121: 
122:         //$this->checkAllowedRoles($element->getRoles());
123: 
124:         return $element->httpAction($action);
125:     }
126: 
127:     /**
128:      * Main application controller.
129:      *
130:      * @Route("/application/{slug}.{_format}", defaults={ "_format" = "html" })
131:      * @Template()
132:      */
133:     public function applicationAction($slug) {
134:         $application = $this->getApplication($slug);
135: 
136:         // At this point, we are allowed to acces the application. In order
137:         // to use the proxy in following request, we have to mark the session
138:         $this->get("session")->set("proxyAllowed",true);
139: 
140:         return new Response($application->render());
141:     }
142: 
143:     /**
144:      * Get the application by slug.
145:      *
146:      * Tries to get the application with the given slug and throws an 404
147:      * exception if it can not be found. This also checks access control and
148:      * therefore may throw an AuthorizationException.
149:      *
150:      * @return Mapbender\CoreBundle\Component\Application
151:      */
152:     private function getApplication($slug) {
153:         $application = $this->get('mapbender')
154:             ->getApplication($slug, $this->getUrls($slug));
155: 
156:         if($application === null) {
157:             throw new NotFoundHttpException(
158:                 'The application can not be found.');
159:         }
160: 
161:         $this->checkApplicationAccess($application);
162: 
163:         return $application;
164:     }
165: 
166:     /**
167:      * Check access permissions for given application.
168:      *
169:      * This will check if any ACE in the ACL for the given applications entity
170:      * grants the VIEW permission.
171:      *
172:      * @param Application $application
173:      */
174:     public function checkApplicationAccess(Application $application) {
175:         $securityContext = $this->get('security.context');
176: 
177:         $application_entity = $application->getEntity();
178:         if($application_entity::SOURCE_YAML === $application_entity->getSource()
179:                 && count($application_entity->yaml_roles)) {
180:             $passed = false;
181:             foreach($application_entity->yaml_roles as $role) {
182:                 if($securityContext->isGranted($role)) {
183:                     $passed = true;
184:                     break; 
185:                 }
186:             }
187:             if(!$passed) {
188:                 throw new AccessDeniedException('You are not granted view permissions for this application.');
189:             }
190:         }
191: 
192:         $granted = $securityContext->isGranted('VIEW', $application_entity);
193:         if(false === $granted) {
194:             throw new AccessDeniedException('You are not granted view permissions for this application.');
195:         }
196: 
197:         if(!$application_entity->isPublished() and !$securityContext->isGranted('EDIT', $application_entity)) {
198:             throw new AccessDeniedException('This application is not published at the moment');
199:         }
200:     }
201: }
202: 
203: 
Mapbender3 API documenation API documentation generated by ApiGen 2.8.0