use of org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager in project carbon-identity-framework by wso2.
the class CORSManagementServiceTests method setUp.
@BeforeMethod
public void setUp() throws Exception {
DatabaseUtils.initiateH2Base();
CarbonUtils.setCarbonHome();
CarbonUtils.mockCarbonContextForTenant(SUPER_TENANT_ID, SUPER_TENANT_DOMAIN_NAME);
CarbonUtils.mockIdentityTenantUtility();
CarbonUtils.mockRealmService();
CarbonUtils.mockApplicationManagementService();
connection = DatabaseUtils.createDataSource();
configurationManager = ConfigurationManagementUtils.getConfigurationManager();
corsManagementService = new CORSManagementServiceImpl();
CORSManagementServiceHolder.getInstance().setConfigurationManager(configurationManager);
// Skip caches for testing.
corsOriginDAO = new CORSOriginDAOImpl();
CORSManagementServiceHolder.getInstance().setCorsOriginDAO(corsOriginDAO);
}
use of org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager in project product-is by wso2.
the class AccountLockWhileCaseInsensitiveUserFalseTestCase method configureServerWithRestart.
private void configureServerWithRestart(String carbonHome) throws AutomationUtilException, XPathExpressionException, IOException {
File defaultTomlFile = getDeploymentTomlFile(carbonHome);
File configuredTomlFile = new File(getISResourceLocation() + File.separator + "identityMgt" + File.separator + "case_insensitive_user_false.toml");
log.info("Applying configured toml file.");
configurationManager = new ServerConfigurationManager(isServer);
configurationManager.applyConfigurationWithoutRestart(configuredTomlFile, defaultTomlFile, true);
configurationManager.restartGracefully();
log.info("Toml configurations applied.");
}
use of org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager in project carbon-apimgt by wso2.
the class TenantServiceCreator method createdConfigurationContext.
public void createdConfigurationContext(ConfigurationContext configurationContext) {
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
log.info("Initializing APIM TenantServiceCreator for the tenant domain : " + tenantDomain);
try {
// first check which configuration should be active
org.wso2.carbon.registry.core.Registry registry = (org.wso2.carbon.registry.core.Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION);
AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();
// initialize the lock
Lock lock = new ReentrantLock();
axisConfig.addParameter("synapse.config.lock", lock);
// creates the synapse configuration directory hierarchy if not exists
// useful at the initial tenant creation
File tenantAxis2Repo = new File(configurationContext.getAxisConfiguration().getRepository().getFile());
File synapseConfigsDir = new File(tenantAxis2Repo, "synapse-configs");
if (!synapseConfigsDir.exists()) {
if (!synapseConfigsDir.mkdir()) {
log.fatal("Couldn't create the synapse-config root on the file system " + "for the tenant domain : " + tenantDomain);
return;
}
}
String synapseConfigsDirLocation = synapseConfigsDir.getAbsolutePath();
// set the required configuration parameters to initialize the ESB
axisConfig.addParameter(SynapseConstants.Axis2Param.SYNAPSE_CONFIG_LOCATION, synapseConfigsDirLocation);
// init the multiple configuration tracker
ConfigurationManager manger = new ConfigurationManager((UserRegistry) registry, configurationContext);
manger.init();
File synapseConfigDir = new File(synapseConfigsDir, manger.getTracker().getCurrentConfigurationName());
StringBuilder filepath = new StringBuilder();
filepath.append(synapseConfigsDir).append('/').append(manger.getTracker().getCurrentConfigurationName()).append('/').append(MultiXMLConfigurationBuilder.SEQUENCES_DIR).append('/').append(authFailureHandlerSequenceName).append(".xml");
File authFailureHandlerSequenceNameFile = new File(filepath.toString());
// sequence synapse configurations by using resource artifacts
if (!authFailureHandlerSequenceNameFile.exists()) {
createTenantSynapseConfigHierarchy(synapseConfigDir, tenantDomain);
}
String graphqlFilepath = String.valueOf(synapseConfigsDir) + '/' + manger.getTracker().getCurrentConfigurationName() + '/' + MultiXMLConfigurationBuilder.SEQUENCES_DIR + '/' + graphqlAuthFailureHandlerSequenceName + ".xml";
File graphqlFailureHandlerSequenceNameFile = new File(graphqlFilepath);
if (!graphqlFailureHandlerSequenceNameFile.exists()) {
createTenantSynapseConfigHierarchy(synapseConfigDir, tenantDomain);
}
String threatFaultConfigLocation = synapseConfigsDir.getAbsolutePath() + File.separator + manger.getTracker().getCurrentConfigurationName() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + threatFaultSequenceName + ".xml";
File threatFaultXml = new File(threatFaultConfigLocation);
if (!threatFaultXml.exists()) {
FileUtils.copyFile(new File(synapseConfigRootPath + threatFaultSequenceName + ".xml"), new File(synapseConfigDir.getAbsolutePath() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + threatFaultSequenceName + ".xml"));
}
String blockingSequenceLocation = synapseConfigsDir.getAbsolutePath() + File.separator + manger.getTracker().getCurrentConfigurationName() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + blockingSequence + ".xml";
File blockingSequenceXml = new File(blockingSequenceLocation);
if (!blockingSequenceXml.exists()) {
FileUtils.copyFile(new File(synapseConfigRootPath + blockingSequence + ".xml"), new File(synapseConfigDir.getAbsolutePath() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + blockingSequence + ".xml"));
}
String backEndFailureSequence = synapseConfigsDir.getAbsolutePath() + File.separator + manger.getTracker().getCurrentConfigurationName() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + backendFailureSequenceName + ".xml";
File backendSequenceXml = new File(backEndFailureSequence);
if (!backendSequenceXml.exists()) {
FileUtils.copyFile(new File(synapseConfigRootPath + backendFailureSequenceName + ".xml"), new File(synapseConfigDir.getAbsolutePath() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + backendFailureSequenceName + ".xml"));
}
String opaPolicyFailureSequence = synapseConfigsDir.getAbsolutePath() + File.separator + manger.getTracker().getCurrentConfigurationName() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + opaPolicyFailureHandlerSequenceName + ".xml";
File opaPolicyFailureSequenceXml = new File(opaPolicyFailureSequence);
if (!opaPolicyFailureSequenceXml.exists()) {
FileUtils.copyFile(new File(synapseConfigRootPath + opaPolicyFailureHandlerSequenceName + ".xml"), new File(synapseConfigDir.getAbsolutePath() + File.separator + MultiXMLConfigurationBuilder.SEQUENCES_DIR + File.separator + opaPolicyFailureHandlerSequenceName + ".xml"));
}
} catch (RemoteException e) {
log.error("Failed to create Tenant's synapse sequences.", e);
} catch (Exception e) {
log.error("Failed to create Tenant's synapse sequences.", e);
}
// Create caches for tenants
CacheProvider.removeAllCaches();
CacheProvider.createGatewayKeyCache();
CacheProvider.createResourceCache();
CacheProvider.createGatewayTokenCache();
CacheProvider.createInvalidTokenCache();
CacheProvider.createGatewayBasicAuthResourceCache();
CacheProvider.createGatewayUsernameCache();
CacheProvider.createInvalidUsernameCache();
// Initialize product REST API token caches
CacheProvider.createRESTAPITokenCache();
CacheProvider.createRESTAPIInvalidTokenCache();
CacheProvider.createGatewayJWTTokenCache();
CacheProvider.createTenantConfigCache();
CacheProvider.createRecommendationsCache();
CacheProvider.createParsedSignJWTCache();
CacheProvider.createInvalidGatewayApiKeyCache();
CacheProvider.createGatewayInternalKeyCache();
CacheProvider.createGatewayInternalKeyDataCache();
CacheProvider.createInvalidInternalKeyCache();
}
use of org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager in project carbon-mediation by wso2.
the class ServiceBusInitializer method activate.
@Activate
protected void activate(ComponentContext ctxt) {
log.debug("Activating Micro Integrator...");
PrivilegedCarbonContext privilegedCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext();
privilegedCarbonContext.setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
privilegedCarbonContext.setTenantId(MultitenantConstants.SUPER_TENANT_ID);
if (taskService != null && !taskService.isServerInit()) {
log.debug("Initialize Task Service");
taskService.serverInitialized();
}
// FIXME: this is a hack to get rid of the https port retrieval from the axis2
// configuration returning the non blocking https transport. Ideally we should be able
// to fix this by making it possible to let the authentication of carbon be done through
// the non blocking https transport
setHttpsProtForConsole();
// clean up temp folder created for connector class loader reference
String javaTempDir = System.getProperty("java.io.tmpdir");
String APP_UNZIP_DIR = javaTempDir.endsWith(File.separator) ? javaTempDir + "libs" : javaTempDir + File.separator + "libs";
cleanupTempDirectory(APP_UNZIP_DIR);
try {
BundleContext bndCtx = ctxt.getBundleContext();
ConfigurationHolder.getInstance().setBundleContext(bndCtx);
// initialize the lock
Lock lock = new ReentrantLock();
configCtxSvc.getServerConfigContext().getAxisConfiguration().addParameter(ServiceBusConstants.SYNAPSE_CONFIG_LOCK, lock);
// first check which configuration should be active
// UserRegistry registry = registryService.getConfigSystemRegistry();
// init the multiple configuration tracker
ConfigurationManager configurationManager = new ConfigurationManager(configCtxSvc.getServerConfigContext());
configurationManager.init();
// set the event broker as a property
/*
if (eventBroker != null) {
configCtxSvc.getServerConfigContext().setProperty("mediation.event.broker", eventBroker);
}
*/
// Initialize Synapse
ServerContextInformation contextInfo = initESB("default");
ServiceRegistration synCfgRegistration = null;
ServiceRegistration synEnvRegistration = null;
if (contextInfo.getSynapseConfiguration() != null) {
// Properties props = new Properties();
SynapseConfigurationService synCfgSvc = new SynapseConfigurationServiceImpl(contextInfo.getSynapseConfiguration(), MultitenantConstants.SUPER_TENANT_ID, configCtxSvc.getServerConfigContext());
synCfgRegistration = bndCtx.registerService(SynapseConfigurationService.class.getName(), synCfgSvc, null);
bndCtx.registerService(ServerShutdownHandler.class.getName(), new MPMShutdownHandler(synCfgSvc.getSynapseConfiguration().getAxisConfiguration()), null);
initPersistence(synCfgSvc, "default");
if (log.isDebugEnabled()) {
log.debug("SynapseConfigurationService Registered");
}
} else {
handleFatal("Couldn't register the SynapseConfigurationService, " + "SynapseConfiguration not found");
}
SynapseEnvironment synapseEnvironment = contextInfo.getSynapseEnvironment();
if (synapseEnvironment != null) {
// Properties props = new Properties();
SynapseEnvironmentService synEnvSvc = new SynapseEnvironmentServiceImpl(synapseEnvironment, MultitenantConstants.SUPER_TENANT_ID, configCtxSvc.getServerConfigContext());
synEnvRegistration = bndCtx.registerService(SynapseEnvironmentService.class.getName(), synEnvSvc, null);
synapseEnvironment.registerSynapseHandler(new SynapseExternalPropertyConfigurator());
synapseEnvironment.registerSynapseHandler(new ProxyLogHandler());
if (log.isDebugEnabled()) {
log.debug("SynapseEnvironmentService Registered");
}
} else {
handleFatal("Couldn't register the SynapseEnvironmentService, " + "SynapseEnvironment not found");
}
// Properties props = new Properties();
SynapseRegistrationsService synRegistrationsSvc = new SynapseRegistrationsServiceImpl(synCfgRegistration, synEnvRegistration, MultitenantConstants.SUPER_TENANT_ID, configCtxSvc.getServerConfigContext());
bndCtx.registerService(SynapseRegistrationsService.class.getName(), synRegistrationsSvc, null);
configCtxSvc.getServerConfigContext().setProperty(ConfigurationManager.CONFIGURATION_MANAGER, configurationManager);
// Start Inbound Endpoint Listeners
// tOdO need to fix inbound endpoints
EndpointListenerLoader.loadListeners();
registerInboundDeployer(configCtxSvc.getServerConfigContext().getAxisConfiguration(), contextInfo.getSynapseEnvironment());
} catch (Exception e) {
handleFatal("Couldn't initialize the ESB...", e);
} catch (Throwable t) {
log.fatal("Failed to initialize ESB due to a fatal error", t);
}
}
use of org.wso2.carbon.identity.configuration.mgt.core.ConfigurationManager in project carbon-mediation by wso2.
the class TenantServiceBusInitializer method createdConfigurationContext.
// private Map<Integer, ServiceRegistration> tenantRegistrations =
// new HashMap<Integer, ServiceRegistration>();
public void createdConfigurationContext(ConfigurationContext configurationContext) {
ServerContextInformation contextInfo;
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
log.info("Initializing the ESB Configuration for the tenant domain : " + tenantDomain);
try {
// first check which configuration should be active
org.wso2.carbon.registry.core.Registry registry = (org.wso2.carbon.registry.core.Registry) PrivilegedCarbonContext.getThreadLocalCarbonContext().getRegistry(RegistryType.SYSTEM_CONFIGURATION);
AxisConfiguration axisConfig = configurationContext.getAxisConfiguration();
// initialize the lock
Lock lock = new ReentrantLock();
axisConfig.addParameter(ServiceBusConstants.SYNAPSE_CONFIG_LOCK, lock);
// creates the synapse configuration directory hierarchy if not exists
// useful at the initial tenant creation
File tenantAxis2Repo = new File(configurationContext.getAxisConfiguration().getRepository().getFile());
File synapseConfigsDir = new File(tenantAxis2Repo, ServiceBusConstants.SYNAPSE_CONFIGS);
if (!synapseConfigsDir.exists()) {
if (!synapseConfigsDir.mkdir()) {
log.fatal("Couldn't create the synapse-config root on the file system " + "for the tenant domain : " + tenantDomain);
return;
}
}
String synapseConfigsDirLocation = synapseConfigsDir.getAbsolutePath();
// set the required configuration parameters to initialize the ESB
axisConfig.addParameter(SynapseConstants.Axis2Param.SYNAPSE_CONFIG_LOCATION, synapseConfigsDirLocation);
// init the multiple configuration tracker
ConfigurationManager manger = new ConfigurationManager((UserRegistry) registry, configurationContext);
manger.init();
File synapseConfigDir = new File(synapseConfigsDir, manger.getTracker().getCurrentConfigurationName());
createTenantSynapseConfigHierarchy(synapseConfigDir, tenantDomain);
axisConfig.addParameter(SynapseConstants.Axis2Param.SYNAPSE_HOME, tenantAxis2Repo.getAbsolutePath());
axisConfig.addParameter(SynapseConstants.Axis2Param.SYNAPSE_SERVER_NAME, "synapse." + tenantDomain);
axisConfig.addParameter(SynapseConstants.Axis2Param.SYNAPSE_RESOLVE_ROOT, tenantAxis2Repo.getAbsolutePath());
// Initialize Synapse
contextInfo = initESB(manger.getTracker().getCurrentConfigurationName(), configurationContext, tenantDomain);
if (contextInfo == null) {
handleFatal("Failed to initialize the ESB for tenant:" + tenantDomain);
}
initPersistence(manger.getTracker().getCurrentConfigurationName(), configurationContext, contextInfo);
configurationContext.setProperty(ConfigurationManager.CONFIGURATION_MANAGER, manger);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
// populate the SynapseEnv service and SynapseConfig OSGI Services so that other
// components get to know about the availability of the new synapse configuration
// Properties props = new Properties();
SynapseConfigurationService synCfgSvc = new SynapseConfigurationServiceImpl(contextInfo.getSynapseConfiguration(), tenantId, configurationContext);
ServiceRegistration confRegistration = ConfigurationHolder.getInstance().getBundleContext().registerService(SynapseConfigurationService.class.getName(), synCfgSvc, null);
// Older SynapseConfiguration references created for a particular tenant are not getting cleaned.
// Hence, there can be an OOM issue when there are multiple accumulated SynapseConfiguration instances.
// To overcome the OOM issue, here, the localRegistry map in the older instance, which can bear the biggest
// object in the SynapseConfiguration instance is cleaned upon a new SynapseConfiguration is created.
SynapseConfiguration olderSynapseConfiguration = ConfigurationHolder.getInstance().getSynapseConfiguration(tenantId);
if (!Objects.isNull(olderSynapseConfiguration)) {
olderSynapseConfiguration.getLocalRegistry().clear();
}
SynapseEnvironment synapseEnvironment = contextInfo.getSynapseEnvironment();
ConfigurationHolder.getInstance().addSynapseConfiguration(tenantId, synapseEnvironment.getSynapseConfiguration());
// props = new Properties();
SynapseEnvironmentService synEnvSvc = new SynapseEnvironmentServiceImpl(synapseEnvironment, tenantId, configurationContext);
ServiceRegistration envRegistration = ConfigurationHolder.getInstance().getBundleContext().registerService(SynapseEnvironmentService.class.getName(), synEnvSvc, null);
synapseEnvironment.registerSynapseHandler(new SynapseExternalPropertyConfigurator());
// props = new Properties();
SynapseRegistrationsService synRegistrationsSvc = new SynapseRegistrationsServiceImpl(confRegistration, envRegistration, tenantId, configurationContext);
ServiceRegistration synapseRegistration = ConfigurationHolder.getInstance().getBundleContext().registerService(SynapseRegistrationsService.class.getName(), synRegistrationsSvc, null);
// creating secure-vault specific location
if (!isRepoExists(registry)) {
org.wso2.carbon.registry.core.Collection secureVaultCollection = registry.newCollection();
registry.put(ServiceBusConstants.CONNECTOR_SECURE_VAULT_CONFIG_REPOSITORY, secureVaultCollection);
}
ConfigurationTrackingService trackingService = ServiceBusInitializer.getConfigurationTrackingService();
if (trackingService != null) {
trackingService.setSynapseConfiguration(contextInfo.getSynapseConfiguration());
}
// set the event broker as a property for tenants
EventBroker eventBroker = ServiceBusInitializer.getEventBroker();
if (eventBroker != null) {
configurationContext.setProperty("mediation.event.broker", eventBroker);
}
ConfigurationHolder.getInstance().addSynapseRegistration(tenantId, synapseRegistration);
registerInboundDeployer(axisConfig, contextInfo.getSynapseEnvironment());
} catch (Exception e) {
handleFatal("Couldn't initialize the ESB for tenant:" + tenantDomain, e);
} catch (Throwable t) {
log.fatal("Failed to initialize ESB for tenant:" + tenantDomain + "due to a fatal error", t);
}
}
Aggregations