From d706509bd82fb7601a93cdacc2a5ea2f055a53ae Mon Sep 17 00:00:00 2001 From: Costantino Perciante Date: Sat, 18 Jun 2016 12:01:58 +0000 Subject: [PATCH] minor fix git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/gcube-ckan-datacatalog@129161 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../GcubeCkanDataCatalogServiceImpl.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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 8cfa7d6..ff5f10b 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 @@ -52,6 +52,8 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem private final static String TEST_SEC_TOKEN = "4620e6d0-2313-4f48-9d54-eb3efd01a810"; // private final static String TEST_SEC_TOKEN = "f539884c-8697-4ac0-9bbf-2f4d595281f5"; + public static final String CKAN_TOKEN_KEY = "ckanToken"; + // ckan utils methods private CKanUtilsImpl instance; @@ -67,6 +69,32 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem } } + /** + * Get current user's token + * @return String the ckan user's token + */ + private String getUserCKanTokenFromSession(){ + + HttpSession httpSession = this.getThreadLocalRequest().getSession(); + ASLSession session = getASLSession(httpSession); + String username = session.getUsername(); + logger.debug("User in session is " + username); + + String token = null; + if(this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY) != null) + token = (String)this.getThreadLocalRequest().getSession().getAttribute(CKAN_TOKEN_KEY); + else{ + + token = instance.getApiKeyFromUsername(username); + this.getThreadLocalRequest().getSession().setAttribute(CKAN_TOKEN_KEY, token); + logger.debug("Ckan token has been set for user " + username); + } + + logger.debug("Found ckan token " + token + " for user " + username); + return token; + + } + /* (non-Javadoc) * @see org.gcube.portlets.gcubeckan.gcubeckandatacatalog.client.GcubeCkanDataCatalogService#getCKanConnector() */ @@ -182,7 +210,7 @@ public class GcubeCkanDataCatalogServiceImpl extends RemoteServiceServlet implem try{ // first of all, check if the user is a sysadmin in the catalog (in this case he can do everything) - boolean isSysAdmin = instance.isSysAdmin(username, instance.getApiKeyFromUsername(username)); + boolean isSysAdmin = instance.isSysAdmin(username, getUserCKanTokenFromSession()); if(isSysAdmin){