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

Source for file papi1.5-papiopoa-hook.php

Documentation is available at papi1.5-papiopoa-hook.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. function hook(&$params{
  15.     $params['PAPIOPOA'"SAML_SUBJECT";
  16.     $params['URL'.= "?ORIGINAL_URL=modified_by_hook";
  17.     return false;
  18. }
  19.  
  20. class Example {
  21.     public function hook(&$clean{
  22.         $clean false;
  23.         return false;
  24.     }
  25. }
  26.  
  27. $poa->addHook("PAPI_REDIRECT_URL_FINISH"new Hook("hook"));
  28. $poa->addHook("PAPI_CLEAN_URL"new Hook(array("Example""hook")));
  29.  
  30. $auth $poa->authenticate();
  31.  
  32. echo "<h1>PAPI 1.5 Example #3</h1>";
  33. echo "<h2>addHook() + authenticate()</h2>";
  34. echo "<hr/>";
  35.  
  36. if ($auth{
  37.     echo "<p><strong>addHook(\"PAPI_REDIRECT_URL_FINISH\", new Hook(\"hook\"))</strong>:";
  38.     echo "<div style=\"background: #cccccc; padding: 5px\"><pre>function hook(&\$params) {\n";
  39.     echo "    // set the PAPIOPOA to a custom string\n";
  40.     echo "    \$params['PAPIOPOA'] = \"SAML_SUBJECT\";\n\n";
  41.     echo "    // modify the return URL for this request\n";
  42.     echo "    \$params['URL'] .= \"?ORIGINAL_URL=modified_by_hook\";\n\n";
  43.     echo "    // return false unless you want to stop hooks execution\n";
  44.     echo "    return false;\n";
  45.     echo "}</pre></div>";
  46.     echo "<p><strong>addHook(\"PAPI_CLEAN_URL\", new Hook(array(\"Example\", \"hook\")))</strong>:";
  47.     echo "<div style=\"background: #cccccc; padding: 5px\"><pre>class Example {\n";
  48.     echo "    public function hook(&\$clean) {\n";
  49.     echo "        // avoid cleaning the URL when coming back from the GPoA\n";
  50.     echo "        \$clean = false;\n\n";
  51.     echo "        // return false unless you want to stop hooks execution\n";
  52.     echo "        return false;\n";
  53.     echo "    }\n}</pre></div>";
  54.     echo "<p><strong>authenticate()</strong>: <div style=\"background: #ccffcc; padding: 5px\"><tt>AUTHN_SUCCESS</tt></div></p>";
  55. else {
  56.     echo "<p><strong>authenticate()</strong>: <div style=\"background: #ffcccc; padding: 5px\"><tt>AUTHN_FAILED</tt></div></p>";
  57. }
  58.  
  59. ?>

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