Search in sources :

Example 1 with ConfigurationException

use of org.wso2.carbon.config.ConfigurationException 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 ConfigurationException

use of org.wso2.carbon.config.ConfigurationException 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 ConfigurationException

use of org.wso2.carbon.config.ConfigurationException 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 4 with ConfigurationException

use of org.wso2.carbon.config.ConfigurationException 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)

Example 5 with ConfigurationException

use of org.wso2.carbon.config.ConfigurationException in project carbon-apimgt by wso2.

the class ServiceReferenceHolder method getAPIMAppConfiguration.

public APIMAppConfigurations getAPIMAppConfiguration() {
    try {
        if (configProvider != null) {
            config = configProvider.getConfigurationObject(APIMAppConfigurations.class);
        } else {
            log.error("Configuration provider is null");
        }
    } catch (ConfigurationException e) {
        log.error("Error getting config : org.wso2.carbon.apimgt.rest.api.authenticator.internal.APIMAppConfiguration", e);
    }
    if (config == null) {
        config = new APIMAppConfigurations();
        log.info("Setting default configurations...");
    }
    return config;
}
Also used : ConfigurationException(org.wso2.carbon.config.ConfigurationException) APIMAppConfigurations(org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations)

Aggregations

ConfigProvider (org.wso2.carbon.config.provider.ConfigProvider)12 ConfigurationException (org.wso2.carbon.config.ConfigurationException)9 Test (org.junit.Test)5 HashMap (java.util.HashMap)3 Test (org.testng.annotations.Test)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 ContainerBasedGatewayConfiguration (org.wso2.carbon.apimgt.core.configuration.models.ContainerBasedGatewayConfiguration)2 APIMAppConfigurations (org.wso2.carbon.apimgt.rest.api.authenticator.configuration.models.APIMAppConfigurations)2 APIMUIConfigurations (org.wso2.carbon.apimgt.rest.api.configurations.models.APIMUIConfigurations)2 File (java.io.File)1 Iterator (java.util.Iterator)1 List (java.util.List)1 QName (javax.xml.namespace.QName)1 OXPath20ExpressionBPEL20 (org.apache.ode.bpel.elang.xpath20.o.OXPath20ExpressionBPEL20)1 ConfigurationException (org.apache.ode.bpel.explang.ConfigurationException)1