use of org.wso2.carbon.config.provider.ConfigProvider in project carbon-apimgt by wso2.
the class BrokerManager method loadUsers.
/**
* Loads the users from users.yaml during broker startup
*/
private static void loadUsers() throws ConfigurationException {
Path usersYamlFile;
String usersFilePath = System.getProperty(BrokerSecurityConstants.SYSTEM_PARAM_USERS_CONFIG);
if (usersFilePath == null || usersFilePath.trim().isEmpty()) {
// use current path.
usersYamlFile = Paths.get("", BrokerSecurityConstants.USERS_FILE_NAME).toAbsolutePath();
} else {
usersYamlFile = Paths.get(usersFilePath).toAbsolutePath();
}
ConfigProvider configProvider = ConfigProviderFactory.getConfigProvider(usersYamlFile, null);
UsersFile usersFile = configProvider.getConfigurationObject(BrokerSecurityConstants.USERS_CONFIG_NAMESPACE, UsersFile.class);
if (usersFile != null) {
List<User> users = usersFile.getUsers();
for (User user : users) {
UserStoreManager.addUser(user);
}
}
}
use of org.wso2.carbon.config.provider.ConfigProvider in project carbon-apimgt by wso2.
the class BrokerManager method initConfigProvider.
/**
* Loads configurations during the broker start up.
* method will try to <br/>
* (1) Load the configuration file specified in 'broker.file' (e.g. -Dbroker.file=<FilePath>). <br/>
* (2) If -Dbroker.file is not specified, the broker.yaml file exists in current directory and load it. <br/>
* <p>
* <b>Note: </b> if provided configuration file cannot be read broker will not start.
*
* @param startupContext startup context of the broker
*/
private static void initConfigProvider(StartupContext startupContext) throws ConfigurationException {
Path brokerYamlFile;
String brokerFilePath = System.getProperty(BrokerConfiguration.SYSTEM_PARAM_BROKER_CONFIG_FILE);
if (brokerFilePath == null || brokerFilePath.trim().isEmpty()) {
// use current path.
brokerYamlFile = Paths.get("", BrokerConfiguration.BROKER_FILE_NAME).toAbsolutePath();
} else {
brokerYamlFile = Paths.get(brokerFilePath).toAbsolutePath();
}
ConfigProvider configProvider = ConfigProviderFactory.getConfigProvider(brokerYamlFile, null);
startupContext.registerService(BrokerConfigProvider.class, (BrokerConfigProvider) configProvider::getConfigurationObject);
}
use of org.wso2.carbon.config.provider.ConfigProvider in project carbon-apimgt by wso2.
the class BundleActivator method start.
@Activate
protected void start(BundleContext bundleContext) {
try {
// Set default timestamp to UTC
java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone("Etc/UTC"));
Context ctx = jndiContextManager.newInitialContext();
DataSource dataSourceAMDB = new DataSourceImpl((HikariDataSource) ctx.lookup("java:comp/env/jdbc/WSO2AMDB"));
DAOUtil.initialize(dataSourceAMDB);
boolean isAnalyticsEnabled = ServiceReferenceHolder.getInstance().getAPIMConfiguration().getAnalyticsConfigurations().isEnabled();
if (isAnalyticsEnabled) {
DataSource dataSourceStatDB = new DataSourceImpl((HikariDataSource) ctx.lookup("java:comp/env/jdbc/WSO2AMSTATSDB"));
DAOUtil.initializeAnalyticsDataSource(dataSourceStatDB);
}
WorkflowExtensionsConfigBuilder.build(configProvider);
ServiceDiscoveryConfigBuilder.build(configProvider);
ContainerBasedGatewayConfigBuilder.build(configProvider);
BrokerManager.start();
Broker broker = new BrokerImpl();
BrokerUtil.initialize(broker);
} catch (NamingException e) {
log.error("Error occurred while jndi lookup", e);
}
// deploying default policies
try {
ThrottlerUtil.addDefaultAdvancedThrottlePolicies();
if (log.isDebugEnabled()) {
log.debug("Checked default throttle policies successfully");
}
} catch (APIManagementException e) {
log.error("Error occurred while deploying default policies", e);
}
// securing files
try {
boolean fileEncryptionEnabled = ServiceReferenceHolder.getInstance().getAPIMConfiguration().getFileEncryptionConfigurations().isEnabled();
if (fileEncryptionEnabled) {
FileEncryptionUtility fileEncryptionUtility = FileEncryptionUtility.getInstance();
fileEncryptionUtility.init();
fileEncryptionUtility.encryptFiles();
}
} catch (APIManagementException e) {
log.error("Error occurred while encrypting files", e);
}
}
use of org.wso2.carbon.config.provider.ConfigProvider in project carbon-apimgt by wso2.
the class ServiceReferenceHolder method getAPIMConfiguration.
/**
* Gives the APIMConfigurations explicitly set in the deployment yaml or the default configurations
*
* @return APIMConfigurations
*/
public APIMConfigurations getAPIMConfiguration() {
try {
if (configProvider != null) {
apimConfigurations = configProvider.getConfigurationObject(APIMConfigurations.class);
} else {
log.error("Configuration provider is null");
}
} catch (ConfigurationException e) {
log.error("error getting config : org.wso2.carbon.apimgt.core.internal.APIMConfiguration", e);
}
if (apimConfigurations == null) {
apimConfigurations = new APIMConfigurations();
log.info("APIMConfiguration: Setting default configurations...");
}
return apimConfigurations;
}
use of org.wso2.carbon.config.provider.ConfigProvider in project carbon-apimgt by wso2.
the class ServiceReferenceHolder method getEnvironmentConfigurations.
/**
* Gives the EnvironmentConfigurations explicitly set in the deployment yaml or the default configurations
*
* @return EnvironmentConfigurations
*/
public EnvironmentConfigurations getEnvironmentConfigurations() {
try {
if (configProvider != null) {
environmentConfigurations = configProvider.getConfigurationObject(EnvironmentConfigurations.class);
} else {
log.error("Configuration provider is null");
}
} catch (ConfigurationException e) {
log.error("error getting config : org.wso2.carbon.apimgt.core.internal.EnvironmentConfigurations", e);
}
if (environmentConfigurations == null) {
environmentConfigurations = new EnvironmentConfigurations();
log.info("EnvironmentConfigurations: Setting default configurations...");
}
return environmentConfigurations;
}
Aggregations