use of org.wso2.carbon.identity.core.model.IdentityCacheConfigKey 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.IdentityCacheConfigKey in project carbon-identity-framework by wso2.
the class IdentityUtilTest method getIdentityCacheConfigTestData.
@DataProvider
public Object[][] getIdentityCacheConfigTestData() {
Map<IdentityCacheConfigKey, IdentityCacheConfig> mockedCacheConfig = new HashMap<>();
IdentityCacheConfigKey cacheConfigKey1 = new IdentityCacheConfigKey("manager1", "key1");
IdentityCacheConfig cacheConfig1 = new IdentityCacheConfig(cacheConfigKey1);
mockedCacheConfig.put(cacheConfigKey1, cacheConfig1);
IdentityCacheConfigKey cacheConfigKey2 = new IdentityCacheConfigKey("manager2", "");
IdentityCacheConfig cacheConfig2 = new IdentityCacheConfig(cacheConfigKey1);
mockedCacheConfig.put(cacheConfigKey2, cacheConfig2);
Whitebox.setInternalState(IdentityUtil.class, "identityCacheConfigurationHolder", mockedCacheConfig);
return new Object[][] { { "manager1", "key1", cacheConfig1 }, { "manager1", "", null }, { "manager2", "", cacheConfig2 }, { "manager1", "$__local__$.key1", cacheConfig1 } };
}
use of org.wso2.carbon.identity.core.model.IdentityCacheConfigKey in project carbon-identity-framework by wso2.
the class IdentityUtil method getIdentityCacheConfig.
/**
* This reads the <CacheConfig> configuration in identity.xml.
* Since the name of the cache is different between the distributed mode and local mode,
* that is specially handled.
* <p>
* When calling this method, only pass the cacheManagerName and cacheName parameters considering
* how the names are set in a clustered environment i.e. without the CachingConstants.LOCAL_CACHE_PREFIX.
*/
public static IdentityCacheConfig getIdentityCacheConfig(String cacheManagerName, String cacheName) {
IdentityCacheConfigKey configKey = new IdentityCacheConfigKey(cacheManagerName, cacheName);
IdentityCacheConfig identityCacheConfig = identityCacheConfigurationHolder.get(configKey);
if (identityCacheConfig == null && cacheName.startsWith(CachingConstants.LOCAL_CACHE_PREFIX)) {
configKey = new IdentityCacheConfigKey(cacheManagerName, cacheName.replace(CachingConstants.LOCAL_CACHE_PREFIX, ""));
identityCacheConfig = identityCacheConfigurationHolder.get(configKey);
}
return identityCacheConfig;
}
use of org.wso2.carbon.identity.core.model.IdentityCacheConfigKey in project carbon-identity-framework by wso2.
the class IdentityConfigParser method buildCacheConfig.
private void buildCacheConfig() {
OMElement cacheConfig = this.getConfigElement(IdentityConstants.CACHE_CONFIG);
if (cacheConfig != null) {
Iterator<OMElement> cacheManagers = cacheConfig.getChildrenWithName(new QName(IdentityCoreConstants.IDENTITY_DEFAULT_NAMESPACE, IdentityConstants.CACHE_MANAGER));
if (cacheManagers != null) {
while (cacheManagers.hasNext()) {
OMElement cacheManager = cacheManagers.next();
String cacheManagerName = cacheManager.getAttributeValue(new QName(IdentityConstants.CACHE_MANAGER_NAME));
if (StringUtils.isBlank(cacheManagerName)) {
throw IdentityRuntimeException.error("CacheManager name not defined correctly");
}
Iterator<OMElement> caches = cacheManager.getChildrenWithName(new QName(IdentityCoreConstants.IDENTITY_DEFAULT_NAMESPACE, IdentityConstants.CACHE));
if (caches != null) {
while (caches.hasNext()) {
OMElement cache = caches.next();
String cacheName = cache.getAttributeValue(new QName(IdentityConstants.CACHE_NAME));
if (StringUtils.isBlank(cacheName)) {
throw IdentityRuntimeException.error("Cache name not defined correctly");
}
IdentityCacheConfigKey identityCacheConfigKey = new IdentityCacheConfigKey(cacheManagerName, cacheName);
IdentityCacheConfig identityCacheConfig = new IdentityCacheConfig(identityCacheConfigKey);
String enable = cache.getAttributeValue(new QName(IdentityConstants.CACHE_ENABLE));
if (StringUtils.isNotBlank(enable)) {
identityCacheConfig.setEnabled(Boolean.parseBoolean(enable));
}
String timeout = cache.getAttributeValue(new QName(IdentityConstants.CACHE_TIMEOUT));
if (StringUtils.isNotBlank(timeout)) {
identityCacheConfig.setTimeout(Integer.parseInt(timeout));
}
String capacity = cache.getAttributeValue(new QName(IdentityConstants.CACHE_CAPACITY));
if (StringUtils.isNotBlank(capacity)) {
identityCacheConfig.setCapacity(Integer.parseInt(capacity));
}
String isDistributedCache = cache.getAttributeValue(new QName(IS_DISTRIBUTED_CACHE));
if (StringUtils.isNotBlank(isDistributedCache)) {
identityCacheConfig.setDistributed(Boolean.parseBoolean(isDistributedCache));
}
String isTemporaryCache = cache.getAttributeValue(new QName(IS_TEMPORARY));
if (StringUtils.isNotBlank(isTemporaryCache)) {
identityCacheConfig.setTemporary(Boolean.parseBoolean(isTemporaryCache));
}
// Add the config to container
identityCacheConfigurationHolder.put(identityCacheConfigKey, identityCacheConfig);
}
}
IdentityCacheConfigKey spCacheKey = new IdentityCacheConfigKey(cacheManagerName, SERVICE_PROVIDER_CACHE);
IdentityCacheConfig identityCacheConfig = identityCacheConfigurationHolder.get(spCacheKey);
IdentityCacheConfigKey key = new IdentityCacheConfigKey(cacheManagerName, SERVICE_PROVIDER_AUTH_KEY_CACHE);
identityCacheConfigurationHolder.putIfAbsent(key, identityCacheConfig);
key = new IdentityCacheConfigKey(cacheManagerName, SERVICE_PROVIDER_ID_CACHE);
identityCacheConfigurationHolder.putIfAbsent(key, identityCacheConfig);
}
}
}
}
Aggregations