Tilman Koester
Tilman Koester

Reputation: 1739

PHP Symfony - Inside Filter, check if action is_secure'd?

How do I check if the action I am calling was secured in security.yml?

security.yml

myAction:
  is_secure: false

filter.yml

myFilter:
  class: myFilter

Now inside myFilter i want to check if the action was secured or not.

class myFilter extends sfFilter
{
  public function execute($filterChain)
  {
    if ($this->getContext()->is_secure === false) {
      $filterChain->execute();
    }
    // ...
  }
}

Upvotes: 1

Views: 1586

Answers (2)

Loris Guignard
Loris Guignard

Reputation: 151

The proper way to handle this is to set the type of your filter as security:

myFilter:
  class: myFilter
  param:
    type: security

Your filter will only be executed on secured (is_secure: true) actions. Take a look at the sfFilterConfigHandler.class.php source code for more information.

Upvotes: 2

greg0ire
greg0ire

Reputation: 23255

greg@liche :) ~/source/symfony/1.4 > ack "public function isSecure" --type="php"
lib/request/sfWebRequest.class.php
545:  public function isSecure()

lib/action/sfAction.class.php
407:  public function isSecure()

test/unit/helper/AssetHelperTest.php
29:  public function isSecure()

test/unit/helper/UrlHelperTest.php
30:  public function isSecure()
greg@liche :( ~/source/symfony/1.4 > ack "public function getAction\(" --type="php"
lib/controller/sfController.class.php
258:  public function getAction($moduleName, $actionName)
greg@liche :) ~/source/symfony/1.4 > ack "public function getController\(" --type="php"
lib/util/sfContext.class.php
243:   public function getController(

)

Which means that $this->getContext()->getController()->getAction()->isSecure() should do it.

Upvotes: 2

Related Questions