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");
}
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;
}
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.");
}
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);
}
}
}
}
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());
}
Aggregations