Added some methods to clear caches

This commit is contained in:
Mauro Mugnaini 2020-06-18 12:10:43 +02:00
parent 6c6f896b77
commit 530637d2de
2 changed files with 36 additions and 12 deletions

View File

@ -1,4 +1,4 @@
package com.nubisware.oidc.lr62; package org.gcube.portal.oidc.lr62;
import java.util.Collections; import java.util.Collections;
import java.util.Map; import java.util.Map;
@ -6,15 +6,16 @@ import java.util.TreeMap;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import com.liferay.portal.model.User; import org.gcube.oidc.rest.JWTToken;
import com.nubisware.oidc.rest.JWTToken;
public class IntraVMOIDCTokenProxy extends OIDCTokenProxy { import com.liferay.portal.model.User;
public class IntraVMOIDCTokenCacheProxy extends OIDCTokenCacheProxy {
private Map<String, String> oidcTokens; private Map<String, String> oidcTokens;
private Map<String, String> rptTokens; private Map<String, String> rptTokens;
protected IntraVMOIDCTokenProxy() { protected IntraVMOIDCTokenCacheProxy() {
oidcTokens = Collections.synchronizedMap(new TreeMap<>()); oidcTokens = Collections.synchronizedMap(new TreeMap<>());
rptTokens = Collections.synchronizedMap(new TreeMap<>()); rptTokens = Collections.synchronizedMap(new TreeMap<>());
} }
@ -49,4 +50,20 @@ public class IntraVMOIDCTokenProxy extends OIDCTokenProxy {
rptTokens.remove(generateKey(user, session)); rptTokens.remove(generateKey(user, session));
} }
@Override
public void clearOIDCTokens() {
oidcTokens.clear();
}
@Override
public void clearUMATokens() {
rptTokens.clear();
}
@Override
public void clearAllTokens() {
clearOIDCTokens();
clearUMATokens();
}
} }

View File

@ -1,19 +1,20 @@
package com.nubisware.oidc.lr62; package org.gcube.portal.oidc.lr62;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import org.gcube.oidc.rest.JWTToken;
import com.liferay.portal.model.User; import com.liferay.portal.model.User;
import com.nubisware.oidc.rest.JWTToken;
public abstract class OIDCTokenProxy { public abstract class OIDCTokenCacheProxy {
protected static OIDCTokenProxy instance; protected static OIDCTokenCacheProxy instance;
public OIDCTokenProxy() { public OIDCTokenCacheProxy() {
instance = this; instance = this;
} }
public static synchronized OIDCTokenProxy getInstance() { public static synchronized OIDCTokenCacheProxy getInstance() {
return instance != null ? instance : new IntraVMOIDCTokenProxy(); return instance != null ? instance : new IntraVMOIDCTokenCacheProxy();
} }
public abstract void setOIDCToken(User user, HttpSession session, JWTToken token); public abstract void setOIDCToken(User user, HttpSession session, JWTToken token);
@ -28,6 +29,12 @@ public abstract class OIDCTokenProxy {
public abstract void removeUMAToken(User user, HttpSession session); public abstract void removeUMAToken(User user, HttpSession session);
public abstract void clearOIDCTokens();
public abstract void clearUMATokens();
public abstract void clearAllTokens();
protected String generateKey(User user, HttpSession session) { protected String generateKey(User user, HttpSession session) {
return user.getScreenName() + "@" + session.getId(); return user.getScreenName() + "@" + session.getId();
} }