use of org.apache.knox.gateway.services.security.token.TokenStateService in project knox by apache.
the class DefaultTokenStateServiceTest method testGetExpiration.
@Test
public void testGetExpiration() throws Exception {
final JWTToken token = createMockToken(System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(60));
final TokenStateService tss = createTokenStateService();
addToken(tss, token, System.currentTimeMillis());
long expiration = tss.getTokenExpiration(TokenUtils.getTokenId(token));
assertEquals(token.getExpiresDate().getTime(), expiration);
}
use of org.apache.knox.gateway.services.security.token.TokenStateService in project knox by apache.
the class DefaultTokenStateServiceTest method testIsExpired_Positive.
@Test
public void testIsExpired_Positive() throws Exception {
final JWTToken token = createMockToken(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(60));
final TokenStateService tss = createTokenStateService();
addToken(tss, token, System.currentTimeMillis());
assertTrue(tss.isExpired(token));
}
use of org.apache.knox.gateway.services.security.token.TokenStateService in project knox by apache.
the class DefaultTokenStateServiceTest method testNegativeTokenEviction.
@Test
public void testNegativeTokenEviction() throws Exception {
final JWTToken token = createMockToken(System.currentTimeMillis() - TimeUnit.SECONDS.toMillis(60));
final TokenStateService tss = createTokenStateService();
final long evictionInterval = TimeUnit.SECONDS.toMillis(3);
final long maxTokenLifetime = TimeUnit.MINUTES.toMillis(2);
// Add the expired token
addToken(tss, token.getClaim(JWTToken.KNOX_ID_CLAIM), System.currentTimeMillis(), token.getExpiresDate().getTime(), maxTokenLifetime);
assertTrue("Expected the token to have expired.", tss.isExpired(token));
// Sleep to allow the eviction evaluation to be performed prior to the maximum token lifetime
Thread.sleep(evictionInterval + (evictionInterval / 2));
// Renewal should succeed because there is sufficient time until expiration + grace period is exceeded
tss.renewToken(token, TimeUnit.SECONDS.toMillis(10));
assertFalse("Expected the token to have been renewed.", tss.isExpired(token));
}
use of org.apache.knox.gateway.services.security.token.TokenStateService in project knox by apache.
the class DefaultTokenStateServiceTest method createTokenStateService.
protected TokenStateService createTokenStateService() throws Exception {
TokenStateService tss = new DefaultTokenStateService();
initTokenStateService(tss);
return tss;
}
use of org.apache.knox.gateway.services.security.token.TokenStateService in project knox by apache.
the class DefaultTokenStateServiceTest method testTokenPermissivenessNoExpiry.
@Test(expected = UnknownTokenException.class)
public void testTokenPermissivenessNoExpiry() throws Exception {
final JWT token = getJWTToken(-1L);
TokenStateService tss = new DefaultTokenStateService();
try {
tss.init(createMockGatewayConfig(true), Collections.emptyMap());
} catch (ServiceLifecycleException e) {
fail("Error creating TokenStateService: " + e.getMessage());
}
tss.getTokenExpiration(token);
}
Aggregations