|
TYPO3 API
SVNRelease
|
00001 <?php 00002 00003 /** 00004 * An implementation of the OpenID Provider Authentication Policy 00005 * Extension 1.0 00006 * 00007 * See: 00008 * http://openid.net/developers/specs/ 00009 */ 00010 00011 require_once "Auth/OpenID/Extension.php"; 00012 00013 define('Auth_OpenID_PAPE_NS_URI', 00014 "http://specs.openid.net/extensions/pape/1.0"); 00015 00016 define('PAPE_AUTH_MULTI_FACTOR_PHYSICAL', 00017 'http://schemas.openid.net/pape/policies/2007/06/multi-factor-physical'); 00018 define('PAPE_AUTH_MULTI_FACTOR', 00019 'http://schemas.openid.net/pape/policies/2007/06/multi-factor'); 00020 define('PAPE_AUTH_PHISHING_RESISTANT', 00021 'http://schemas.openid.net/pape/policies/2007/06/phishing-resistant'); 00022 00023 define('PAPE_TIME_VALIDATOR', 00024 '/^[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$/'); 00025 /** 00026 * A Provider Authentication Policy request, sent from a relying party 00027 * to a provider 00028 * 00029 * preferred_auth_policies: The authentication policies that 00030 * the relying party prefers 00031 * 00032 * max_auth_age: The maximum time, in seconds, that the relying party 00033 * wants to allow to have elapsed before the user must re-authenticate 00034 */ 00035 class Auth_OpenID_PAPE_Request extends Auth_OpenID_Extension { 00036 00037 var $ns_alias = 'pape'; 00038 var $ns_uri = Auth_OpenID_PAPE_NS_URI; 00039 00040 function Auth_OpenID_PAPE_Request($preferred_auth_policies=null, 00041 $max_auth_age=null) 00042 { 00043 if ($preferred_auth_policies === null) { 00044 $preferred_auth_policies = array(); 00045 } 00046 00047 $this->preferred_auth_policies = $preferred_auth_policies; 00048 $this->max_auth_age = $max_auth_age; 00049 } 00050 00051 /** 00052 * Add an acceptable authentication policy URI to this request 00053 * 00054 * This method is intended to be used by the relying party to add 00055 * acceptable authentication types to the request. 00056 * 00057 * policy_uri: The identifier for the preferred type of 00058 * authentication. 00059 */ 00060 function addPolicyURI($policy_uri) 00061 { 00062 if (!in_array($policy_uri, $this->preferred_auth_policies)) { 00063 $this->preferred_auth_policies[] = $policy_uri; 00064 } 00065 } 00066 00067 function getExtensionArgs() 00068 { 00069 $ns_args = array( 00070 'preferred_auth_policies' => 00071 implode(' ', $this->preferred_auth_policies) 00072 ); 00073 00074 if ($this->max_auth_age !== null) { 00075 $ns_args['max_auth_age'] = strval($this->max_auth_age); 00076 } 00077 00078 return $ns_args; 00079 } 00080 00081 /** 00082 * Instantiate a Request object from the arguments in a checkid_* 00083 * OpenID message 00084 */ 00085 function fromOpenIDRequest($request) 00086 { 00087 $obj = new Auth_OpenID_PAPE_Request(); 00088 $args = $request->message->getArgs(Auth_OpenID_PAPE_NS_URI); 00089 00090 if ($args === null || $args === array()) { 00091 return null; 00092 } 00093 00094 $obj->parseExtensionArgs($args); 00095 return $obj; 00096 } 00097 00098 /** 00099 * Set the state of this request to be that expressed in these 00100 * PAPE arguments 00101 * 00102 * @param args: The PAPE arguments without a namespace 00103 */ 00104 function parseExtensionArgs($args) 00105 { 00106 // preferred_auth_policies is a space-separated list of policy 00107 // URIs 00108 $this->preferred_auth_policies = array(); 00109 00110 $policies_str = Auth_OpenID::arrayGet($args, 'preferred_auth_policies'); 00111 if ($policies_str) { 00112 foreach (explode(' ', $policies_str) as $uri) { 00113 if (!in_array($uri, $this->preferred_auth_policies)) { 00114 $this->preferred_auth_policies[] = $uri; 00115 } 00116 } 00117 } 00118 00119 // max_auth_age is base-10 integer number of seconds 00120 $max_auth_age_str = Auth_OpenID::arrayGet($args, 'max_auth_age'); 00121 if ($max_auth_age_str) { 00122 $this->max_auth_age = Auth_OpenID::intval($max_auth_age_str); 00123 } else { 00124 $this->max_auth_age = null; 00125 } 00126 } 00127 00128 /** 00129 * Given a list of authentication policy URIs that a provider 00130 * supports, this method returns the subsequence of those types 00131 * that are preferred by the relying party. 00132 * 00133 * @param supported_types: A sequence of authentication policy 00134 * type URIs that are supported by a provider 00135 * 00136 * @return array The sub-sequence of the supported types that are 00137 * preferred by the relying party. This list will be ordered in 00138 * the order that the types appear in the supported_types 00139 * sequence, and may be empty if the provider does not prefer any 00140 * of the supported authentication types. 00141 */ 00142 function preferredTypes($supported_types) 00143 { 00144 $result = array(); 00145 00146 foreach ($supported_types as $st) { 00147 if (in_array($st, $this->preferred_auth_policies)) { 00148 $result[] = $st; 00149 } 00150 } 00151 return $result; 00152 } 00153 } 00154 00155 /** 00156 * A Provider Authentication Policy response, sent from a provider to 00157 * a relying party 00158 */ 00159 class Auth_OpenID_PAPE_Response extends Auth_OpenID_Extension { 00160 00161 var $ns_alias = 'pape'; 00162 var $ns_uri = Auth_OpenID_PAPE_NS_URI; 00163 00164 function Auth_OpenID_PAPE_Response($auth_policies=null, $auth_time=null, 00165 $nist_auth_level=null) 00166 { 00167 if ($auth_policies) { 00168 $this->auth_policies = $auth_policies; 00169 } else { 00170 $this->auth_policies = array(); 00171 } 00172 00173 $this->auth_time = $auth_time; 00174 $this->nist_auth_level = $nist_auth_level; 00175 } 00176 00177 /** 00178 * Add a authentication policy to this response 00179 * 00180 * This method is intended to be used by the provider to add a 00181 * policy that the provider conformed to when authenticating the 00182 * user. 00183 * 00184 * @param policy_uri: The identifier for the preferred type of 00185 * authentication. 00186 */ 00187 function addPolicyURI($policy_uri) 00188 { 00189 if (!in_array($policy_uri, $this->auth_policies)) { 00190 $this->auth_policies[] = $policy_uri; 00191 } 00192 } 00193 00194 /** 00195 * Create an Auth_OpenID_PAPE_Response object from a successful 00196 * OpenID library response. 00197 * 00198 * @param success_response $success_response A SuccessResponse 00199 * from Auth_OpenID_Consumer::complete() 00200 * 00201 * @returns: A provider authentication policy response from the 00202 * data that was supplied with the id_res response. 00203 */ 00204 function fromSuccessResponse($success_response) 00205 { 00206 $obj = new Auth_OpenID_PAPE_Response(); 00207 00208 // PAPE requires that the args be signed. 00209 $args = $success_response->getSignedNS(Auth_OpenID_PAPE_NS_URI); 00210 00211 if ($args === null || $args === array()) { 00212 return null; 00213 } 00214 00215 $result = $obj->parseExtensionArgs($args); 00216 00217 if ($result === false) { 00218 return null; 00219 } else { 00220 return $obj; 00221 } 00222 } 00223 00224 /** 00225 * Parse the provider authentication policy arguments into the 00226 * internal state of this object 00227 * 00228 * @param args: unqualified provider authentication policy 00229 * arguments 00230 * 00231 * @param strict: Whether to return false when bad data is 00232 * encountered 00233 * 00234 * @return null The data is parsed into the internal fields of 00235 * this object. 00236 */ 00237 function parseExtensionArgs($args, $strict=false) 00238 { 00239 $policies_str = Auth_OpenID::arrayGet($args, 'auth_policies'); 00240 if ($policies_str && $policies_str != "none") { 00241 $this->auth_policies = explode(" ", $policies_str); 00242 } 00243 00244 $nist_level_str = Auth_OpenID::arrayGet($args, 'nist_auth_level'); 00245 if ($nist_level_str !== null) { 00246 $nist_level = Auth_OpenID::intval($nist_level_str); 00247 00248 if ($nist_level === false) { 00249 if ($strict) { 00250 return false; 00251 } else { 00252 $nist_level = null; 00253 } 00254 } 00255 00256 if (0 <= $nist_level && $nist_level < 5) { 00257 $this->nist_auth_level = $nist_level; 00258 } else if ($strict) { 00259 return false; 00260 } 00261 } 00262 00263 $auth_time = Auth_OpenID::arrayGet($args, 'auth_time'); 00264 if ($auth_time !== null) { 00265 if (preg_match(PAPE_TIME_VALIDATOR, $auth_time)) { 00266 $this->auth_time = $auth_time; 00267 } else if ($strict) { 00268 return false; 00269 } 00270 } 00271 } 00272 00273 function getExtensionArgs() 00274 { 00275 $ns_args = array(); 00276 if (count($this->auth_policies) > 0) { 00277 $ns_args['auth_policies'] = implode(' ', $this->auth_policies); 00278 } else { 00279 $ns_args['auth_policies'] = 'none'; 00280 } 00281 00282 if ($this->nist_auth_level !== null) { 00283 if (!in_array($this->nist_auth_level, range(0, 4), true)) { 00284 return false; 00285 } 00286 $ns_args['nist_auth_level'] = strval($this->nist_auth_level); 00287 } 00288 00289 if ($this->auth_time !== null) { 00290 if (!preg_match(PAPE_TIME_VALIDATOR, $this->auth_time)) { 00291 return false; 00292 } 00293 00294 $ns_args['auth_time'] = $this->auth_time; 00295 } 00296 00297 return $ns_args; 00298 } 00299 } 00300 00301 ?>
1.8.0