Search in sources :

Example 1 with IdentityEventListenerConfigKey

use of org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey in project carbon-identity-framework by wso2.

the class IdentityUtilTest method testPopulateProperties.

@Test
public void testPopulateProperties() throws Exception {
    Map<String, Object> mockConfig = new HashMap<>();
    mockConfig.put("dummy", new Object());
    Map<IdentityEventListenerConfigKey, IdentityEventListenerConfig> mockedEventListenerConfig = new HashMap<>();
    IdentityEventListenerConfigKey configKey = new IdentityEventListenerConfigKey("type", "name");
    mockedEventListenerConfig.put(configKey, new IdentityEventListenerConfig("false", 0, configKey, null));
    Map<IdentityCacheConfigKey, IdentityCacheConfig> mockedCacheConfig = new HashMap<>();
    IdentityCacheConfigKey cacheConfigKey = new IdentityCacheConfigKey("manager", "key");
    mockedCacheConfig.put(cacheConfigKey, new IdentityCacheConfig(cacheConfigKey));
    Map<String, IdentityCookieConfig> mockedCookieConfig = new HashMap<>();
    mockedCookieConfig.put("cookie", new IdentityCookieConfig("cookieName"));
    when(mockConfigParser.getConfiguration()).thenReturn(mockConfig);
    when(IdentityConfigParser.getEventListenerConfiguration()).thenReturn(mockedEventListenerConfig);
    when(IdentityConfigParser.getIdentityCacheConfigurationHolder()).thenReturn(mockedCacheConfig);
    when(IdentityConfigParser.getIdentityCookieConfigurationHolder()).thenReturn(mockedCookieConfig);
    when(IdentityConfigParser.getInstance()).thenReturn(mockConfigParser);
    IdentityUtil.populateProperties();
    assertEquals(Whitebox.getField(IdentityUtil.class, "configuration").get(IdentityUtil.class), mockConfig, "Configuration is not set properly during config population");
    assertEquals(Whitebox.getField(IdentityUtil.class, "eventListenerConfiguration").get(IdentityUtil.class), mockedEventListenerConfig, "eventListenerConfiguration is not set properly during config population");
    assertEquals(IdentityUtil.getIdentityCookiesConfigurationHolder(), mockedCookieConfig, "cookieConfiguration is not set properly during config population");
    assertEquals(Whitebox.getField(IdentityUtil.class, "identityCacheConfigurationHolder").get(IdentityUtil.class), mockedCacheConfig, "identityCacheConfigurationHolder is not set properly during config population");
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityEventListenerConfigKey(org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey) Matchers.anyString(org.mockito.Matchers.anyString) IdentityCacheConfig(org.wso2.carbon.identity.core.model.IdentityCacheConfig) IdentityCacheConfigKey(org.wso2.carbon.identity.core.model.IdentityCacheConfigKey) IdentityCookieConfig(org.wso2.carbon.identity.core.model.IdentityCookieConfig) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with IdentityEventListenerConfigKey

use of org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey in project carbon-identity-framework by wso2.

the class IdentityUtil method readEventListenerProperty.

public static IdentityEventListenerConfig readEventListenerProperty(String type, String name) {
    IdentityEventListenerConfigKey identityEventListenerConfigKey = new IdentityEventListenerConfigKey(type, name);
    IdentityEventListenerConfig identityEventListenerConfig = eventListenerConfiguration.get(identityEventListenerConfigKey);
    return identityEventListenerConfig;
}
Also used : IdentityEventListenerConfigKey(org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig)

Example 3 with IdentityEventListenerConfigKey

use of org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey in project carbon-identity-framework by wso2.

the class IdentityUtilTest method testReadEventListenerProperty.

@Test
public void testReadEventListenerProperty() throws Exception {
    IdentityEventListenerConfigKey key = new IdentityEventListenerConfigKey("ListenerType", "ListenerName");
    IdentityEventListenerConfig config = new IdentityEventListenerConfig("true", 0, key, new Properties());
    Map<IdentityEventListenerConfigKey, IdentityEventListenerConfig> mockedMap = new HashMap<>();
    mockedMap.put(key, config);
    Whitebox.setInternalState(IdentityUtil.class, "eventListenerConfiguration", mockedMap);
    IdentityEventListenerConfig configResponse = IdentityUtil.readEventListenerProperty("ListenerType", "ListenerName");
    assertEquals(configResponse.getEnable(), "true", "Listener should be enabled");
    assertEquals(configResponse.getOrder(), 0, "Listener should have order : 0");
    IdentityEventListenerConfig nullResponse = IdentityUtil.readEventListenerProperty("NonExistingType", "NonExistingListenerName");
    assertNull(nullResponse, "Response should be null for invalid listener.");
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) IdentityEventListenerConfigKey(org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Properties(java.util.Properties) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with IdentityEventListenerConfigKey

use of org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey in project carbon-identity-framework by wso2.

the class IdentityConfigParser method buildEventListenerData.

private void buildEventListenerData() {
    OMElement eventListeners = this.getConfigElement(IdentityConstants.EVENT_LISTENERS);
    if (eventListeners != null) {
        Iterator<OMElement> eventListener = eventListeners.getChildrenWithName(new QName(IdentityCoreConstants.IDENTITY_DEFAULT_NAMESPACE, IdentityConstants.EVENT_LISTENER));
        if (eventListener != null) {
            while (eventListener.hasNext()) {
                OMElement eventListenerElement = eventListener.next();
                String eventListenerType = eventListenerElement.getAttributeValue(new QName(IdentityConstants.EVENT_LISTENER_TYPE));
                String eventListenerName = eventListenerElement.getAttributeValue(new QName(IdentityConstants.EVENT_LISTENER_NAME));
                int order = Integer.parseInt(eventListenerElement.getAttributeValue(new QName(IdentityConstants.EVENT_LISTENER_ORDER)));
                String enable = eventListenerElement.getAttributeValue(new QName(IdentityConstants.EVENT_LISTENER_ENABLE));
                Iterator<OMElement> propertyElements = eventListenerElement.getChildrenWithName(new QName(IdentityConstants.EVENT_LISTENER_PROPERTY));
                Properties properties = new Properties();
                while (propertyElements.hasNext()) {
                    OMElement propertyElem = propertyElements.next();
                    String propertyName = propertyElem.getAttributeValue(new QName(IdentityConstants.EVENT_LISTENER_PROPERTY_NAME));
                    String propertyValue = propertyElem.getText();
                    properties.setProperty(propertyName, propertyValue);
                }
                if (StringUtils.isBlank(eventListenerType) || StringUtils.isBlank(eventListenerName)) {
                    throw IdentityRuntimeException.error("eventListenerType or eventListenerName is not defined " + "correctly");
                }
                IdentityEventListenerConfigKey configKey = new IdentityEventListenerConfigKey(eventListenerType, eventListenerName);
                IdentityEventListenerConfig identityEventListenerConfig = new IdentityEventListenerConfig(enable, order, configKey, properties);
                eventListenerConfiguration.put(configKey, identityEventListenerConfig);
            }
        }
    }
}
Also used : QName(javax.xml.namespace.QName) IdentityEventListenerConfigKey(org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) OMElement(org.apache.axiom.om.OMElement) Properties(java.util.Properties)

Example 5 with IdentityEventListenerConfigKey

use of org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey in project identity-inbound-auth-oauth by wso2-extensions.

the class AbstractOAuthEventInterceptorTest method testIsEnabled.

@Test
public void testIsEnabled() throws Exception {
    mockStatic(IdentityUtil.class);
    IdentityEventListenerConfig identityEventListenerConfig = new IdentityEventListenerConfig("true", 1, new IdentityEventListenerConfigKey(), new Properties());
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(identityEventListenerConfig);
    assertTrue(testclass.isEnabled());
    when(IdentityUtil.readEventListenerProperty(anyString(), anyString())).thenReturn(null);
    assertFalse(testclass.isEnabled());
}
Also used : IdentityEventListenerConfigKey(org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey) IdentityEventListenerConfig(org.wso2.carbon.identity.core.model.IdentityEventListenerConfig) Properties(java.util.Properties) PowerMockIdentityBaseTest(org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.testng.annotations.Test)

Aggregations

IdentityEventListenerConfig (org.wso2.carbon.identity.core.model.IdentityEventListenerConfig)5 IdentityEventListenerConfigKey (org.wso2.carbon.identity.core.model.IdentityEventListenerConfigKey)5 Properties (java.util.Properties)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Test (org.testng.annotations.Test)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 QName (javax.xml.namespace.QName)1 OMElement (org.apache.axiom.om.OMElement)1 Matchers.anyString (org.mockito.Matchers.anyString)1 IdentityCacheConfig (org.wso2.carbon.identity.core.model.IdentityCacheConfig)1 IdentityCacheConfigKey (org.wso2.carbon.identity.core.model.IdentityCacheConfigKey)1 IdentityCookieConfig (org.wso2.carbon.identity.core.model.IdentityCookieConfig)1 PowerMockIdentityBaseTest (org.wso2.carbon.identity.testutil.powermock.PowerMockIdentityBaseTest)1