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

Source for file papi1.5-customattr.php

Documentation is available at papi1.5-customattr.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 PAPIAuthenticationEngine
  8.  */
  9.  
  10. include("../PoA.php");
  11.  
  12. $poa new PoA("samples");
  13.  
  14. $auth $poa->authenticate();
  15.  
  16. echo "<h1>PAPI 1.5 Example #2</h1>";
  17. echo "<h2>authenticate() + addHook() + getAttributes()</h2>";
  18. echo "<hr/>";
  19.  
  20. function handler($assertion&$attributes{
  21.     $attributes explode("@"$assertion);
  22.     return true;
  23. }
  24.  
  25.  
  26.     public function handle($assertion&$attributes{
  27.         $attributes explode(","$assertion);
  28.         return true;
  29.     }
  30.  
  31. }
  32.  
  33. if ($auth{
  34.     echo "<p><strong>authenticate()</strong>: <div style=\"background: #ccffcc; padding: 5px\"><tt>AUTHN_SUCCESS</tt></div></p>";
  35.     echo "<p><strong>addHook(\"PAPI_ATTRIBUTE_PARSER\", new Hook(\"handler\"))</strong>:<br/>";
  36.     echo "<div style=\"background: #cccccc; padding: 5px\"><pre>function handler(\$assertion, &\$attributes) {\n";
  37.     echo "    \$attributes = explode(\"@\", \$assertion);\n";
  38.     echo "    return true;\n";
  39.     echo "}</pre></div>";
  40.     echo "<p><strong>getAttributes()</strong>:</p>";
  41.     $fhook new Hook("handler");
  42.     $poa->addHook("PAPI_ATTRIBUTE_PARSER"$fhook);
  43.     echo "<div style=\"background: #cccccc; padding: 5px\"><pre style=\"overflow: auto\">".print_r($poa->getAttributes(),true)."</pre></div>";
  44.     echo "<p><strong>addHook(\"PAPI_ATTRIBUTE_PARSER\", new Hook(array(\"AttributeHandler\",\"handler\")))</strong>:<br/>";
  45.     echo "<div style=\"background: #cccccc; padding: 5px\"><pre>class AttributeHandler {\n";
  46.     echo "    public function handler(\$assertion, &\$attributes) {\n";
  47.     echo "        \$attributes = explode(\",\", \$assertion);\n";
  48.     echo "        return true;\n";
  49.     echo "    }\n}</pre></div>";
  50.     $poa->removeHook("PAPI_ATTRIBUTE_PARSER"$fhook);
  51.     $o new AttributeHandler();
  52.     $ohook new Hook(array($o"handle"));
  53.     $poa->addHook("PAPI_ATTRIBUTE_PARSER"$ohook);
  54.     echo "<p><strong>getAttributes()</strong>:</p>";
  55.     echo "<div style=\"background: #cccccc; padding: 5px\"><pre style=\"overflow: auto\">".print_r($poa->getAttributes(),true)."</pre></div>";
  56. else {
  57.     echo "<p><strong>authenticate()</strong>: <div style=\"background: #ffcccc; padding: 5px\"><tt>AUTHN_FAILED</tt></div></p>";
  58. }
  59.  
  60. ?>

Documentation generated on Tue, 14 Jun 2011 12:22:12 +0200 by phpDocumentor 1.4.3