Fixing user cache management #23303
This commit is contained in:
parent
a320786185
commit
d9ed838a89
|
@ -2,7 +2,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
|
||||||
|
|
||||||
# Changelog for gCube Catalogue (gCat) Service
|
# Changelog for gCube Catalogue (gCat) Service
|
||||||
|
|
||||||
## [v2.2.0]
|
## [v2.2.0-SNAPSHOT]
|
||||||
|
|
||||||
- Switched gcat credentials to new IAM authz [#21628][#22727]
|
- Switched gcat credentials to new IAM authz [#21628][#22727]
|
||||||
- Added support to manage configurations [#22658][#22742]
|
- Added support to manage configurations [#22658][#22742]
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -12,7 +12,7 @@
|
||||||
<groupId>org.gcube.data-catalogue</groupId>
|
<groupId>org.gcube.data-catalogue</groupId>
|
||||||
<artifactId>gcat</artifactId>
|
<artifactId>gcat</artifactId>
|
||||||
<packaging>war</packaging>
|
<packaging>war</packaging>
|
||||||
<version>2.2.0</version>
|
<version>2.2.0-SNAPSHOT</version>
|
||||||
<name>gCube Catalogue (gCat) Service</name>
|
<name>gCube Catalogue (gCat) Service</name>
|
||||||
<description>
|
<description>
|
||||||
This service allows any client to publish on the gCube Catalogue.
|
This service allows any client to publish on the gCube Catalogue.
|
||||||
|
|
|
@ -56,7 +56,7 @@ public class CatalogueConfigurationFactory {
|
||||||
|
|
||||||
// The supported organizations could be changed we need to empty the user cache for the context
|
// The supported organizations could be changed we need to empty the user cache for the context
|
||||||
// to avoid to miss to add an user in an organization which has been added.
|
// to avoid to miss to add an user in an organization which has been added.
|
||||||
CKANUserCache.emptyUserCache();
|
CKANUserCache.emptyUsersCache();
|
||||||
|
|
||||||
return catalogueConfiguration;
|
return catalogueConfiguration;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package org.gcube.gcat.persistence.ckan;
|
package org.gcube.gcat.persistence.ckan;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import javax.cache.Cache;
|
import javax.cache.Cache;
|
||||||
|
@ -24,8 +22,6 @@ public abstract class CKANUserCache {
|
||||||
|
|
||||||
private static final MutableConfiguration<String,CKANUser> userCacheConfiguration;
|
private static final MutableConfiguration<String,CKANUser> userCacheConfiguration;
|
||||||
|
|
||||||
private static final Map<String,Cache<String,CKANUser>> userCachePerContext;
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
CachingProvider provider = Caching.getCachingProvider();
|
CachingProvider provider = Caching.getCachingProvider();
|
||||||
cacheManager = provider.getCacheManager();
|
cacheManager = provider.getCacheManager();
|
||||||
|
@ -33,8 +29,6 @@ public abstract class CKANUserCache {
|
||||||
userCacheConfiguration = new MutableConfiguration<String,CKANUser>().setTypes(String.class, CKANUser.class)
|
userCacheConfiguration = new MutableConfiguration<String,CKANUser>().setTypes(String.class, CKANUser.class)
|
||||||
.setStoreByValue(false)
|
.setStoreByValue(false)
|
||||||
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 15)));
|
.setExpiryPolicyFactory(CreatedExpiryPolicy.factoryOf(new Duration(TimeUnit.MINUTES, 15)));
|
||||||
|
|
||||||
userCachePerContext = new HashMap<String,Cache<String,CKANUser>>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CKANUserCache() {
|
private CKANUserCache() {
|
||||||
|
@ -43,10 +37,9 @@ public abstract class CKANUserCache {
|
||||||
public synchronized static CKANUser getCurrrentCKANUser() {
|
public synchronized static CKANUser getCurrrentCKANUser() {
|
||||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
String context = secretManager.getContext();
|
String context = secretManager.getContext();
|
||||||
Cache<String,CKANUser> userCache = userCachePerContext.get(context);
|
Cache<String,CKANUser> userCache = cacheManager.getCache(context);
|
||||||
if(userCache == null) {
|
if(userCache == null) {
|
||||||
userCache = cacheManager.createCache(context, userCacheConfiguration);
|
userCache = cacheManager.createCache(context, userCacheConfiguration);
|
||||||
userCachePerContext.put(context, userCache);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String gcubeUsername = secretManager.getUser().getUsername();
|
String gcubeUsername = secretManager.getUser().getUsername();
|
||||||
|
@ -68,16 +61,16 @@ public abstract class CKANUserCache {
|
||||||
public synchronized static void removeUserFromCache(String gcubeUsername) {
|
public synchronized static void removeUserFromCache(String gcubeUsername) {
|
||||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
String context = secretManager.getContext();
|
String context = secretManager.getContext();
|
||||||
Cache<String,CKANUser> userCache = userCachePerContext.get(context);
|
Cache<String,CKANUser> userCache = cacheManager.getCache(context);
|
||||||
if(userCache != null) {
|
if(userCache != null) {
|
||||||
userCache.remove(gcubeUsername);
|
userCache.remove(gcubeUsername);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static void emptyUserCache() {
|
public synchronized static void emptyUsersCache() {
|
||||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
String context = secretManager.getContext();
|
String context = secretManager.getContext();
|
||||||
userCachePerContext.remove(context);
|
cacheManager.destroyCache(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue