use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl in project carbon-apimgt by wso2.
the class APIMgtDAOTest method setUp.
@Before
public void setUp() throws Exception {
String dbConfigPath = System.getProperty("APIManagerDBConfigurationPath");
APIManagerConfiguration config = new APIManagerConfiguration();
initializeDatabase(dbConfigPath);
config.load(dbConfigPath);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(new APIManagerConfigurationServiceImpl(config));
List<Notifier> notifierList = new ArrayList<>();
Notifier subscriptionsNotifier = Mockito.mock(Notifier.class);
Mockito.when(subscriptionsNotifier.getType()).thenReturn(APIConstants.NotifierType.SUBSCRIPTIONS.name());
notifierList.add(subscriptionsNotifier);
ServiceReferenceHolder.getInstance().getNotifiersMap().put(subscriptionsNotifier.getType(), notifierList);
PowerMockito.mockStatic(KeyManagerHolder.class);
keyManager = Mockito.mock(KeyManager.class);
APIMgtDBUtil.initialize();
apiMgtDAO = ApiMgtDAO.getInstance();
IdentityTenantUtil.setRealmService(new TestRealmService());
String identityConfigPath = System.getProperty("IdentityConfigurationPath");
IdentityConfigParser.getInstance(identityConfigPath);
OAuthServerConfiguration oAuthServerConfiguration = OAuthServerConfiguration.getInstance();
ServiceReferenceHolder.getInstance().setOauthServerConfiguration(oAuthServerConfiguration);
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl in project carbon-apimgt by wso2.
the class APIManagerComponent method activate.
@Activate
protected void activate(ComponentContext componentContext) throws Exception {
if (log.isDebugEnabled()) {
log.debug("API manager component activated");
}
try {
BundleContext bundleContext = componentContext.getBundleContext();
addRxtConfigs();
addApplicationsPermissionsToRegistry();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String filePath = CarbonUtils.getCarbonConfigDirPath() + File.separator + "api-manager.xml";
configuration.load(filePath);
String gatewayType = configuration.getFirstProperty(APIConstants.API_GATEWAY_TYPE);
if (APIConstants.API_GATEWAY_TYPE_SYNAPSE.equalsIgnoreCase(gatewayType)) {
addDefinedSequencesToRegistry();
}
CommonConfigDeployer configDeployer = new CommonConfigDeployer();
bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), configDeployer, null);
TenantLoadMessageSender tenantLoadMessageSender = new TenantLoadMessageSender();
bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), tenantLoadMessageSender, null);
KeyMgtConfigDeployer keyMgtConfigDeployer = new KeyMgtConfigDeployer();
bundleContext.registerService(Axis2ConfigurationContextObserver.class.getName(), keyMgtConfigDeployer, null);
// Registering Notifiers
bundleContext.registerService(Notifier.class.getName(), new SubscriptionsNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ApisNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ApplicationNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ApplicationRegistrationNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new PolicyNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new DeployAPIInGatewayNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ScopesNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new CertificateNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new GoogleAnalyticsNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ExternalGatewayNotifier(), null);
bundleContext.registerService(Notifier.class.getName(), new ExternallyDeployedApiNotifier(), null);
APIManagerConfigurationServiceImpl configurationService = new APIManagerConfigurationServiceImpl(configuration);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(configurationService);
APIMgtDBUtil.initialize();
APIMConfigService apimConfigService = new APIMConfigServiceImpl();
bundleContext.registerService(APIMConfigService.class.getName(), apimConfigService, null);
APIUtil.loadAndSyncTenantConf(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
APIUtil.loadTenantExternalStoreConfig(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
APIUtil.loadTenantGAConfig(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
APIUtil.loadTenantWorkFlowExtensions(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
// load self sigup configuration to the registry
APIUtil.loadTenantSelfSignUpConfigurations(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
APIUtil.loadCommonOperationPolicies(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
APIManagerAnalyticsConfiguration analyticsConfiguration = APIManagerAnalyticsConfiguration.getInstance();
analyticsConfiguration.setAPIManagerConfiguration(configuration);
registration = componentContext.getBundleContext().registerService(APIManagerConfigurationService.class.getName(), configurationService, null);
KeyManagerConfigurationServiceImpl keyManagerConfigurationService = new KeyManagerConfigurationServiceImpl();
registration = componentContext.getBundleContext().registerService(KeyManagerConfigurationService.class, keyManagerConfigurationService, null);
JWTValidationService jwtValidationService = new JWTValidationServiceImpl();
registration = componentContext.getBundleContext().registerService(JWTValidationService.class, jwtValidationService, null);
ServiceReferenceHolder.getInstance().setKeyManagerConfigurationService(keyManagerConfigurationService);
APIStatusObserverList.getInstance().init(configuration);
log.debug("Reading Analytics Configuration from file...");
// This method is called in two places. Mostly by the time activate hits,
// ServiceDataPublisherAdmin is not activated. Therefore, this same method is run,
// when ServiceDataPublisherAdmin is set.
AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_CREATOR_APIMGT_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_APPLICATION_DATA_LOCATION), APIConstants.Permissions.API_CREATE, UserMgtConstants.EXECUTE_ACTION, null);
AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_CREATOR_GOVERNANCE_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + "/trunk"), APIConstants.Permissions.API_CREATE, UserMgtConstants.EXECUTE_ACTION, null);
AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_PUBLISHER_APIMGT_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_APPLICATION_DATA_LOCATION), APIConstants.Permissions.API_PUBLISH, UserMgtConstants.EXECUTE_ACTION, null);
// Enabling API Publishers/Creators to make changes on life-cycle history.
AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_CREATOR_LIFECYCLE_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_LIFE_CYCLE_HISTORY), APIConstants.Permissions.API_CREATE, UserMgtConstants.EXECUTE_ACTION, null);
AuthorizationUtils.addAuthorizeRoleListener(APIConstants.AM_PUBLISHER_LIFECYCLE_EXECUTION_ID, RegistryUtils.getAbsolutePath(RegistryContext.getBaseInstance(), APIUtil.getMountedPath(RegistryContext.getBaseInstance(), RegistryConstants.GOVERNANCE_REGISTRY_BASE_PATH) + APIConstants.API_LIFE_CYCLE_HISTORY), APIConstants.Permissions.API_PUBLISH, UserMgtConstants.EXECUTE_ACTION, null);
setupImagePermissions();
GatewayArtifactsMgtDBUtil.initialize();
configureEventPublisherProperties();
configureNotificationEventPublisher();
// Load initially available api contexts at the server startup. This Cache is only use by the products other than the api-manager
/* TODO: Load Config values from apimgt.core*/
boolean apiManagementEnabled = APIUtil.isAPIManagementEnabled();
boolean loadAPIContextsAtStartup = APIUtil.isLoadAPIContextsAtStartup();
if (apiManagementEnabled && loadAPIContextsAtStartup) {
List<String> contextList = ApiMgtDAO.getInstance().getAllAvailableContexts();
Cache contextCache = APIUtil.getAPIContextCache();
for (String context : contextList) {
contextCache.put(context, Boolean.TRUE);
}
}
try {
APIUtil.createDefaultRoles(MultitenantConstants.SUPER_TENANT_ID);
} catch (APIManagementException e) {
log.error("Failed create default roles for tenant " + MultitenantConstants.SUPER_TENANT_ID, e);
} catch (Exception e) {
// The generic Exception is handled explicitly so execution does not stop during config deployment
log.error("Exception when creating default roles for tenant " + MultitenantConstants.SUPER_TENANT_ID, e);
}
// Adding default throttle policies
addDefaultAdvancedThrottlePolicies();
// Update all NULL THROTTLING_TIER values to Unlimited
boolean isNullThrottlingTierConversionEnabled = APIUtil.updateNullThrottlingTierAtStartup();
try {
if (isNullThrottlingTierConversionEnabled) {
ApiMgtDAO.getInstance().convertNullThrottlingTiers();
}
} catch (APIManagementException e) {
log.error("Failed to convert NULL THROTTLING_TIERS to Unlimited");
}
// // Initialise KeyManager.
// KeyManagerHolder.initializeKeyManager(configuration);
// Initialise sql constants
SQLConstantManagerFactory.initializeSQLConstantManager();
// Initialize PasswordResolver
PasswordResolverFactory.initializePasswordResolver();
APIUtil.init();
// Activating UserPostSelfRegistration handler componeAPITemplateBuilderImplnt
try {
registration = componentContext.getBundleContext().registerService(AbstractEventHandler.class.getName(), new UserPostSelfRegistrationHandler(), null);
} catch (Exception e) {
log.error("Error while activating UserPostSelfRegistration handler component.", e);
}
// Read the trust store
ServerConfiguration config = CarbonUtils.getServerConfiguration();
// Initialize product REST API token caches
CacheProvider.createRESTAPITokenCache();
CacheProvider.createRESTAPIInvalidTokenCache();
CacheProvider.createGatewayJWTTokenCache();
CacheProvider.createTenantConfigCache();
CacheProvider.createRecommendationsCache();
CacheProvider.createParsedSignJWTCache();
CacheProvider.createGatewayBasicAuthResourceCache();
CacheProvider.createGatewayUsernameCache();
CacheProvider.createIntrospectionCache();
// Initialize Recommendation wso2event output publisher
configureRecommendationEventPublisherProperties();
setupAccessTokenGenerator();
retrieveAndSetParentTrustStore();
if (configuration.getGatewayArtifactSynchronizerProperties().isRetrieveFromStorageEnabled()) {
if (APIConstants.GatewayArtifactSynchronizer.DB_RETRIEVER_NAME.equals(configuration.getGatewayArtifactSynchronizerProperties().getRetrieverName())) {
bundleContext.registerService(ArtifactRetriever.class.getName(), new DBRetriever(), null);
}
}
bundleContext.registerService(ScopeValidator.class, new SystemScopesIssuer(), null);
} catch (APIManagementException e) {
log.error("Error while initializing the API manager component", e);
} catch (APIManagerDatabaseException e) {
log.fatal("Error while Creating the database", e);
}
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl in project carbon-apimgt by wso2.
the class UserSignUpSimpleWorkflowExecutorTest method init.
@Before
public void init() throws Exception {
userSignUpSimpleWorkflowExecutor = new UserSignUpSimpleWorkflowExecutor();
workflowDTO = new WorkflowDTO();
workflowDTO.setExternalWorkflowReference("12345");
workflowDTO.setTenantDomain(tenantDomain);
workflowDTO.setStatus(WorkflowStatus.APPROVED);
workflowDTO.setWorkflowReference(username);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
RealmService realmService = Mockito.mock(RealmService.class);
TenantManager tenantManager = Mockito.mock(TenantManager.class);
UserRealm userRealm = Mockito.mock(UserRealm.class);
userStoreManager = Mockito.mock(UserStoreManager.class);
ServiceClient serviceClient = Mockito.mock(ServiceClient.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
PowerMockito.mockStatic(SelfSignUpUtil.class);
PowerMockito.mockStatic(CarbonUtils.class);
Mockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(apiManagerConfiguration);
Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService);
Mockito.when(serviceReferenceHolder.getRealmService()).thenReturn(realmService);
Mockito.when(realmService.getTenantManager()).thenReturn(tenantManager);
Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
Mockito.when(tenantManager.getTenantId(tenantDomain)).thenReturn(tenantID);
Mockito.when(realmService.getTenantUserRealm(tenantID)).thenReturn(userRealm);
Mockito.when(userRealm.getUserStoreManager()).thenReturn(userStoreManager);
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl in project carbon-apimgt by wso2.
the class WebSubConfigContextTest method testWithSecretConfigContextForAPI.
@Test
public void testWithSecretConfigContextForAPI() throws Exception {
API api = new API(new APIIdentifier("admin", "websubAPI", "1.0.0"));
api.setStatus(APIConstants.CREATED);
api.setContextTemplate("/websub");
api.setTransports(Constants.TRANSPORT_HTTP);
api.setEndpointSecured(false);
api.setUriTemplates(setAPIUriTemplates());
api.setType(APIConstants.APITransportType.WEBSUB.toString());
WebsubSubscriptionConfiguration webSubConfig = new WebsubSubscriptionConfiguration(true, "9207975e1fef9c41fab41645f81dbf0f", "SHA1", "x-hub-signature");
api.setWebsubSubscriptionConfiguration(webSubConfig);
Environment environment = new Environment();
environment.setType("production");
config = Mockito.mock(APIManagerConfiguration.class);
APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(config);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
String templatePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator;
System.setProperty("carbon.home", templatePath);
APITemplateBuilderImpl apiTemplateBuilder = new APITemplateBuilderImpl(api, null, null);
String updatedTemplate = apiTemplateBuilder.getConfigStringForTemplate(environment);
Assert.assertTrue("The websub velocity template is not updated correctly", updatedTemplate.contains("generated_signature"));
}
use of org.wso2.carbon.apimgt.impl.APIManagerConfigurationServiceImpl in project carbon-apimgt by wso2.
the class WebSubConfigContextTest method testWithoutSecretConfigContextForAPI.
@Test
public void testWithoutSecretConfigContextForAPI() throws Exception {
API api = new API(new APIIdentifier("admin", "websubAPI", "1.0.0"));
api.setStatus(APIConstants.CREATED);
api.setContextTemplate("/websub");
api.setTransports(Constants.TRANSPORT_HTTP);
api.setEndpointSecured(false);
api.setUriTemplates(setAPIUriTemplates());
api.setType(APIConstants.APITransportType.WEBSUB.toString());
WebsubSubscriptionConfiguration webSubConfig = new WebsubSubscriptionConfiguration(false, "", "", "");
api.setWebsubSubscriptionConfiguration(webSubConfig);
Environment environment = new Environment();
environment.setType("production");
config = Mockito.mock(APIManagerConfiguration.class);
APIManagerConfigurationService apiManagerConfigurationService = new APIManagerConfigurationServiceImpl(config);
ServiceReferenceHolder.getInstance().setAPIManagerConfigurationService(apiManagerConfigurationService);
String templatePath = System.getProperty("user.dir") + File.separator + "src" + File.separator + "test" + File.separator + "resources" + File.separator;
System.setProperty("carbon.home", templatePath);
APITemplateBuilderImpl apiTemplateBuilder = new APITemplateBuilderImpl(api, null, null);
String updatedTemplate = apiTemplateBuilder.getConfigStringForTemplate(environment);
Assert.assertFalse("The websub velocity template is not updated correctly", updatedTemplate.contains("generated_signature"));
}
Aggregations