Support Joomla!

Packages

Package: Unknown

License

Content on this site is copyright © 2005 - 2008 Open Source Matters Inc and can be used in accordance with the Joomla! Electronic Documentation License. Some parts of this website may be subject to other licenses.
Source code for file /openid/Auth/OpenID/PAPE.php

Documentation is available at PAPE.php

  1. <?php
  2.  
  3. /**
  4.  * An implementation of the OpenID Provider Authentication Policy
  5.  *  Extension 1.0
  6.  *
  7.  * See:
  8.  * http://openid.net/developers/specs/
  9.  */
  10.  
  11. // Do not allow direct access
  12. defined'_JEXEC' or die'Restricted access' );
  13.  
  14. require_once "Auth/OpenID/Extension.php";
  15.  
  16. define('Auth_OpenID_PAPE_NS_URI',
  17.        "http://specs.openid.net/extensions/pape/1.0");
  18.  
  19. define('PAPE_AUTH_MULTI_FACTOR_PHYSICAL',
  20.        'http://schemas.openid.net/pape/policies/2007/06/multi-factor-physical');
  21. define('PAPE_AUTH_MULTI_FACTOR',
  22.        'http://schemas.openid.net/pape/policies/2007/06/multi-factor');
  23. define('PAPE_AUTH_PHISHING_RESISTANT',
  24.        'http://schemas.openid.net/pape/policies/2007/06/phishing-resistant');
  25.  
  26. define('PAPE_TIME_VALIDATOR',
  27.        '^[0-9]{4,4}-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z$');
  28. /**
  29.  * A Provider Authentication Policy request, sent from a relying party
  30.  * to a provider
  31.  *
  32.  * preferred_auth_policies: The authentication policies that
  33.  * the relying party prefers
  34.  *
  35.  * max_auth_age: The maximum time, in seconds, that the relying party
  36.  * wants to allow to have elapsed before the user must re-authenticate
  37.  */
  38.  
  39.     var $ns_alias = 'pape';
  40.     var $ns_uri = Auth_OpenID_PAPE_NS_URI;
  41.  
  42.     function Auth_OpenID_PAPE_Request($preferred_auth_policies=null,
  43.                                       $max_auth_age=null)
  44.     {
  45.         if ($preferred_auth_policies === null{
  46.             $preferred_auth_policies array();
  47.         }
  48.  
  49.         $this->preferred_auth_policies $preferred_auth_policies;
  50.         $this->max_auth_age $max_auth_age;
  51.     }
  52.  
  53.     /**
  54.      * Add an acceptable authentication policy URI to this request
  55.      *
  56.      * This method is intended to be used by the relying party to add
  57.      * acceptable authentication types to the request.
  58.      *
  59.      * policy_uri: The identifier for the preferred type of
  60.      * authentication.
  61.      */
  62.     function addPolicyURI($policy_uri)
  63.     {
  64.         if (!in_array($policy_uri$this->preferred_auth_policies)) {
  65.             $this->preferred_auth_policies[$policy_uri;
  66.         }
  67.     }
  68.  
  69.     function getExtensionArgs()
  70.     {
  71.         $ns_args array(
  72.                          'preferred_auth_policies' =>
  73.                            implode(' '$this->preferred_auth_policies)
  74.                          );
  75.  
  76.         if ($this->max_auth_age !== null{
  77.             $ns_args['max_auth_age'strval($this->max_auth_age);
  78.         }
  79.  
  80.         return $ns_args;
  81.     }
  82.  
  83.     /**
  84.      * Instantiate a Request object from the arguments in a checkid_*
  85.      * OpenID message
  86.      */
  87.     function fromOpenIDRequest($request)
  88.     {
  89.         $obj new Auth_OpenID_PAPE_Request();
  90.         $args $request->message->getArgs(Auth_OpenID_PAPE_NS_URI);
  91.  
  92.         if ($args === null || $args === array()) {
  93.             return null;
  94.         }
  95.  
  96.         $obj->parseExtensionArgs($args);
  97.         return $obj;
  98.     }
  99.  
  100.     /**
  101.      * Set the state of this request to be that expressed in these
  102.      * PAPE arguments
  103.      *
  104.      * @param args: The PAPE arguments without a namespace
  105.      */
  106.     function parseExtensionArgs($args)
  107.     {
  108.         // preferred_auth_policies is a space-separated list of policy
  109.         // URIs
  110.         $this->preferred_auth_policies array();
  111.  
  112.         $policies_str Auth_OpenID::arrayGet($args'preferred_auth_policies');
  113.         if ($policies_str{
  114.             foreach (explode(' '$policies_stras $uri{
  115.                 if (!in_array($uri$this->preferred_auth_policies)) {
  116.                     $this->preferred_auth_policies[$uri;
  117.                 }
  118.             }
  119.         }
  120.  
  121.         // max_auth_age is base-10 integer number of seconds
  122.         $max_auth_age_str Auth_OpenID::arrayGet($args'max_auth_age');
  123.         if ($max_auth_age_str{
  124.             $this->max_auth_age Auth_OpenID::intval($max_auth_age_str);
  125.         else {
  126.             $this->max_auth_age null;
  127.         }
  128.     }
  129.  
  130.     /**
  131.      * Given a list of authentication policy URIs that a provider
  132.      * supports, this method returns the subsequence of those types
  133.      * that are preferred by the relying party.
  134.      *
  135.      * @param supported_types: A sequence of authentication policy
  136.      *  type URIs that are supported by a provider
  137.      *
  138.      * @return array The sub-sequence of the supported types that are
  139.      *  preferred by the relying party. This list will be ordered in
  140.      *  the order that the types appear in the supported_types
  141.      *  sequence, and may be empty if the provider does not prefer any
  142.      *  of the supported authentication types.
  143.      */
  144.     function preferredTypes($supported_types)
  145.     {
  146.         $result array();
  147.  
  148.         foreach ($supported_types as $st{
  149.             if (in_array($st$this->preferred_auth_policies)) {
  150.                 $result[$st;
  151.             }
  152.         }
  153.         return $result;
  154.     }
  155. }
  156.  
  157. /**
  158.  * A Provider Authentication Policy response, sent from a provider to
  159.  * a relying party
  160.  */
  161.  
  162.     var $ns_alias = 'pape';
  163.     var $ns_uri = Auth_OpenID_PAPE_NS_URI;
  164.  
  165.     function Auth_OpenID_PAPE_Response($auth_policies=null$auth_time=null,
  166.                                        $nist_auth_level=null)
  167.     {
  168.         if ($auth_policies{
  169.             $this->auth_policies $auth_policies;
  170.         else {
  171.             $this->auth_policies array();
  172.         }
  173.  
  174.         $this->auth_time $auth_time;
  175.         $this->nist_auth_level $nist_auth_level;
  176.     }
  177.  
  178.     /**
  179.      * Add a authentication policy to this response
  180.      *
  181.      * This method is intended to be used by the provider to add a
  182.      * policy that the provider conformed to when authenticating the
  183.      * user.
  184.      *
  185.      * @param policy_uri: The identifier for the preferred type of
  186.      *  authentication.
  187.      */
  188.     function addPolicyURI($policy_uri)
  189.     {
  190.         if (!in_array($policy_uri$this->auth_policies)) {
  191.             $this->auth_policies[$policy_uri;
  192.         }
  193.     }
  194.  
  195.     /**
  196.      * Create an Auth_OpenID_PAPE_Response object from a successful
  197.      * OpenID library response.
  198.      *
  199.      * @param success_response $success_response A SuccessResponse
  200.      *  from Auth_OpenID_Consumer::complete()
  201.      *
  202.      * @returns: A provider authentication policy response from the
  203.      *  data that was supplied with the id_res response.
  204.      */
  205.     function fromSuccessResponse($success_response)
  206.     {
  207.         $obj new Auth_OpenID_PAPE_Response();
  208.  
  209.         // PAPE requires that the args be signed.
  210.         $args $success_response->getSignedNS(Auth_OpenID_PAPE_NS_URI);
  211.  
  212.         if ($args === null || $args === array()) {
  213.             return null;
  214.         }
  215.  
  216.         $result $obj->parseExtensionArgs($args);
  217.  
  218.         if ($result === false{
  219.             return null;
  220.         else {
  221.             return $obj;
  222.         }
  223.     }
  224.  
  225.     /**
  226.      * Parse the provider authentication policy arguments into the
  227.      *  internal state of this object
  228.      *
  229.      * @param args: unqualified provider authentication policy
  230.      *  arguments
  231.      *
  232.      * @param strict: Whether to return false when bad data is
  233.      *  encountered
  234.      *
  235.      * @return null The data is parsed into the internal fields of
  236.      *  this object.
  237.     */
  238.     function parseExtensionArgs($args$strict=false)
  239.     {
  240.         $policies_str Auth_OpenID::arrayGet($args'auth_policies');
  241.         if ($policies_str && $policies_str != "none"{
  242.             $this->auth_policies explode(" "$policies_str);
  243.         }
  244.  
  245.         $nist_level_str Auth_OpenID::arrayGet($args'nist_auth_level');
  246.         if ($nist_level_str !== null{
  247.             $nist_level Auth_OpenID::intval($nist_level_str);
  248.  
  249.             if ($nist_level === false{
  250.                 if ($strict{
  251.                     return false;
  252.                 else {
  253.                     $nist_level null;
  254.                 }
  255.             }
  256.  
  257.             if (<= $nist_level && $nist_level 5{
  258.                 $this->nist_auth_level $nist_level;
  259.             else if ($strict{
  260.                 return false;
  261.             }
  262.         }
  263.  
  264.         $auth_time Auth_OpenID::arrayGet($args'auth_time');
  265.         if ($auth_time !== null{
  266.             if (ereg(PAPE_TIME_VALIDATOR$auth_time)) {
  267.                 $this->auth_time $auth_time;
  268.             else if ($strict{
  269.                 return false;
  270.             }
  271.         }
  272.     }
  273.  
  274.     function getExtensionArgs()
  275.     {
  276.         $ns_args array();
  277.         if (count($this->auth_policies0{
  278.             $ns_args['auth_policies'implode(' '$this->auth_policies);
  279.         else {
  280.             $ns_args['auth_policies''none';
  281.         }
  282.  
  283.         if ($this->nist_auth_level !== null{
  284.             if (!in_array($this->nist_auth_levelrange(04)true)) {
  285.                 return false;
  286.             }
  287.             $ns_args['nist_auth_level'strval($this->nist_auth_level);
  288.         }
  289.  
  290.         if ($this->auth_time !== null{
  291.             if (!ereg(PAPE_TIME_VALIDATOR$this->auth_time)) {
  292.                 return false;
  293.             }
  294.  
  295.             $ns_args['auth_time'$this->auth_time;
  296.         }
  297.  
  298.         return $ns_args;
  299.     }
  300. }
  301.  
  302. ?>

Documentation generated on Sat, 14 Nov 2009 11:16:40 +0000 by phpDocumentor 1.3.1