This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Role based caching

  • Loading branch information...
Marco Bohler
Marco Bohler committed Oct 30, 2012
1 parent bb08f4c commit bffc9fae5b24797eb46772d8a8206e429c70dc89
@@ -47,6 +47,7 @@ private function addRulesSection(ArrayNodeDefinition $rootNode)
->arrayNode('rules')
->prototype('array')
->children()
+ ->scalarNode('role')->defaultNull()->end()
->scalarNode('path')->defaultNull()->end()
->scalarNode('domain')->defaultNull()->end()
->scalarNode('reverse_proxy_ttl')->defaultNull()->end()
@@ -6,6 +6,7 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\Security\Core\SecurityContext;
/**
* Set caching settings on the reponse according to the app config
@@ -16,6 +17,8 @@
*/
class CacheControlListener
{
+ protected $securityContext;
+
protected $map = array();
/**
@@ -28,6 +31,14 @@ class CacheControlListener
/**
* Constructor.
*
+ * @param \Symfony\Component\Security\Core\SecurityContext $securityContext
+ */
+ public function __construct(SecurityContext $securityContext = null)
+ {
+ $this->securityContext = $securityContext;
+ }
+
+ /**
* @param RequestMatcherInterface $requestMatcher A RequestMatcherInterface instance
* @param array $options An array of options
*/
@@ -114,6 +125,13 @@ protected function setExtraControls(Response $response, array $controls)
protected function getOptions(Request $request)
{
foreach ($this->map as $elements) {
+ if (!empty($elements[1]['role'])
+ && $this->securityContext
+ && $this->securityContext->isGranted($elements[1]['role'])
+ ) {
+ continue;
+ }
+
if (null === $elements[0] || $elements[0]->matches($request)) {
return $elements[1];
}
@@ -8,6 +8,7 @@
<service id="liip_cache_control.response_listener" class="Liip\CacheControlBundle\EventListener\CacheControlListener">
<tag name="kernel.event_listener" event="kernel.response" method="onKernelResponse" />
+ <argument type="service" id="security.context" on-invalid="ignore"/>
</service>
<service id="liip_cache_control.request_matcher" class="Symfony\Component\HttpFoundation\RequestMatcher" public="false" />

0 comments on commit bffc9fa

Please sign in to comment.