123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- class sfBasicSecurityFilter extends sfFilter
- {
-
- public function execute($filterChain)
- {
-
- if (
- (sfConfig::get('sf_login_module') == $this->context->getModuleName()) && (sfConfig::get('sf_login_action') == $this->context->getActionName())
- ||
- (sfConfig::get('sf_secure_module') == $this->context->getModuleName()) && (sfConfig::get('sf_secure_action') == $this->context->getActionName())
- )
- {
- $filterChain->execute();
- return;
- }
-
-
-
- if (!$this->context->getUser()->isAuthenticated())
- {
-
- $this->forwardToLoginAction();
- }
-
- $credential = $this->getUserCredential();
- if (!is_null($credential) && !$this->context->getUser()->hasCredential($credential))
- {
-
- $this->forwardToSecureAction();
- }
-
- $filterChain->execute();
- }
-
- protected function forwardToSecureAction()
- {
- $this->context->getController()->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action'));
- throw new sfStopException();
- }
-
- protected function forwardToLoginAction()
- {
- $this->context->getController()->forward(sfConfig::get('sf_login_module'), sfConfig::get('sf_login_action'));
- throw new sfStopException();
- }
-
- protected function getUserCredential()
- {
- return $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance()->getCredential();
- }
- }
|