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

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

Documentation is available at papi1.5-invite-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 InviteAuthorizationEngine
  8.  */
  9.  
  10. include("../PoA.php");
  11.  
  12. $poa new PoA("sample7");
  13.  
  14. $auth $poa->authenticate();
  15. $attrs $poa->getAttributes();
  16.  
  17. echo "<h1>PAPI 1.5 Example #7</h1>";
  18. echo "<h2>authenticate() + getAttributes() + isAuthorized() + getAuthorizationEngines()</h2>";
  19. echo "<p>This example demonstrates the use of the invitation based authorization engine. Authentication is automatically ";
  20. echo "triggered and once authenticated, the attributes of the user are collected. The <tt>eduPersonTargetedId</tt> attribute ";
  21. echo "is used to identify users across different sessions, and therefore to authorize and query if the user is authorized.</p>";
  22. echo "<hr/>";
  23.  
  24. if ($auth{
  25.     echo "<p><strong>authenticate()</strong>: <div style=\"background: #ccffcc; padding: 5px\"><tt>AUTHN_SUCCESS</tt></div></p>";
  26. else {
  27.     echo "<p><strong>authenticate()</strong>: <div style=\"background: #ffcccc; padding: 5px\"><tt>AUTHN_FAILED</tt></div></p>";
  28. }
  29.  
  30. $auth $poa->isAuthorized($attrs['ePTI']$attrs"InviteAuthzEngine");
  31.  
  32. if ($auth{
  33.     echo "<p><strong>isAuthorized(\"".$attrs['ePTI']."\", PoA::getAttributes(), \"InviteAuthzEngine\")</strong>: <div style=\"background: #ccffcc; padding: 5px\"><tt>AUTHZ_SUCCESS</tt></div></p>";
  34. else {
  35.     echo "<p><strong>isAuthorized(\"".$attrs['ePTI']."\", PoA::getAttributes(), \"InviteAuthzEngine\")</strong>: <div style=\"background: #ffcccc; padding: 5px\"><tt>AUTHZ_FAILED</tt></div></p>";
  36. }
  37.  
  38. $engines $poa->getAuthorizationEngines("InviteAuthzEngine");
  39. $engine $engines['InviteAuthzEngine'];
  40.  
  41. echo "<hr/>";
  42.  
  43. // send invite
  44. if (@$_REQUEST['action'=== "Send"{
  45.     echo "<h2>invite() + getAuthorizedList() + getPendingInvites()</h2>";
  46.     echo "<p>An invitation e-mail has been sent to ".htmlentities($_REQUEST['mail']).".";
  47.     echo "<p>Listed below are both sets of currently authorized users and the invitations pending of acceptation. Click the link on each invite to "
  48.     echo "accept it. Please note that e-mail verification is done by means of the <tt>sPUC</tt> (<tt>schacPersonalUniqueCode</tt>) attribute, so if you are ";
  49.     echo "not using it or its value does not correspond to the e-mail where the invitation was sent, authorization will fail. If you want to send another ";
  50.     echo "invitation, please use the form below.</p>";
  51.     echo "<hr/>";
  52.     $r $engine->invite($_REQUEST['mail']);
  53.     if ($r{
  54.         echo "<p><strong>invite(\"".$_REQUEST['mail']."\")</strong>: <div style=\"background: #ccffcc; padding: 5px\"><tt>TRUE</tt></div></p>";
  55.     else {
  56.         echo "<p><strong>invite(\"".$_REQUEST['mail']."\")</strong>: <div style=\"background: #ffcccc; padding: 5px\"><tt>FALSE</tt></div></p>";
  57.     }
  58. else if (@$_REQUEST['action'=== "authorize"{
  59.     echo "<h2>authorize() + getAuthorizedList() + getPendingInvites()</h2>";
  60.     $r $poa->authorize($attrs['ePTI']$attrs$_REQUEST['ref']);
  61.     if ($r{
  62.         echo "<p>The user with the <tt>eduPersonTargetedId</tt> '".htmlentities($attrs['ePTI'])."' has been authorized.</p>";
  63.         echo "<p>Listed below are both sets of currently authorized users and the invitations pending of acceptation. Click the link on each invite to "
  64.         echo "accept it. Please note that e-mail verification is done by means of the <tt>sPUC</tt> (<tt>schacPersonalUniqueCode</tt>) attribute, so if you are ";
  65.         echo "not using it or its value does not correspond to the e-mail where the invitation was sent, authorization will fail. If you want to send another ";
  66.         echo "invitation, please use the form below.</p>";
  67.         echo "<hr/>";
  68.         echo "<p><strong>authorize(\"".$attrs['ePTI']."\", PoA::getAttributes(), \"".$_REQUEST['ref']."\")</strong>: <div style=\"background: #ccffcc; padding: 5px\"><tt>TRUE</tt></div></p>";
  69.     else {
  70.         echo "<p>The user with the <tt>eduPersonTargetedId</tt> '".htmlentities($attrs['ePTI'])."' has <strong>NOT</strong> been authorized. Please check the logs ";
  71.         echo "for a detailed explanation of the error.</p>";
  72.         echo "<p>Listed below are both sets of currently authorized users and the invitations pending of acceptation. Click the link on each invite to ";
  73.         echo "accept it. Please note that e-mail verification is done by means of the <tt>sPUC</tt> (<tt>schacPersonalUniqueCode</tt>) attribute, so if you are ";
  74.         echo "not using it or its value does not correspond to the e-mail where the invitation was sent, authorization will fail. If you want to send another ";
  75.         echo "invitation, please use the form below.</p>";
  76.         echo "<hr/>";
  77.         echo "<p><strong>authorize(\"".$attrs['ePTI']."\", PoA::getAttributes(), \"".$_REQUEST['ref']."\")</strong>: <div style=\"background: #ffcccc; padding: 5px\"><tt>FALSE</tt></div></p>";
  78.     }
  79. else {
  80.     echo "<h2>getAuthorizedList() + getPendingInvites()</h2>";
  81.     echo "<p>Listed below are both sets of currently authorized users and the invitations pending of acceptation. Click the link on each invite to "
  82.     echo "accept it. Please note that e-mail verification is done by means of the <tt>sPUC</tt> (<tt>schacPersonalUniqueCode</tt>) attribute, so if you are ";
  83.     echo "not using it or its value does not correspond to the e-mail where the invitation was sent, authorization will fail. If you want to send another ";
  84.     echo "invitation, please use the form below.</p>";
  85.     echo "<hr/>";
  86. }
  87.  
  88. $authorized $engine->getAuthorizedList();
  89. $pending $engine->getPendingInvites();
  90.  
  91. echo "<p><strong>getAuthorizedList()</strong>:</p>";
  92.  
  93. echo "<ul>";
  94. if (empty($authorized)) {
  95.     echo "<li>none</li>";
  96. else {
  97.     foreach ($authorized as $id => $user{
  98.         $color "cccccc";
  99.         if ($attrs['ePTI'=== $id{
  100.             $color "ccffcc";
  101.         }
  102.         echo "<li><div style=\"background: #".$color."; padding: 5px\"><strong>ePTI</strong>: <tt>".$id."</tt>:";
  103.         echo "<ul>";
  104.         echo "<li><strong>email</strong>: <tt>".$user['email']."</tt></li>";
  105.         echo "<li><strong>attributes</strong>:<ul>";
  106.         foreach ($user['attributes'as $name => $value{
  107.             echo "<li><strong>".$name."</strong>: <tt>".$value."</tt></li>";
  108.         }
  109.         echo "</ul></li>";
  110.         echo "<li><strong>since</strong>: <tt>".date("r"$user['since'])."</tt></li>";
  111.         $expires (!$user['expires']"never" date("r"$user['expires']);
  112.         echo "<li><strong>expires</strong>: <tt>".$expires."</tt></li>";
  113.         echo "</ul></div></li><br/>";
  114.     }
  115. }
  116. echo "</ul>";
  117.  
  118. echo "<p><strong>getPendingInvites()</strong>:</p>";
  119.  
  120. echo "<ul>";
  121. if (empty($pending)) {
  122.     echo "<li>none</li>";
  123. else  {
  124.     foreach ($pending as $ref => $invite{
  125.         echo "<li><div style=\"background: #cccccc; padding: 5px\"><strong>reference</strong>: <a href=\"papi1.5-invite-authz.php?action=authorize&ref=".$ref."\"><tt>".$ref."</tt></a>:";
  126.         echo "<ul>";
  127.         echo "<li><strong>email</strong>: <tt>".$invite['email']."</tt></li>";
  128.         echo "<li><strong>since</strong>: <tt>".date("r"$invite['since'])."</tt></li>";
  129.         $expires (!$invite['expires']"never" date("r"$invite['expires']);
  130.         echo "<li><strong>expires</strong>: <tt>".$expires."</tt></li>";
  131.         echo "</ul></div></li><br/>";
  132.     }
  133. }
  134. echo "</ul>";
  135.  
  136. ?>
  137. <h3>Send invite</h3>
  138. <form name="invite" action="papi1.5-invite-authz.php" method="get">
  139.   E-mail address:<br/> <input type="text" name="mail"/>
  140.   <input name="action" type="submit" value="Send"/>
  141. </form>

Documentation generated on Fri, 11 Feb 2011 10:58:00 +0100 by phpDocumentor 1.4.3