Added a way to remove user from cache
This commit is contained in:
parent
49b8424965
commit
38b3c9aa72
|
@ -59,6 +59,16 @@ public abstract class CKANUserCache {
|
||||||
return ckanUser;
|
return ckanUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void removeUserFromCache() {
|
||||||
|
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
|
String context = secretManager.getContext();
|
||||||
|
Cache<String,CKANUser> userCache = userCachePerContext.get(context);
|
||||||
|
if(userCache != null) {
|
||||||
|
String gcubeUsername = secretManager.getUser().getUsername();
|
||||||
|
userCache.remove(gcubeUsername);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void finalize() throws Throwable {
|
protected void finalize() throws Throwable {
|
||||||
super.finalize();
|
super.finalize();
|
||||||
|
|
|
@ -10,11 +10,14 @@ import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.Produces;
|
import javax.ws.rs.Produces;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import javax.ws.rs.core.Response.Status;
|
||||||
|
|
||||||
|
import org.gcube.gcat.annotation.PURGE;
|
||||||
//import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
//import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
||||||
import org.gcube.gcat.api.GCatConstants;
|
import org.gcube.gcat.api.GCatConstants;
|
||||||
//import org.gcube.gcat.api.roles.Role;
|
//import org.gcube.gcat.api.roles.Role;
|
||||||
import org.gcube.gcat.persistence.ckan.CKANUser;
|
import org.gcube.gcat.persistence.ckan.CKANUser;
|
||||||
|
import org.gcube.gcat.persistence.ckan.CKANUserCache;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Luca Frosini (ISTI - CNR)
|
* @author Luca Frosini (ISTI - CNR)
|
||||||
|
@ -66,8 +69,19 @@ public class User extends REST<CKANUser> implements org.gcube.gcat.api.interface
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{" + USER_ID_PARAMETER + "}")
|
@Path("/{" + USER_ID_PARAMETER + "}")
|
||||||
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
||||||
|
/*
|
||||||
|
* Purge user form cache
|
||||||
|
*/
|
||||||
public Response delete(@PathParam(USER_ID_PARAMETER) String username) {
|
public Response delete(@PathParam(USER_ID_PARAMETER) String username) {
|
||||||
return super.delete(username, false);
|
CKANUserCache.removeUserFromCache();
|
||||||
|
return Response.status(Status.NO_CONTENT).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PURGE
|
||||||
|
@Path("/{" + USER_ID_PARAMETER + "}")
|
||||||
|
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
||||||
|
public Response purge(@PathParam(USER_ID_PARAMETER) String username) {
|
||||||
|
return super.delete(username, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue