use of org.wso2.carbon.apimgt.common.gateway.jwtgenerator.APIMgtGatewayJWTGeneratorImpl in project carbon-apimgt by wso2.
the class APIMgtGatewayJWTGeneratorImplTest method testJWTGeneratorClaimConfig.
@Test
public void testJWTGeneratorClaimConfig() {
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
APIManagerConfigurationService apiManagerConfigurationService = Mockito.mock(APIManagerConfigurationService.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration);
ExtendedJWTConfigurationDto jwtConfigurationDto = Mockito.mock(ExtendedJWTConfigurationDto.class);
Mockito.when(apiManagerConfiguration.getJwtConfigurationDto()).thenReturn(jwtConfigurationDto);
String defaultDialectUri = "http://wso2.org/claims";
// default dialect if not changed
AbstractAPIMgtGatewayJWTGenerator generator = new APIMgtGatewayJWTGeneratorImpl();
// Set jwtConfigurationDto
generator.setJWTConfigurationDto(jwtConfigurationDto);
Assert.assertEquals(generator.getDialectURI(), ClaimsRetriever.DEFAULT_DIALECT_URI);
// Test dialect after changing it through config
String claimDialect = "http://test.com";
Mockito.when(jwtConfigurationDto.getConsumerDialectUri()).thenReturn(claimDialect);
generator = new APIMgtGatewayJWTGeneratorImpl();
generator.setJWTConfigurationDto(jwtConfigurationDto);
Assert.assertEquals(generator.getDialectURI(), claimDialect);
}
use of org.wso2.carbon.apimgt.common.gateway.jwtgenerator.APIMgtGatewayJWTGeneratorImpl in project carbon-apimgt by wso2.
the class APIHandlerServiceComponent method activate.
@Activate
protected void activate(ComponentContext context) {
BundleContext bundleContext = context.getBundleContext();
if (log.isDebugEnabled()) {
log.debug("API handlers component activated");
}
// Set public cert
ServiceReferenceHolder.getInstance().setPublicCert();
// Set private key
ServiceReferenceHolder.getInstance().setPrivateKey();
clientPool = APIKeyValidatorClientPool.getInstance();
GatewayStartupListener gatewayStartupListener = new GatewayStartupListener();
bundleContext.registerService(ServerStartupObserver.class.getName(), gatewayStartupListener, null);
bundleContext.registerService(ServerShutdownHandler.class, gatewayStartupListener, null);
bundleContext.registerService(Axis2ConfigurationContextObserver.class, gatewayStartupListener, null);
bundleContext.registerService(JMSListenerShutDownService.class, gatewayStartupListener, null);
// Register Tenant service creator to deploy tenant specific common synapse configurations
TenantServiceCreator listener = new TenantServiceCreator();
bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), listener, null);
bundleContext.registerService(ServerStartupObserver.class.getName(), new ServerStartupListener(), null);
// Set APIM Gateway JWT Generator
registration = context.getBundleContext().registerService(AbstractAPIMgtGatewayJWTGenerator.class.getName(), new APIMgtGatewayJWTGeneratorImpl(), null);
registration = context.getBundleContext().registerService(AbstractAPIMgtGatewayJWTGenerator.class.getName(), new APIMgtGatewayUrlSafeJWTGeneratorImpl(), null);
// Start JWT revoked map cleaner.
RevokedJWTMapCleaner revokedJWTMapCleaner = new RevokedJWTMapCleaner();
revokedJWTMapCleaner.startJWTRevokedMapCleaner();
ServiceReferenceHolder.getInstance().setTracer(ServiceReferenceHolder.getInstance().getTracingService().buildTracer(APIMgtGatewayConstants.SERVICE_NAME));
RedisConfig redisConfig = ServiceReferenceHolder.getInstance().getAPIManagerConfiguration().getRedisConfig();
if (redisConfig.isRedisEnabled()) {
RedisBaseDistributedCountManager redisBaseDistributedCountManager = new RedisBaseDistributedCountManager(ServiceReferenceHolder.getInstance().getRedisPool());
context.getBundleContext().registerService(DistributedCounterManager.class, redisBaseDistributedCountManager, null);
ServiceReferenceHolder.getInstance().setRedisPool(getJedisPool(redisConfig));
}
// Create caches for the super tenant
ServerConfiguration.getInstance().overrideConfigurationProperty("Cache.ForceLocalCache", "true");
CacheProvider.createGatewayKeyCache();
CacheProvider.createResourceCache();
CacheProvider.createGatewayTokenCache();
CacheProvider.createInvalidTokenCache();
CacheProvider.createGatewayBasicAuthResourceCache();
CacheProvider.createGatewayUsernameCache();
CacheProvider.createInvalidUsernameCache();
CacheProvider.createGatewayApiKeyCache();
CacheProvider.createGatewayApiKeyDataCache();
CacheProvider.createInvalidGatewayApiKeyCache();
CacheProvider.createParsedSignJWTCache();
CacheProvider.createGatewayInternalKeyCache();
CacheProvider.createGatewayInternalKeyDataCache();
CacheProvider.createInvalidInternalKeyCache();
}
Aggregations