use of edu.uiuc.ncsa.security.delegation.token.RefreshToken in project OA4MP by ncsa.
the class Client2AssetStoreTest method storeTest.
@Override
public Asset storeTest(AssetStore store) throws Exception {
OA2Asset asset = (OA2Asset) super.storeTest(store);
AccessToken at = new AccessTokenImpl(URI.create("oa4mp:accessToken:/" + ClientTestStoreUtil.getRandomString()));
RefreshToken rt = new OA2RefreshTokenImpl(URI.create("oa4mp:refreshToken:/" + ClientTestStoreUtil.getRandomString()));
rt.setExpiresIn(1000000L);
asset.setAccessToken(at);
asset.setRefreshToken(rt);
store.save(asset);
OA2Asset OA2Asset = (OA2Asset) store.get(asset.getIdentifier());
assert asset.getAccessToken().equals(OA2Asset.getAccessToken()) : "Failed to match access tokens. " + "Expected \"" + asset.getAccessToken() + "\" and got \"" + OA2Asset.getAccessToken() + "\"";
RefreshToken rt2 = OA2Asset.getRefreshToken();
assert rt.getToken().equals(rt2.getToken()) : "Failed to match refresh tokens. " + "Expected \"" + rt.getToken() + "\" and got \"" + rt2.getToken() + "\"";
assert rt.getExpiresIn() == rt2.getExpiresIn() : "Failed to match refresh lifetime. " + "Expected \"" + rt.getExpiresIn() + "\" and got \"" + rt2.getExpiresIn() + "\"";
return asset;
}
use of edu.uiuc.ncsa.security.delegation.token.RefreshToken in project OA4MP by ncsa.
the class AssetRetentionPolicy method retain.
@Override
public boolean retain(Object key, Object value) {
Identifier identifier = (Identifier) key;
OA2Asset oa2Asset = (OA2Asset) value;
RefreshToken rt = oa2Asset.getRefreshToken();
if (rt == null || rt.getToken() == null) {
return true;
}
// Now we have to check against the timestamp on the original and the expires in flag.
Date creationTS = DateUtils.getDate(oa2Asset.getRefreshToken().getToken());
if (creationTS.getTime() + oa2Asset.getRefreshToken().getExpiresIn() <= System.currentTimeMillis()) {
return true;
}
return false;
}
use of edu.uiuc.ncsa.security.delegation.token.RefreshToken in project OA4MP by ncsa.
the class OA2ATServlet method doAT.
protected IssuerTransactionState doAT(HttpServletRequest request, HttpServletResponse response, OA2Client client) throws Throwable {
verifyClientSecret(client, getClientSecret(request));
IssuerTransactionState state = doDelegation(client, request, response);
ATIResponse2 atResponse = (ATIResponse2) state.getIssuerResponse();
atResponse.setSignToken(client.isSignTokens());
DebugUtil.dbg(this, "set token signing flag =" + atResponse.isSignToken());
OA2ServiceTransaction st2 = (OA2ServiceTransaction) state.getTransaction();
if (!client.isRTLifetimeEnabled() && ((OA2SE) getServiceEnvironment()).isRefreshTokenEnabled()) {
// Since this bit of information could be extremely useful if a service decides
// eto start issuing refresh tokens after
// clients have been registered, it should be logged.
info("Refresh tokens are disabled for client " + client.getIdentifierString() + ", but enabled on the server. No refresh token will be madeg.");
}
if (client.isRTLifetimeEnabled() && ((OA2SE) getServiceEnvironment()).isRefreshTokenEnabled()) {
RefreshToken rt = atResponse.getRefreshToken();
st2.setRefreshToken(rt);
// First pass through the system should have the system default as the refresh token lifetime.
st2.setRefreshTokenLifetime(((OA2SE) getServiceEnvironment()).getRefreshTokenLifetime());
rt.setExpiresIn(computeRefreshLifetime(st2));
st2.setRefreshTokenValid(true);
} else {
// Do not return a refresh token.
atResponse.setRefreshToken(null);
}
getTransactionStore().save(st2);
return state;
}
use of edu.uiuc.ncsa.security.delegation.token.RefreshToken in project OA4MP by ncsa.
the class RefreshTokenStoreTest method testRT.
public void testRT(TransactionStore tStore) throws Exception {
if (!(tStore instanceof RefreshTokenStore)) {
// fail here if can't cast
throw new IllegalStateException("Error: The store " + tStore.getClass().getSimpleName() + " is not of a type RefreshTokenStore");
}
RefreshTokenStore rts = (RefreshTokenStore) tStore;
OA2ServiceTransaction st2 = (OA2ServiceTransaction) tStore.create();
OA2TokenForge tf2 = new OA2TokenForge("http://localhost/test/");
RefreshToken rt = tf2.getRefreshToken();
st2.setRefreshToken(rt);
// the auth grant is used to retrieve this later and should in this case just be set to the identifier.
AuthorizationGrant ag = tf2.getAuthorizationGrant(st2.getIdentifierString());
st2.setAuthorizationGrant(ag);
st2.setRefreshTokenLifetime(EXPIRES_IN);
tStore.save(st2);
OA2ServiceTransaction testST = rts.get(rt);
assert testST.equals(st2) : "Error: created transaction is not fetched faithfully from the store";
// get another one and retry since we have to be able to show the store can handle updating the refresh token
rt = tf2.getRefreshToken();
st2.setRefreshToken(rt);
st2.setRefreshTokenValid(false);
tStore.save(st2);
assert rts.get(rt).equals(st2) : "Error: updating refresh token fails.";
}
use of edu.uiuc.ncsa.security.delegation.token.RefreshToken in project OA4MP by ncsa.
the class RefreshTokenRetentionPolicy method retain.
@Override
public boolean retain(Object key, Object value) {
OA2ServiceTransaction st2 = (OA2ServiceTransaction) value;
RefreshToken rt = st2.getRefreshToken();
long timeout = st2.getRefreshTokenLifetime();
if (rt == null || rt.getToken() == null) {
// fall back to looking at the access token timestamp. Failing that, fall back to the creation time from
// the identifier.
String token;
token = (st2.getAccessToken() == null ? st2.getIdentifierString() : st2.getAccessToken().getToken());
try {
DateUtils.checkTimestamp(token);
} catch (InvalidTimestampException its) {
return false;
}
return true;
}
try {
if (timeout <= 0) {
// use default????
DateUtils.checkTimestamp(rt.getToken());
} else {
DateUtils.checkTimestamp(rt.getToken(), timeout);
}
return true;
} catch (InvalidTimestampException its) {
return false;
}
}
Aggregations