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
This commit is contained in:
Costantino Perciante 2016-06-18 12:01:58 +00:00
parent 60b93329ec
commit d706509bd8
1 changed files with 29 additions and 1 deletions

View File

@ -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){