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

Source for file papi1.5-attr-authz.php

Documentation is available at papi1.5-attr-authz.php

  1. <?php
  2. /**
  3.  * This is a sample file to demonstrate the functionality of the phpPoA2 package.
  4.  * @author Jaime Perez <jaime.perez@rediris.es>
  5.  * @filesource
  6.  * @package phpPoA2
  7.  * @subpackage AttributeFilterAuthorizationEngine
  8.  */
  9.  
  10. include("../PoA.php");
  11.  
  12. $poa new PoA("samples");
  13.  
  14. $poa->authenticate();
  15. $attrs $poa->getAttributes();
  16.  
  17. function attrHook(&$attrs&$allowed&$denied{
  18.     array_push($allowed['sHO']preg_quote($attrs['sHO']));
  19.     return false;
  20. }
  21.  
  22. echo "<h1>PAPI 1.5 Example #6</h1>";
  23.  
  24. if (isset($_GET['force'])) {
  25.     $hook new Hook("attrHook");
  26.     $poa->addHook("ATTRIBUTE_BEFORE_FILTERS"$hook);
  27.  
  28.     echo "<h2>addHook() + isAuthorized()</h2>";
  29.     echo "<p>This example demonstrates the use of the attribute filtering authorization engine and makes use ";
  30.     echo "of a hook to modify the filters on runtime and therefore modify also the authorization result. If ";
  31.     echo "authorization fails, you will be provided with a link below that will add a hook that forces your ";
  32.     echo "<tt>sHO</tt> attribute to be recognized as a valid one, and be authorized then.</p>";
  33.     echo "<hr/>";
  34.  
  35.     echo "<p><strong>addHook(\"ATTRIBUTE_BEFORE_FILTERS\", new Hook(\"attrHook\"))</strong>:</p>";
  36.     echo "<div style=\"background: #cccccc; padding: 5px\"><pre>function attrHook(&\$attrs, &\$allowed, &\$denied) {\n";
  37.     echo "    array_push(\$allowed['sHO'], preg_quote(\$attrs['sHO']));\n";
  38.     echo "    return false;\n";
  39.     echo "}</pre></div>";
  40.  
  41. else {
  42.     echo "<h2>isAuthorized()</h2>";
  43.     echo "<p>This example demonstrates the use of the attribute filtering authorization engine and makes use ";
  44.     echo "of a hook to modify the filters on runtime and therefore modify also the authorization result. If ";
  45.     echo "authorization fails, you will be provided with a link below that will add a hook that forces your ";
  46.     echo "<tt>sHO</tt> attribute to be recognized as a valid one, and be authorized then.</p>";
  47.     echo "<hr/>";
  48. }
  49.  
  50. $auth $poa->isAuthorized(""$attrs"AttributeFilterAuthzEngine");
  51.  
  52. if ($auth{
  53.     echo "<p><strong>isAuthorized(\"\", PoA::getAttributes(), \"AttributeFilterAuthzEngine\")</strong>: <div style=\"background: #ccffcc; padding: 5px\"><tt>AUTHZ_SUCCESS</tt></div></p>";
  54. else {
  55.     echo "<p><strong>isAuthorized(\"\", PoA::getAttributes(),  \"AttributeFilterAuthzEngine\")</strong>: <div style=\"background: #ffcccc; padding: 5px\"><tt>AUTHZ_FAILED</tt></div></p>";
  56.     echo "<p><a href=\"?force\">Force authorization</a></p>";
  57. }
  58.  
  59. ?>

Documentation generated on Fri, 11 Feb 2011 10:57:59 +0100 by phpDocumentor 1.4.3