Search in sources :

Example 6 with InitConfig

use of org.wso2.carbon.identity.core.handler.InitConfig in project product-iots by wso2.

the class QSGUtils method initConfig.

public static EMMQSGConfig initConfig() {
    Properties props = new Properties();
    InputStream input = null;
    EMMQSGConfig emmConfig = null;
    try {
        input = new FileInputStream("config.properties");
        // load a properties file and set the properties
        props.load(input);
        emmConfig = EMMQSGConfig.getInstance();
        emmConfig.setEmmHost(props.getProperty("emm-host"));
        emmConfig.setDcrEndPoint(props.getProperty("dcr-endpoint"));
        emmConfig.setOauthEndPoint(props.getProperty("oauth-endpoint"));
        emmConfig.setUsername(props.getProperty("username"));
        emmConfig.setPassword(props.getProperty("password"));
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        if (input != null) {
            try {
                input.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return emmConfig;
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) EMMQSGConfig(org.wso2.mdm.qsg.dto.EMMQSGConfig) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Example 7 with InitConfig

use of org.wso2.carbon.identity.core.handler.InitConfig in project carbon-identity-framework by wso2.

the class AbstractIdentityHandler method init.

@Override
public void init(InitConfig initConfig) {
    this.initConfig = initConfig;
    IdentityEventListenerConfig identityEventListenerConfig = IdentityUtil.readEventListenerProperty(AbstractIdentityHandler.class.getName(), this.getClass().getName());
    if (identityEventListenerConfig == null) {
        return;
    }
    if (identityEventListenerConfig.getProperties() != null) {
        for (Map.Entry<Object, Object> property : identityEventListenerConfig.getProperties().entrySet()) {
            String key = (String) property.getKey();
            String value = (String) property.getValue();
            if (!properties.containsKey(key)) {
                properties.setProperty(key, value);
            } else {
                log.warn("Property key " + key + " already exists. Cannot add property!!");
            }
        }
    }
}
Also used : IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Map(java.util.Map)

Example 8 with InitConfig

use of org.wso2.carbon.identity.core.handler.InitConfig in project carbon-identity-framework by wso2.

the class AbstractIdentityMessageHandler method init.

public void init(InitConfig initConfig) {
    this.initConfig = initConfig;
    IdentityEventListenerConfig identityEventListenerConfig = IdentityUtil.readEventListenerProperty(AbstractIdentityMessageHandler.class.getName(), this.getClass().getName());
    if (identityEventListenerConfig == null) {
        return;
    }
    if (identityEventListenerConfig.getProperties() != null) {
        for (Map.Entry<Object, Object> property : identityEventListenerConfig.getProperties().entrySet()) {
            String key = (String) property.getKey();
            String value = (String) property.getValue();
            if (!properties.containsKey(key)) {
                properties.setProperty(key, value);
            } else {
                log.warn("Property key " + key + " already exists. Cannot add property!!");
            }
        }
    }
}
Also used : IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Map(java.util.Map)

Example 9 with InitConfig

use of org.wso2.carbon.identity.core.handler.InitConfig in project carbon-identity-framework by wso2.

the class HttpIdentityRequestFactoryTest method testInitWithDuplicateEventListenerProperties.

@Test(dataProvider = "initConfigDataProvider")
public void testInitWithDuplicateEventListenerProperties(Properties eventListenerProperties, Properties expectedListenerProperties) throws Exception {
    Util.mockReturnEventListenerConfigWithProperties(eventListenerProperties);
    httpIdentityRequestFactory.init(new InitConfig());
    Util.assertPropertiesEqual(httpIdentityRequestFactory.properties, expectedListenerProperties);
}
Also used : InitConfig(org.wso2.carbon.identity.core.handler.InitConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 10 with InitConfig

use of org.wso2.carbon.identity.core.handler.InitConfig in project carbon-identity-framework by wso2.

the class HttpIdentityRequestFactoryTest method testInit.

@Test
public void testInit() throws Exception {
    // Mock returning a null after reading event listener configs
    Util.mockReturnNullEventListenerConfig();
    InitConfig initConfig = new InitConfig();
    httpIdentityRequestFactory.init(initConfig);
    assertEquals(httpIdentityRequestFactory.properties.size(), 0);
}
Also used : InitConfig(org.wso2.carbon.identity.core.handler.InitConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Test (org.testng.annotations.Test)6 InitConfig (org.wso2.carbon.identity.core.handler.InitConfig)6 Map (java.util.Map)5 IdentityEventListenerConfig (org.wso2.carbon.identity.core.model.IdentityEventListenerConfig)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 HashMap (java.util.HashMap)2 IdentityBaseTest (org.wso2.carbon.identity.testutil.IdentityBaseTest)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 Properties (java.util.Properties)1 ModuleConfiguration (org.wso2.carbon.identity.event.bean.ModuleConfiguration)1 EMMQSGConfig (org.wso2.mdm.qsg.dto.EMMQSGConfig)1