phpPoA2
[ class tree: phpPoA2 ] [ index: phpPoA2 ] [ all elements ]

Source for file QueryFilterAuthzEngine.php

Documentation is available at QueryFilterAuthzEngine.php

  1. <?php
  2. /**
  3.  * @copyright Copyright 2005-2010 RedIRIS, http://www.rediris.es/
  4.  *
  5.  *  This file is part of phpPoA2.
  6.  *
  7.  *  phpPoA2 is free software: you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation, either version 3 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  phpPoA2 is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with phpPoA2. If not, see <http://www.gnu.org/licenses/>.
  19.  *
  20.  * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  21.  * @version 2.0
  22.  * @author Jaime Perez <jaime.perez@rediris.es>
  23.  * @filesource
  24.  */
  25.  
  26. /**
  27.  * This hook is executed right after retrieving the current URI, the params (both GET and POST) and
  28.  * the arrays of allowed and denied patterns that will be checked inmediately.
  29.  * It can be used to alter parameters and the URL, and also to configure the filters on runtime.
  30.  * The hook receives the URI string, an array of parameters, the allowed and the denied patterns.
  31.  * Functions for this hook must be defined like this:
  32.  *
  33.  * function queryBeforeFilterHook(&$uri, &$params, &$allowed, &$denied);
  34.  *
  35.  * Please bear in mind that hooks must return TRUE or they'll keep other hooks from executing.
  36.  */
  37. define("QUERY_BEFORE_FILTERS""QUERY_BEFORE_FILTERS");
  38.  
  39. /**
  40.  * Authorization engine that works by checking the query string of the request.
  41.  * @package phpPoA2
  42.  * @subpackage QueryFilterAuthorizationEngine
  43.  */
  44.  
  45.     protected $valid_hooks = array(QUERY_BEFORE_FILTERS);
  46.  
  47.     public function isAuthorized($user$attrs{
  48.         $uri $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
  49.         $params $this->getQueryParams();
  50.         $allowed $this->cfg->getAllowedPatterns();
  51.         $denied  $this->cfg->getDeniedPatterns();
  52.  
  53.         // run hook before checking patterns
  54.         $args array($uri$params$allowed$denied);
  55.         $this->runHooks(QUERY_BEFORE_FILTERS$args);
  56.         $uri $args[0];
  57.         $params $args[1];
  58.         $allowed $args[2];
  59.         $denied $args[3];
  60.  
  61.         // check patterns against the current URI
  62.         foreach ($allowed as $pattern// allowed URIs
  63.             if (preg_match('/'.$pattern.'/'$uri)) {
  64.                 trigger_error(msg('allowed-pattern-match'array($uri$pattern))E_USER_WARNING);
  65.                 return true;
  66.             }
  67.         }
  68.  
  69.         // denied URIs
  70.         foreach ($denied as $pattern{
  71.             if (preg_match('/'.$pattern.'/'$uri)) {
  72.                 trigger_error(msg('denied-pattern-match'array($uri$pattern))E_USER_WARNING);
  73.                 return false;
  74.             }
  75.         }
  76.  
  77.         // check patterns against the request params
  78.         foreach ($params as $param{
  79.             // allowed params
  80.             foreach ($allowed as $pattern{
  81.                 if (preg_match('/'.$pattern.'/'$param)) {
  82.                     trigger_error(msg('allowed-pattern-match'array($param$pattern))E_USER_WARNING);
  83.                     return true;
  84.                 }
  85.             }
  86.  
  87.             // denied params
  88.             foreach ($denied as $pattern{
  89.                 if (preg_match('/'.$pattern.'/'$param)) {
  90.                     trigger_error(msg('denied-pattern-match'array($param$pattern))E_USER_WARNING);
  91.                     return false;
  92.                 }
  93.             }
  94.         }
  95.  
  96.         // default response
  97.         trigger_error(msg('authz-default-fallback')E_USER_WARNING);
  98.         return $this->cfg->getDefaultBehaviour();
  99.     }
  100.  
  101.     public function getAuthorizedList({
  102.         $this->registerHandler();
  103.         $list $this->cfg->getAllowedPatterns();
  104.         $this->clean();
  105.         return $list;
  106.     }
  107.  
  108.     public function authorize($user$attrs$ref$expires 0{
  109.         return false;
  110.     }
  111.  
  112.     public function revoke($mail{
  113.         return false;
  114.     }
  115.  
  116.     private function getQueryParams({
  117.         // GET queries
  118.         $data explode("&"$_SERVER['QUERY_STRING']);
  119.  
  120.         // POST queries
  121.         if ($_SERVER['REQUEST_METHOD'=== "POST"{
  122.             $str file_get_contents(STDIN);
  123.  
  124.             $post array();
  125.             if ($str{
  126.                 $post explode("&"$str);
  127.             }
  128.  
  129.             $data array_merge($data$post);
  130.         }
  131.  
  132.         return $data;
  133.     }
  134.  
  135. }
  136.  
  137. ?>

Documentation generated on Wed, 13 Oct 2010 15:06:25 +0200 by phpDocumentor 1.4.3