Skip to content
This repository has been archived by the owner on Apr 8, 2019. It is now read-only.

Commit

Permalink
GTNPORTAL-2458 Fix some bugs for GadgetTokenInfoService
Browse files Browse the repository at this point in the history
  • Loading branch information
kiennguyen authored and mstruk committed Aug 22, 2012
1 parent 7203991 commit b53f821
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
Expand Up @@ -15,7 +15,7 @@ public GadgetToken(String accessToken, String tokenSecret, String sessionHandle,

public boolean isExpired()
{
return false;
return System.currentTimeMillis() > getExpirationTimeMillis();
}

public long getExpirationTimeMillis()
Expand Down
Expand Up @@ -37,14 +37,15 @@ public GadgetToken removeToken(BasicOAuthStoreTokenIndex tokenKey)
BasicOAuthStoreTokenIndex key = tokenEntry.getKey();
if (tokenKey.equals(key))
{
GadgetToken token = tokenEntry.getToken();
tokenEntry.remove();
return tokenEntry.getToken();
return token;
}
}
return null;
}

public GadgetToken saveToken(BasicOAuthStoreTokenIndex tokenKey, TokenInfo tokenInfo)
public GadgetToken saveToken(BasicOAuthStoreTokenIndex tokenKey, TokenInfo tokenInfo, long expirationTime)
{
Map<String, GadgetTokenEntry> tokens = getGadgetTokens();
GadgetTokenEntry entry = null;
Expand All @@ -70,7 +71,7 @@ public GadgetToken saveToken(BasicOAuthStoreTokenIndex tokenKey, TokenInfo token
entry.setAccessToken(tokenInfo.getAccessToken());
entry.setTokenSecret(tokenInfo.getTokenSecret());
entry.setSessionHandle(tokenInfo.getSessionHandle() == null ? "" : tokenInfo.getSessionHandle());
entry.setTokenExpireMillis(tokenInfo.getTokenExpireMillis());
entry.setTokenExpireMillis(expirationTime);
return entry.getToken();
}
}
Expand Up @@ -70,6 +70,6 @@ public BasicOAuthStoreTokenIndex getKey()

public GadgetToken getToken()
{
return new GadgetToken(getAccessToken(), getTokenSecret(), getServiceName(), getTokenExpireMillis());
return new GadgetToken(getAccessToken(), getTokenSecret(), getSessionHandle(), getTokenExpireMillis());
}
}
Expand Up @@ -30,7 +30,9 @@
import org.exoplatform.web.security.security.AbstractTokenService;
import org.gatein.wci.security.Credentials;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class GadgetTokenInfoService extends AbstractTokenService<GadgetToken, BasicOAuthStoreTokenIndex>
{
Expand All @@ -51,7 +53,8 @@ public GadgetToken createToken(final BasicOAuthStoreTokenIndex key, final TokenI
protected GadgetToken execute()
{
GadgetTokenContainer container = getGadgetTokenContainer();
return container.saveToken(key, tokenInfo);
long expirationTimeMillis = System.currentTimeMillis() + validityMillis;
return container.saveToken(key, tokenInfo, expirationTimeMillis);
}
}.executeWith(chromatticLifeCycle);
}
Expand Down Expand Up @@ -91,13 +94,13 @@ public BasicOAuthStoreTokenIndex[] getAllTokens()
protected BasicOAuthStoreTokenIndex[] execute()
{
GadgetTokenContainer container = getGadgetTokenContainer();
Collection<GadgetTokenEntry> tokens = container.getGadgetTokens().values();
BasicOAuthStoreTokenIndex[] gadgetTokens = new BasicOAuthStoreTokenIndex[9];
int count = 0;
for(GadgetTokenEntry tokenEntry : tokens) {
gadgetTokens[count++] = tokenEntry.getKey();
Collection<GadgetTokenEntry> tokenEntries = container.getGadgetTokens().values();
List<BasicOAuthStoreTokenIndex> tokenHolder = new ArrayList<BasicOAuthStoreTokenIndex>();
for (GadgetTokenEntry tokenEntry : tokenEntries)
{
tokenHolder.add(tokenEntry.getKey());
}
return gadgetTokens;
return tokenHolder.toArray(new BasicOAuthStoreTokenIndex[tokenHolder.size()]);
}
}.executeWith(chromatticLifeCycle);
}
Expand Down

0 comments on commit b53f821

Please sign in to comment.