开发者

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();
    }
开发者_StackOverflow    // ...
  }
}


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