| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
class sfBasicSecurityFilter extends sfFilter |
|---|
| 24 |
{ |
|---|
| 25 |
|
|---|
| 26 |
* Executes this filter. |
|---|
| 27 |
* |
|---|
| 28 |
* @param sfFilterChain $filterChain A sfFilterChain instance |
|---|
| 29 |
*/ |
|---|
| 30 |
public function execute($filterChain) |
|---|
| 31 |
{ |
|---|
| 32 |
|
|---|
| 33 |
if ( |
|---|
| 34 |
(sfConfig::get('sf_login_module') == $this->context->getModuleName()) && (sfConfig::get('sf_login_action') == $this->context->getActionName()) |
|---|
| 35 |
|| |
|---|
| 36 |
(sfConfig::get('sf_secure_module') == $this->context->getModuleName()) && (sfConfig::get('sf_secure_action') == $this->context->getActionName()) |
|---|
| 37 |
) |
|---|
| 38 |
{ |
|---|
| 39 |
$filterChain->execute(); |
|---|
| 40 |
|
|---|
| 41 |
return; |
|---|
| 42 |
} |
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
// is vague enough to describe any level of security and can be |
|---|
| 46 |
// used to retrieve such data and should never have to be altered |
|---|
| 47 |
if (!$this->context->getUser()->isAuthenticated()) |
|---|
| 48 |
{ |
|---|
| 49 |
|
|---|
| 50 |
$this->forwardToLoginAction(); |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
|
|---|
| 54 |
$credential = $this->getUserCredential(); |
|---|
| 55 |
if (!is_null($credential) && !$this->context->getUser()->hasCredential($credential)) |
|---|
| 56 |
{ |
|---|
| 57 |
|
|---|
| 58 |
$this->forwardToSecureAction(); |
|---|
| 59 |
} |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
$filterChain->execute(); |
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
|
|---|
| 66 |
* Forwards the current request to the secure action. |
|---|
| 67 |
* |
|---|
| 68 |
* @throws sfStopException |
|---|
| 69 |
*/ |
|---|
| 70 |
protected function forwardToSecureAction() |
|---|
| 71 |
{ |
|---|
| 72 |
$this->context->getController()->forward(sfConfig::get('sf_secure_module'), sfConfig::get('sf_secure_action')); |
|---|
| 73 |
|
|---|
| 74 |
throw new sfStopException(); |
|---|
| 75 |
} |
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
* Forwards the current request to the login action. |
|---|
| 79 |
* |
|---|
| 80 |
* @throws sfStopException |
|---|
| 81 |
*/ |
|---|
| 82 |
protected function forwardToLoginAction() |
|---|
| 83 |
{ |
|---|
| 84 |
$this->context->getController()->forward(sfConfig::get('sf_login_module'), sfConfig::get('sf_login_action')); |
|---|
| 85 |
|
|---|
| 86 |
throw new sfStopException(); |
|---|
| 87 |
} |
|---|
| 88 |
|
|---|
| 89 |
|
|---|
| 90 |
* Returns the credential required for this action. |
|---|
| 91 |
* |
|---|
| 92 |
* @return mixed The credential required for this action |
|---|
| 93 |
*/ |
|---|
| 94 |
protected function getUserCredential() |
|---|
| 95 |
{ |
|---|
| 96 |
return $this->context->getController()->getActionStack()->getLastEntry()->getActionInstance()->getCredential(); |
|---|
| 97 |
} |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|