DBSecurityFilter.class.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. class DBSecurityFilter extends sfBasicSecurityFilter
  3. {
  4. protected function getUserCredentials()
  5. {
  6. $c = new Criteria();
  7. $c->add(LinksTablePeer::ACTION_NAME,$this->context->getActionName());
  8. $c->add(LinksTablePeer::MODULE_NAME,$this->context->getModuleName());
  9. $link = LinksTablePeer::doSelectOne($c);
  10. // if (! @($link->getId()) )
  11. // $this->forwardToSecureAction();
  12. $gids = PermissionsTablePeer::getGidsForLink($link->getId());
  13. return $gids;
  14. }
  15. public function execute($filterChain)
  16. {
  17. // disable security on login and secure actions
  18. if (
  19. (sfConfig::get('sf_login_module') == $this->context->getModuleName()) && (sfConfig::get('sf_login_action') == $this->context->getActionName())
  20. ||
  21. (sfConfig::get('sf_secure_module') == $this->context->getModuleName()) && (sfConfig::get('sf_secure_action') == $this->context->getActionName())
  22. )
  23. {
  24. $filterChain->execute();
  25. return;
  26. }
  27. // NOTE: the nice thing about the Action class is that getCredential()
  28. // is vague enough to describe any level of security and can be
  29. // used to retrieve such data and should never have to be altered
  30. if (!$this->context->getUser()->isAuthenticated())
  31. {
  32. // the user is not authenticated
  33. $this->forwardToLoginAction();
  34. }
  35. // the user is authenticated
  36. $credentials = $this->getUserCredentials();
  37. //var_dump($credentials);var_dump($this->context->getUser()->listCredentials());
  38. foreach($credentials as $credential)
  39. {
  40. // checking for administrators
  41. if ($credential == 'www')
  42. if ( $this->context->getUser()->getAttribute('www') ) {
  43. // o, it's the admin!
  44. $filterChain->execute();
  45. return;
  46. } else break; // you can't argue with 'www' :(
  47. if (!is_null($credential) && $this->context->getUser()->hasCredential($credential))
  48. {
  49. // the user has access, continue
  50. $filterChain->execute(); return;
  51. }
  52. }
  53. // the user doesn't have access
  54. $this->forwardToSecureAction(); return;
  55. }
  56. }