Search in sources :

Example 1 with APIMgtGatewayJWTGeneratorImpl

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);
}
Also used : ServiceReferenceHolder(org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) ExtendedJWTConfigurationDto(org.wso2.carbon.apimgt.impl.dto.ExtendedJWTConfigurationDto) APIMgtGatewayJWTGeneratorImpl(org.wso2.carbon.apimgt.common.gateway.jwtgenerator.APIMgtGatewayJWTGeneratorImpl) APIManagerConfigurationService(org.wso2.carbon.apimgt.impl.APIManagerConfigurationService) AbstractAPIMgtGatewayJWTGenerator(org.wso2.carbon.apimgt.common.gateway.jwtgenerator.AbstractAPIMgtGatewayJWTGenerator) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with APIMgtGatewayJWTGeneratorImpl

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();
}
Also used : ServerStartupObserver(org.wso2.carbon.core.ServerStartupObserver) APIMgtGatewayJWTGeneratorImpl(org.wso2.carbon.apimgt.common.gateway.jwtgenerator.APIMgtGatewayJWTGeneratorImpl) RedisBaseDistributedCountManager(org.wso2.carbon.apimgt.gateway.RedisBaseDistributedCountManager) APIMgtGatewayUrlSafeJWTGeneratorImpl(org.wso2.carbon.apimgt.common.gateway.jwtgenerator.APIMgtGatewayUrlSafeJWTGeneratorImpl) GatewayStartupListener(org.wso2.carbon.apimgt.gateway.listeners.GatewayStartupListener) Axis2ConfigurationContextObserver(org.wso2.carbon.utils.Axis2ConfigurationContextObserver) ServerStartupListener(org.wso2.carbon.apimgt.gateway.listeners.ServerStartupListener) BundleContext(org.osgi.framework.BundleContext) RevokedJWTMapCleaner(org.wso2.carbon.apimgt.gateway.jwt.RevokedJWTMapCleaner) RedisConfig(org.wso2.carbon.apimgt.impl.dto.RedisConfig) Activate(org.osgi.service.component.annotations.Activate)

Aggregations

APIMgtGatewayJWTGeneratorImpl (org.wso2.carbon.apimgt.common.gateway.jwtgenerator.APIMgtGatewayJWTGeneratorImpl)2 Test (org.junit.Test)1 BundleContext (org.osgi.framework.BundleContext)1 Activate (org.osgi.service.component.annotations.Activate)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1 APIMgtGatewayUrlSafeJWTGeneratorImpl (org.wso2.carbon.apimgt.common.gateway.jwtgenerator.APIMgtGatewayUrlSafeJWTGeneratorImpl)1 AbstractAPIMgtGatewayJWTGenerator (org.wso2.carbon.apimgt.common.gateway.jwtgenerator.AbstractAPIMgtGatewayJWTGenerator)1 RedisBaseDistributedCountManager (org.wso2.carbon.apimgt.gateway.RedisBaseDistributedCountManager)1 RevokedJWTMapCleaner (org.wso2.carbon.apimgt.gateway.jwt.RevokedJWTMapCleaner)1 GatewayStartupListener (org.wso2.carbon.apimgt.gateway.listeners.GatewayStartupListener)1 ServerStartupListener (org.wso2.carbon.apimgt.gateway.listeners.ServerStartupListener)1 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)1 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)1 ExtendedJWTConfigurationDto (org.wso2.carbon.apimgt.impl.dto.ExtendedJWTConfigurationDto)1 RedisConfig (org.wso2.carbon.apimgt.impl.dto.RedisConfig)1 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)1 ServerStartupObserver (org.wso2.carbon.core.ServerStartupObserver)1 Axis2ConfigurationContextObserver (org.wso2.carbon.utils.Axis2ConfigurationContextObserver)1