/** * Adds a signature to the request * * @access public * @author Joel Bout, <*****@*****.**> * @param $authorizationHeader Move the signature parameters into the Authorization header of the request */ public function sign(common_http_Request $request, common_http_Credentials $credentials, $authorizationHeader = false) { if (!$credentials instanceof tao_models_classes_oauth_Credentials) { throw new tao_models_classes_oauth_Exception('Invalid credentals: ' . gettype($credentials)); } $oauthRequest = $this->getOauthRequest($request); $dataStore = new tao_models_classes_oauth_DataStore(); $consumer = $dataStore->getOauthConsumer($credentials); $token = $dataStore->new_request_token($consumer); $allInitialParameters = array(); $allInitialParameters = array_merge($allInitialParameters, $request->getParams()); $allInitialParameters = array_merge($allInitialParameters, $request->getHeaders()); //oauth_body_hash is used for the signing computation if ($authorizationHeader) { $oauth_body_hash = base64_encode(sha1($request->getBody(), true)); //the signature should be ciomputed from encoded versions $allInitialParameters = array_merge($allInitialParameters, array("oauth_body_hash" => $oauth_body_hash)); } //$authorizationHeader = self::buildAuthorizationHeader($signatureParameters); $signedRequest = OAuthRequest::from_consumer_and_token($consumer, $token, $oauthRequest->get_normalized_http_method(), $oauthRequest->getUrl(), $allInitialParameters); $signature_method = new OAuthSignatureMethod_HMAC_SHA1(); //common_logger::d('Base string: '.$signedRequest->get_signature_base_string()); $signedRequest->sign_request($signature_method, $consumer, $token); common_logger::d('Base string from TAO/Joel: ' . $signedRequest->get_signature_base_string()); if ($authorizationHeader) { $combinedParameters = $signedRequest->get_parameters(); $signatureParameters = array_diff_assoc($combinedParameters, $allInitialParameters); $signatureParameters["oauth_body_hash"] = base64_encode(sha1($request->getBody(), true)); $signatureHeaders = array("Authorization" => self::buildAuthorizationHeader($signatureParameters)); $signedRequest = new common_http_Request($signedRequest->getUrl(), $signedRequest->get_normalized_http_method(), $request->getParams(), array_merge($signatureHeaders, $request->getHeaders()), $request->getBody()); } else { $signedRequest = new common_http_Request($signedRequest->getUrl(), $signedRequest->get_normalized_http_method(), $signedRequest->get_parameters(), $request->getHeaders(), $request->getBody()); } return $signedRequest; }
/** * Retrieves a constant from the manifest.php file of the extension. * * @author Joel Bout, <*****@*****.**> * @param string $key * @return mixed * @throws common_exception_Error If the constant cannot be found. */ public function getConstant($key) { $returnValue = null; $constants = $this->getConstants(); if (isset($constants[$key])) { $returnValue = $constants[$key]; } elseif (defined($key)) { common_logger::w('constant outside of extension called: ' . $key); $returnValue = constant($key); } else { throw new common_exception_Error('Unknown constant \'' . $key . '\' for extension ' . $this->id); } return $returnValue; }
/** * Short description of method getSection * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param string extension * @param string perspectiveId * @param string sectionId * @return Section */ public static function getSection($extension, $perspectiveId, $sectionId) { $returnValue = null; $structure = self::getPerspective($extension, $perspectiveId); foreach ($structure->getChildren() as $section) { if ($section->getId() == $sectionId) { $returnValue = $section; break; } } if (empty($returnValue)) { \common_logger::w('Section ' . $sectionId . ' not found found for perspective ' . $perspectiveId); } return $returnValue; }
public function spawnResult() { common_logger::i("LoggerStorage - Spawn request made"); }