Author: chabotc
Date: Wed Mar 25 13:04:54 2009
New Revision: 758243

URL: http://svn.apache.org/viewvc?rev=758243&view=rev
Log:
Part 2 of the proxied content work and improvements to the remote content 
fetcher chain

Modified:
    incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
    incubator/shindig/trunk/php/src/common/sample/BasicSecurityToken.php
    incubator/shindig/trunk/php/src/gadgets/render/GadgetHrefRenderer.php

Modified: incubator/shindig/trunk/php/src/common/RemoteContentRequest.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/RemoteContentRequest.php?rev=758243&r1=758242&r2=758243&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/RemoteContentRequest.php (original)
+++ incubator/shindig/trunk/php/src/common/RemoteContentRequest.php Wed Mar 25 
13:04:54 2009
@@ -34,6 +34,7 @@
   private $contentType = null;
   private $options;
   private $created;
+  private $refreshInterval;
   private static $SC_OK = 200; //Please, use only for testing!
   public $handle = false;
   public static $DEFAULT_CONTENT_TYPE = "application/x-www-form-urlencoded; 
charset=utf-8";
@@ -253,23 +254,60 @@
   }
 
   /**
+   * Sets the security token to use (used if the request has authorization set 
(signed, oauth))
    * @param SecurityToken $token
    */
   public function setToken($token) {
     $this->token = $token;
   }
 
+  /**
+   * Returns the SecurityToken for this request
+   *
+   * @return unknown
+   */
   public function getToken() {
     return $this->token;
   }
 
+  /**
+   * Sets the authorization type for this request, can be one of
+   * - none, no signing or authorization
+   * - signed, sign the request with an oauth_signature
+   * - oauth, logges in to the remote oauth service and uses it as base for 
signing the requests
+   *
+   * @param string $type ('none', 'signed', 'oauth')
+   */
   public function setAuthType($type) {
     $this->authType = $type;
   }
 
+  /**
+   * Returns the auth type of the request
+   *
+   * @return string ('none', 'signed', 'oauth')
+   */
   public function getAuthType() {
     return $this->authType;
   }
+
+  /**
+   * Sets the cache refresh interval to use for this request
+   *
+   * @param int $refreshInterval (in seconds)
+   */
+  public function setRefreshInterval($refreshInterval) {
+    $this->refreshInterval = $refreshInterval;
+  }
+
+  /**
+   * Returns the cache's refresh interval for this request
+   *
+   * @return int refreshInterval (in seconds)
+   */
+  public function getRefreshInterval() {
+    return $this->refreshInterval;
+  }
 }
 
 /**

Modified: incubator/shindig/trunk/php/src/common/sample/BasicSecurityToken.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/common/sample/BasicSecurityToken.php?rev=758243&r1=758242&r2=758243&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/common/sample/BasicSecurityToken.php 
(original)
+++ incubator/shindig/trunk/php/src/common/sample/BasicSecurityToken.php Wed 
Mar 25 13:04:54 2009
@@ -25,13 +25,13 @@
 class BasicSecurityToken extends SecurityToken {
   /** serialized form of the token */
   private $token;
-  
+
   /** data from the token */
   private $tokenData;
-  
+
   /** tool to use for signing and encrypting the token */
   protected $crypter;
-  
+
   private $OWNER_KEY = "o";
   private $APP_KEY = "a";
   private $VIEWER_KEY = "v";
@@ -39,7 +39,7 @@
   private $APPURL_KEY = "u";
   private $MODULE_KEY = "m";
   private $CONTAINER_KEY = "c";
