Search in sources :

Example 1 with ConfigProvider

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);
        }
    }
}
Also used : Path(java.nio.file.Path) User(org.wso2.broker.core.security.authentication.user.User) BrokerConfigProvider(org.wso2.broker.common.BrokerConfigProvider) ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider) UsersFile(org.wso2.broker.core.security.authentication.user.UsersFile)

Example 2 with ConfigProvider

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);
}
Also used : Path(java.nio.file.Path) BrokerConfigProvider(org.wso2.broker.common.BrokerConfigProvider) ConfigProvider(org.wso2.carbon.config.provider.ConfigProvider)

Example 3 with ConfigProvider

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);
    }
}
Also used : Context(javax.naming.Context) BundleContext(org.osgi.framework.BundleContext) BrokerImpl(org.wso2.carbon.apimgt.core.impl.BrokerImpl) Broker(org.wso2.carbon.apimgt.core.api.Broker) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) FileEncryptionUtility(org.wso2.carbon.apimgt.core.impl.FileEncryptionUtility) DataSourceImpl(org.wso2.carbon.apimgt.core.dao.impl.DataSourceImpl) NamingException(javax.naming.NamingException) DataSource(org.wso2.carbon.apimgt.core.dao.impl.DataSource) HikariDataSource(com.zaxxer.hikari.HikariDataSource) Activate(org.osgi.service.component.annotations.Activate)

Example 4 with ConfigProvider

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;
}
Also used : ConfigurationException(org.wso2.carbon.config.ConfigurationException) APIMConfigurations(org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations)

Example 5 with ConfigProvider

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;
}
Also used : EnvironmentConfigurations(org.wso2.carbon.apimgt.core.configuration.models.EnvironmentConfigurations) ConfigurationException(org.wso2.carbon.config.ConfigurationException)

Aggregations

ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)17 ConfigurationException (org.wso2.carbon.config.ConfigurationException)9 Test (org.testng.annotations.Test)8 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 ContainerBasedGatewayConfiguration (org.wso2.carbon.apimgt.core.configuration.models.ContainerBasedGatewayConfiguration)3 WorkflowConfig (org.wso2.carbon.apimgt.core.models.WorkflowConfig)3 Feature (org.wso2.carbon.apimgt.rest.api.configurations.models.Feature)3 Path (java.nio.file.Path)2 Map (java.util.Map)2 BeforeTest (org.testng.annotations.BeforeTest)2 BrokerConfigProvider (org.wso2.broker.common.BrokerConfigProvider)2 APIMConfigurations (org.wso2.carbon.apimgt.core.configuration.models.APIMConfigurations)2 APIMAppConfigurations (org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations)2 APIMUIConfigurations (org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations)2 HikariDataSource (com.zaxxer.hikari.HikariDataSource)1 File (java.io.File)1 Context (javax.naming.Context)1 NamingException (javax.naming.NamingException)1 BundleContext (org.osgi.framework.BundleContext)1