Search in sources :

Example 1 with TokenStateService

use of org.apache.knox.gateway.services.security.token.TokenStateService in project knox by apache.

the class CommonJWTFilterTest method doTestIsStillValid.

private boolean doTestIsStillValid(final Long expiration) throws Exception {
    TokenStateService tss = EasyMock.createNiceMock(TokenStateService.class);
    EasyMock.expect(tss.getTokenExpiration(anyObject(JWT.class))).andReturn(expiration).anyTimes();
    EasyMock.expect(tss.getTokenExpiration(anyObject(String.class))).andReturn(expiration).anyTimes();
    EasyMock.replay(tss);
    return doTestIsStillValid(tss);
}
Also used : TokenStateService(org.apache.knox.gateway.services.security.token.TokenStateService)

Example 2 with TokenStateService

use of org.apache.knox.gateway.services.security.token.TokenStateService in project knox by apache.

the class CommonJWTFilterTest method testIsStillValidUnknownToken.

@Test(expected = UnknownTokenException.class)
public void testIsStillValidUnknownToken() throws Exception {
    TokenStateService tss = EasyMock.createNiceMock(TokenStateService.class);
    final String tokenId = UUID.randomUUID().toString();
    EasyMock.expect(tss.getTokenExpiration(anyObject(JWT.class))).andThrow(new UnknownTokenException(tokenId)).anyTimes();
    EasyMock.expect(tss.getTokenExpiration(anyObject(String.class))).andThrow(new UnknownTokenException(tokenId)).anyTimes();
    EasyMock.replay(tss);
    doTestIsStillValid(tss);
}
Also used : UnknownTokenException(org.apache.knox.gateway.services.security.token.UnknownTokenException) TokenStateService(org.apache.knox.gateway.services.security.token.TokenStateService) Test(org.junit.Test)

Example 3 with TokenStateService

use of org.apache.knox.gateway.services.security.token.TokenStateService in project knox by apache.

the class TokenStateServiceFactoryTest method shouldReturnAliasBasedTokenStateService.

@Test
public void shouldReturnAliasBasedTokenStateService() throws Exception {
    final TokenStateService tokenStateService = (TokenStateService) serviceFactory.create(gatewayServices, ServiceType.TOKEN_STATE_SERVICE, gatewayConfig, options, AliasBasedTokenStateService.class.getName());
    assertTrue(tokenStateService instanceof AliasBasedTokenStateService);
    assertTrue(isAliasServiceSet(tokenStateService));
}
Also used : AliasBasedTokenStateService(org.apache.knox.gateway.services.token.impl.AliasBasedTokenStateService) DefaultTokenStateService(org.apache.knox.gateway.services.token.impl.DefaultTokenStateService) AliasBasedTokenStateService(org.apache.knox.gateway.services.token.impl.AliasBasedTokenStateService) JournalBasedTokenStateService(org.apache.knox.gateway.services.token.impl.JournalBasedTokenStateService) ZookeeperTokenStateService(org.apache.knox.gateway.services.token.impl.ZookeeperTokenStateService) TokenStateService(org.apache.knox.gateway.services.security.token.TokenStateService) Test(org.junit.Test)

Example 4 with TokenStateService

use of org.apache.knox.gateway.services.security.token.TokenStateService in project knox by apache.

the class TokenStateServiceFactoryTest method shouldReturnAliasBasedTokenStateServiceByDefault.

@Test
public void shouldReturnAliasBasedTokenStateServiceByDefault() throws Exception {
    TokenStateService tokenStateService = (TokenStateService) serviceFactory.create(gatewayServices, ServiceType.TOKEN_STATE_SERVICE, gatewayConfig, options, "");
    assertTrue(tokenStateService instanceof AliasBasedTokenStateService);
    assertTrue(isAliasServiceSet(tokenStateService));
}
Also used : AliasBasedTokenStateService(org.apache.knox.gateway.services.token.impl.AliasBasedTokenStateService) DefaultTokenStateService(org.apache.knox.gateway.services.token.impl.DefaultTokenStateService) AliasBasedTokenStateService(org.apache.knox.gateway.services.token.impl.AliasBasedTokenStateService) JournalBasedTokenStateService(org.apache.knox.gateway.services.token.impl.JournalBasedTokenStateService) ZookeeperTokenStateService(org.apache.knox.gateway.services.token.impl.ZookeeperTokenStateService) TokenStateService(org.apache.knox.gateway.services.security.token.TokenStateService) Test(org.junit.Test)

Example 5 with TokenStateService

use of org.apache.knox.gateway.services.security.token.TokenStateService in project knox by apache.

the class TokenStateServiceFactoryTest method shouldReturnDefaultTokenStateService.

@Test
public void shouldReturnDefaultTokenStateService() throws Exception {
    TokenStateService tokenStateService = (TokenStateService) serviceFactory.create(gatewayServices, ServiceType.TOKEN_STATE_SERVICE, gatewayConfig, options, DefaultTokenStateService.class.getName());
    assertTrue(tokenStateService instanceof DefaultTokenStateService);
}
Also used : DefaultTokenStateService(org.apache.knox.gateway.services.token.impl.DefaultTokenStateService) DefaultTokenStateService(org.apache.knox.gateway.services.token.impl.DefaultTokenStateService) AliasBasedTokenStateService(org.apache.knox.gateway.services.token.impl.AliasBasedTokenStateService) JournalBasedTokenStateService(org.apache.knox.gateway.services.token.impl.JournalBasedTokenStateService) ZookeeperTokenStateService(org.apache.knox.gateway.services.token.impl.ZookeeperTokenStateService) TokenStateService(org.apache.knox.gateway.services.security.token.TokenStateService) Test(org.junit.Test)

Aggregations

TokenStateService (org.apache.knox.gateway.services.security.token.TokenStateService)28 Test (org.junit.Test)21 JWTToken (org.apache.knox.gateway.services.security.token.impl.JWTToken)14 HashSet (java.util.HashSet)5 Map (java.util.Map)5 Field (java.lang.reflect.Field)4 HashMap (java.util.HashMap)4 UnknownTokenException (org.apache.knox.gateway.services.security.token.UnknownTokenException)3 JWT (org.apache.knox.gateway.services.security.token.impl.JWT)3 AliasBasedTokenStateService (org.apache.knox.gateway.services.token.impl.AliasBasedTokenStateService)3 DefaultTokenStateService (org.apache.knox.gateway.services.token.impl.DefaultTokenStateService)3 JournalBasedTokenStateService (org.apache.knox.gateway.services.token.impl.JournalBasedTokenStateService)3 ZookeeperTokenStateService (org.apache.knox.gateway.services.token.impl.ZookeeperTokenStateService)3 ServiceLifecycleException (org.apache.knox.gateway.services.ServiceLifecycleException)2 TokenMetadata (org.apache.knox.gateway.services.security.token.TokenMetadata)2 TokenStateJournal (org.apache.knox.gateway.services.token.state.TokenStateJournal)2 EasyMock.anyString (org.easymock.EasyMock.anyString)1