diff --git a/src/main/java/org/gcube/portlets/user/dataminermanager/server/SessionUtil.java b/src/main/java/org/gcube/portlets/user/dataminermanager/server/SessionUtil.java index b1a61e4..750b79e 100644 --- a/src/main/java/org/gcube/portlets/user/dataminermanager/server/SessionUtil.java +++ b/src/main/java/org/gcube/portlets/user/dataminermanager/server/SessionUtil.java @@ -34,12 +34,12 @@ public class SessionUtil { public static ServiceCredentials getServiceCredentials( HttpServletRequest httpServletRequest) throws ServiceException { - return getServiceCredentials(httpServletRequest, null,null); + return getServiceCredentials(httpServletRequest, null, null); } public static ServiceCredentials getServiceCredentials( - HttpServletRequest httpServletRequest, String scopeGroupId, String currUserId) - throws ServiceException { + HttpServletRequest httpServletRequest, String scopeGroupId, + String currUserId) throws ServiceException { ServiceCredentials sCredentials = null; String userName = null; @@ -83,6 +83,7 @@ public class SessionUtil { } + logger.debug("Scope: " + scope); if (scope == null || scope.isEmpty()) { String error = "Error retrieving scope: " + scope; logger.error(error); @@ -104,7 +105,7 @@ public class SessionUtil { } else { gCubeUser = pContext.getCurrentUser(httpServletRequest); } - + if (gCubeUser == null) { String error = "Error retrieving gCubeUser in scope " + scope + ": " + gCubeUser; @@ -113,6 +114,7 @@ public class SessionUtil { } userName = gCubeUser.getUsername(); + logger.debug("UserName: " + userName); if (userName == null || userName.isEmpty()) { String error = "Error retrieving username in scope " + scope @@ -121,8 +123,22 @@ public class SessionUtil { throw new ServiceException(error); } - token = pContext.getCurrentUserToken(scope, httpServletRequest); + if (hasCurrUserId) { + try { + token = pContext.getCurrentUserToken(scope, + Long.valueOf(currUserId)); + } catch (Exception e) { + String error = "Error retrieving token for: [userId= " + + currUserId + ", scope: " + scope + "]"; + logger.error(error, e); + throw new ServiceException(error); + } + } else { + token = pContext.getCurrentUserToken(scope, httpServletRequest); + } + + logger.debug("Token: " + token); if (token == null || token.isEmpty()) { String error = "Error retrieving token for " + userName + " in " + scope + ": " + token;