You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wookie.apache.org by sc...@apache.org on 2014/02/05 01:06:45 UTC

svn commit: r1564570 - /wookie/trunk/wookie-server/src/main/java/org/apache/wookie/auth/AuthToken.java

Author: scottbw
Date: Wed Feb  5 00:06:44 2014
New Revision: 1564570

URL: http://svn.apache.org/r1564570
Log:
Added default serialization method for use by SPIs to AuthToken. Also added a utility for converting WidgetInstance to AuthToken to help with migrating over from the persistent widgetinstance model.

Modified:
    wookie/trunk/wookie-server/src/main/java/org/apache/wookie/auth/AuthToken.java

Modified: wookie/trunk/wookie-server/src/main/java/org/apache/wookie/auth/AuthToken.java
URL: http://svn.apache.org/viewvc/wookie/trunk/wookie-server/src/main/java/org/apache/wookie/auth/AuthToken.java?rev=1564570&r1=1564569&r2=1564570&view=diff
==============================================================================
--- wookie/trunk/wookie-server/src/main/java/org/apache/wookie/auth/AuthToken.java (original)
+++ wookie/trunk/wookie-server/src/main/java/org/apache/wookie/auth/AuthToken.java Wed Feb  5 00:06:44 2014
@@ -17,7 +17,9 @@
 
 package org.apache.wookie.auth;
 
+import org.apache.wookie.beans.IWidgetInstance;
 import org.apache.wookie.server.security.ApiKey;
+import org.apache.wookie.server.security.ApiKeys;
 
 /**
  * An AuthToken used to pass contextual information about an instance of a
@@ -38,6 +40,27 @@ public class AuthToken {
 	private static final long CLOCK_SKEW_ALLOWANCE = 180; // allow three minutes for clock skew
 	private Long expiresAt;
 	private int tokenTTL;
+	
+	public AuthToken(){
+	}
+	
+	/**
+	 * Utility method for instantiating an authToken from a widget instance
+	 * Used for transition to new SPI model; marked as deprecated so we know to remove it
+	 * @param widgetInstance
+	 */
+	@Deprecated
+	public AuthToken(IWidgetInstance widgetInstance){
+		for (ApiKey apiKey : ApiKeys.getInstance().getKeys()){
+			if (apiKey.getValue().equals(widgetInstance.getApiKey())){
+				this.apiKey = apiKey;
+			}
+		}
+		this.viewerId = widgetInstance.getUserId();
+		this.widgetId = widgetInstance.getWidget().getIdentifier();
+		this.contextId = widgetInstance.getSharedDataKey();
+		this.lang = widgetInstance.getLang();
+	}
 
 	/**
 	 * @return The time in seconds since epoc that this token expires or
@@ -186,4 +209,20 @@ public class AuthToken {
 		return this.tokenTTL;
 	}
 
+	/* (non-Javadoc)
+	 * @see java.lang.Object#toString()
+	 */
+	@Override
+	public String toString() {
+		String token = "<token>";
+		token += "<apikey>"+apiKey.getValue()+"</apikey>";
+		token += "<widget>"+widgetId + "</widget>";
+		token += "<viewer>"+viewerId + "</viewer>";
+		token += "<context>" + contextId + "</context>";
+		token += "</token>";
+		return token;
+	}
+	
+	
+
 }