-  
+
   private $authenticationMode;
 
   /**
@@ -53,7 +53,7 @@
    * Generates a token from an input string
    * @param token String form of token
    * @param maxAge max age of the token (in seconds)
-   * @throws BlobCrypterException 
+   * @throws BlobCrypterException
    */
   static public function createFromToken($token, $maxAge) {
     return new BasicSecurityToken($token, $maxAge, null, null, null, null, 
null, null, null);
@@ -67,8 +67,8 @@
    * @param domain domain of the container
    * @param appUrl url where the application lives
    * @param moduleId module id of this gadget
-   * @return BasicSecurityToken 
-   * @throws BlobCrypterException 
+   * @return BasicSecurityToken
+   * @throws BlobCrypterException
    */
   static public function createFromValues($owner, $viewer, $app, $domain, 
$appUrl, $moduleId, $containerId) {
     return new BasicSecurityToken(null, null, $owner, $viewer, $app, $domain, 
$appUrl, $moduleId, $containerId);
@@ -147,7 +147,7 @@
     if ($this->isAnonymous()) {
       throw new Exception("Can't get appUrl from an anonymous token");
     }
-    return $this->tokenData[$this->APPURL_KEY];
+    return urldecode($this->tokenData[$this->APPURL_KEY]);
   }
 
   /**
@@ -172,14 +172,14 @@
     }
     return $this->tokenData[$this->CONTAINER_KEY];
   }
-  
+
   /**
    * {...@inheritdoc}
    */
   public function getAuthenticationMode() {
     return $this->authenticationMode;
   }
-  
+
   public function setAuthenticationMode($mode) {
     $this->authenticationMode = $mode;
   }

Modified: incubator/shindig/trunk/php/src/gadgets/render/GadgetHrefRenderer.php
URL: 
http://svn.apache.org/viewvc/incubator/shindig/trunk/php/src/gadgets/render/GadgetHrefRenderer.php?rev=758243&r1=758242&r2=758243&view=diff
==============================================================================
--- incubator/shindig/trunk/php/src/gadgets/render/GadgetHrefRenderer.php 
(original)
+++ incubator/shindig/trunk/php/src/gadgets/render/GadgetHrefRenderer.php Wed 
Mar 25 13:04:54 2009
@@ -1,5 +1,4 @@
 <?php
-
 /**
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -21,12 +20,18 @@
 
 class GadgetHrefRenderer extends GadgetRenderer {
 
+  /**
+   * Renders a 'proxied content' view, for reference see:
+   * 
http://opensocial-resources.googlecode.com/svn/spec/draft/OpenSocial-Data-Pipelining.xml
+   *
+   * @param Gadget $gadget
+   * @param array $view
+   */
   public function renderGadget(Gadget $gadget, $view) {
     /* TODO
      * We should really re-add OAuth fetching support some day, uses these 
view atributes:
      * $view['oauthServiceName'], $view['oauthTokenName'], 
$view['oauthRequestToken'], $view['oauthRequestTokenSecret'];
     */
-
     $gadgetSigner = Config::get('security_token_signer');
     $gadgetSigner = new $gadgetSigner();
     $token = $gadget->gadgetContext->extractAndValidateToken($gadgetSigner);
@@ -35,25 +40,37 @@
     $refreshInterval = $this->getRefreshInterval($view);
     $href = $this->buildHref($view, $token);
 
-    $signingFetcherFactory = false;
+    // rewrite our $_GET to match the outgoing request, this is currently 
needed for the oauth library
+    // to generate it's correct signature
+    $_GET = $_POST = array();
+    $uri = parse_url($href);
+    parse_str($uri['query'], $_GET);
+
     $request = new RemoteContentRequest($href);
+
     $request->setToken($token);
-    if ($authz != 'NONE') {
+    $request->setRefreshInterval($refreshInterval);
+    $request->setAuthType($authz);
+
+    $signingFetcherFactory = false;
+    if ($authz != 'none') {
       $signingFetcherFactory = new 
SigningFetcherFactory(Config::get("private_key_file"));
-      $request->setAuthType($authz);
     }
 
-    //TODO Currently our signing fetcher assumes it's being called from the 
makeRequest handler and the $_GET and $_POST should be relayed.
-    // Here that's not the case, so we reset our super globals. We should 
refactor the signing fetcher to not make this assumption anymore.
-    $_GET = array('st' => $_GET['st']);
-    $_POST = array();
-
     $basicFetcher = new BasicRemoteContentFetcher();
     $basicRemoteContent = new BasicRemoteContent($basicFetcher, 
$signingFetcherFactory, $gadgetSigner);
     $response = $basicRemoteContent->fetch($request, $gadget->gadgetContext, 
$authz);
     echo $response->getResponseContent();
   }
 
+  /**
+   * Builds the outgoing URL by taking the href attribute of the view and 
appending
+   * the country, lang, and opensocial query params to it
+   *
+   * @param array $view
+   * @param SecurityToken $token
+   * @return string the url
+   */
   private function buildHref($view, $token) {
     $href = $view['href'];
     if (empty($href)) {
@@ -75,11 +92,24 @@
     return $href;
   }
 
+  /**
+   * Returns the requested refreshInterval (cache time) of the view, or if 
none is specified
+   * it will return the configured default_refresh_interval value
+   *
+   * @param array $view
+   * @return int refresh interval
+   */
   private function getRefreshInterval($view) {
-    return ! empty($view['refreshInterval']) && 
is_numeric($view['refreshInterval']) ? $view['refreshInterval'] : 3500;
+    return ! empty($view['refreshInterval']) && 
is_numeric($view['refreshInterval']) ? $view['refreshInterval'] : 
Config::get('default_refresh_interval');
   }
 
+  /**
+   * Returns the authz attribute of the view, can be 'none', 'signed' or 
'oauth'
+   *
+   * @param array $view
+   * @return string authz attribute
+   */
   private function getAuthz($view) {
-    return ! empty($view['authz']) ? strtoupper($view['authz']) : 'NONE';
+    return ! empty($view['authz']) ? strtolower($view['authz']) : 'none';
   }
 }


Reply via email to