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/03/04 12:53:17 UTC
svn commit: r1574047 -
/wookie/trunk/wookie-server/src/main/java/org/apache/wookie/auth/AuthToken.java
Author: scottbw
Date: Tue Mar 4 11:53:16 2014
New Revision: 1574047
URL: http://svn.apache.org/r1574047
Log:
Added a single-use flag to AuthToken, and some convenience constructors for different kinds of token.
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=1574047&r1=1574046&r2=1574047&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 Tue Mar 4 11:53:16 2014
@@ -33,16 +33,90 @@ public class AuthToken {
private String viewerId;
private String contextId;
private String lang;
+ private boolean singleUse = false;
public static final int DEFAULT_MAX_TOKEN_TTL = 3600; // 1 hour
private static final long CLOCK_SKEW_ALLOWANCE = 180; // allow three minutes for clock skew
private Long expiresAt;
private int tokenTTL;
- public AuthToken(){
+ /**
+ * Default constructor
+ */
+ protected AuthToken(){
+ }
+
+ /**
+ * Create a new single-use AuthToken from an existing
+ * authtoken. This type of token can only be used to
+ * request a new token.
+ * @return the authtoken
+ */
+ public static AuthToken SINGLE_USE_TOKEN(AuthToken oldToken){
+ AuthToken authToken = new AuthToken();
+ authToken.setExpires(300); // 5 minutes
+ authToken.setSingleUse(true);
+ authToken.setApiKey(oldToken.getApiKeyInstance());
+ authToken.setContextId(oldToken.getContextId());
+ authToken.setWidgetId(oldToken.getWidgetId());
+ authToken.setViewerId(oldToken.getViewerId());
+ authToken.setLang(oldToken.getLang());
+ return authToken;
}
/**
+ * Create a new AuthToken with a 5 minute lifespon.
+ * @return the authtoken
+ */
+ public static AuthToken SHORT_LIFESPAN_TOKEN(){
+ AuthToken authToken = new AuthToken();
+ authToken.setExpires(300); // 5 minutes
+ return authToken;
+ }
+
+ /**
+ * Create a new AuthToken with a 5 minute lifespon from an existing
+ * authtoken
+ * @return the authtoken
+ */
+ public static AuthToken SHORT_LIFESPAN_TOKEN(AuthToken oldToken){
+ AuthToken authToken = new AuthToken();
+ authToken.setExpires(300); // 5 minutes
+ authToken.setApiKey(oldToken.getApiKeyInstance());
+ authToken.setContextId(oldToken.getContextId());
+ authToken.setWidgetId(oldToken.getWidgetId());
+ authToken.setViewerId(oldToken.getViewerId());
+ authToken.setLang(oldToken.getLang());
+ return authToken;
+ }
+
+ /**
+ * Create a new AuthToken with a standard lifespon
+ * @return the authtoken
+ */
+ public static AuthToken STANDARD_LIFESPAN_TOKEN(){
+ AuthToken authToken = new AuthToken();
+ authToken.setExpires();
+ return authToken;
+ }
+
+ /**
+ * Create a new AuthToken with a standard lifespon from an existing
+ * authtoken
+ * @return the authtoken
+ */
+ public static AuthToken STANDARD_LIFESPAN_TOKEN(AuthToken oldToken){
+ AuthToken authToken = new AuthToken();
+ authToken.setExpires();
+ authToken.setApiKey(oldToken.getApiKeyInstance());
+ authToken.setContextId(oldToken.getContextId());
+ authToken.setWidgetId(oldToken.getWidgetId());
+ authToken.setViewerId(oldToken.getViewerId());
+ authToken.setLang(oldToken.getLang());
+ return authToken;
+ }
+
+ /**
* @return The time in seconds since epoc that this token expires or
* <code>null</code> if unknown or indeterminate.
*/
@@ -188,6 +262,22 @@ public class AuthToken {
protected int getMaxTokenTTL() {
return this.tokenTTL;
}
+
+ /**
+ * Returns whether this token is a single-use token
+ * @return the singleUse
+ */
+ public boolean isSingleUse() {
+ return singleUse;
+ }
+
+ /**
+ * Set the token as single-use
+ * @param singleUse the singleUse to set
+ */
+ public void setSingleUse(boolean singleUse) {
+ this.singleUse = singleUse;
+ }
/* (non-Javadoc)
* @see java.lang.Object#toString()