diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/CkanLogout.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/CkanLogout.java index cbd6ed5..da9cc06 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/CkanLogout.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/CkanLogout.java @@ -38,13 +38,14 @@ public class CkanLogout extends HttpServlet { */ @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { - logger.info("CkanLogout performing..."); HttpSession httpSession = req.getSession(); ASLSession session = getASLSession(httpSession); + String scope = session.getScope(); String username = session.getUsername(); - CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(req.getSession()); + logger.info("CkanLogout performing..."); + CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(req.getSession(), scope); // String token = getGcubeSecurityToken(); - logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue()); + logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue() +", the scope is: "+scope); String ckanConnectorLogut = getServletContext().getInitParameter(GcubeCkanDataCatalogServiceImpl.CKANCONNECTORLOGOUT); logger.debug(GcubeCkanDataCatalogServiceImpl.CKANCONNECTORLOGOUT + " is: "+ckanConnectorLogut); diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java index b7ae6cd..a5875dc 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/GcubeCkanDataCatalogServiceImpl.java @@ -109,7 +109,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem } CkanConnectorAccessPoint ckAP = getCkanConnectorAccessPoint(pathInfoParameter, queryStringParameters); - SessionUtil.saveCkanAccessPoint(this.getThreadLocalRequest().getSession(), ckAP); + ASLSession aslSession = getASLSession(this.getThreadLocalRequest().getSession()); + SessionUtil.saveCkanAccessPoint(this.getThreadLocalRequest().getSession(), aslSession.getScope(), ckAP); logger.info("Builded URI to CKAN Connector: "+ckAP.buildURI()); logger.debug("returning ckanConnectorUri: "+ckAP); return ckAP; @@ -133,10 +134,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem private CkanConnectorAccessPoint getCkanConnectorAccessPoint(String pathInfoParameter, String queryStringParameters) throws Exception { if(outsidePortal()){ - CkanConnectorAccessPoint ckan = new CkanConnectorAccessPoint(getCkanUtilsObj().getCatalogueUrl(),""); return ckan; - } //CKAN BASE URL @@ -394,7 +393,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem HttpSession httpSession = this.getThreadLocalRequest().getSession(); ASLSession session = getASLSession(httpSession); String username = session.getUsername(); - CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession()); + CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession(), session.getScope()); // String token = getGcubeSecurityToken(); logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue()); @@ -415,7 +414,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem HttpSession httpSession = this.getThreadLocalRequest().getSession(); ASLSession session = getASLSession(httpSession); String username = session.getUsername(); - CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession()); + CkanConnectorAccessPoint ckanAP = SessionUtil.getCkanAccessPoint(this.getThreadLocalRequest().getSession(), session.getScope()); // String token = getGcubeSecurityToken(); logger.info("Logout from CKAN for: "+username +" by token: "+ckanAP.getGcubeTokenValue()); diff --git a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java index 2a8962f..b889ab2 100644 --- a/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/gcubeckan/gcubeckandatacatalog/server/SessionUtil.java @@ -29,16 +29,20 @@ public class SessionUtil { * Gets the ckan end point. * * @param session the session + * @param scope the scope * @return the ckan end point + * @throws Exception the exception */ public static GcoreEndpointReader getCkanEndPoint(HttpSession session, String scope) throws Exception{ - GcoreEndpointReader ckanEndPoint = (GcoreEndpointReader) session.getAttribute(CKAN_END_POINT); - + String key = getKeyForSession(CKAN_END_POINT, scope); + logger.debug("Getting GcoreEndpointReader for key: "+key +", from HttpSession"); + GcoreEndpointReader ckanEndPoint = (GcoreEndpointReader) session.getAttribute(key); + logger.debug("GcoreEndpointReader for key: "+key +", found in session? "+(ckanEndPoint!=null)); if(ckanEndPoint==null){ logger.debug("GcoreEndpointReader is null, instancing new.."); ckanEndPoint = new GcoreEndpointReader(scope); - session.setAttribute(CKAN_END_POINT, ckanEndPoint); + session.setAttribute(key, ckanEndPoint); } logger.debug("returning: "+ckanEndPoint); return ckanEndPoint; @@ -60,23 +64,38 @@ public class SessionUtil { } /** - * @param ckAP + * Save ckan access point. + * + * @param session the session + * @param scope the scope + * @param ckAP the ck ap */ - public static void saveCkanAccessPoint(HttpSession session, CkanConnectorAccessPoint ckAP) { - - session.setAttribute(CKAN_ACCESS_POINT, ckAP); + public static void saveCkanAccessPoint(HttpSession session, String scope, CkanConnectorAccessPoint ckAP) { + String key = getKeyForSession(CKAN_ACCESS_POINT, scope); + session.setAttribute(key, ckAP); + } + /** + * Gets the key for session. + * + * @param key the key + * @param scope the scope + * @return the key for session + */ + private static String getKeyForSession(String key, String scope){ + return key+scope; } /** * Gets the ckan access point. * * @param session the session + * @param scope the scope * @return the ckan access point */ - public static CkanConnectorAccessPoint getCkanAccessPoint(HttpSession session) { - - return (CkanConnectorAccessPoint) session.getAttribute(CKAN_ACCESS_POINT); + public static CkanConnectorAccessPoint getCkanAccessPoint(HttpSession session, String scope) { + String key = getKeyForSession(CKAN_ACCESS_POINT, scope); + return (CkanConnectorAccessPoint) session.getAttribute(key); }