ref 6278: DataMiner - getUserId doesn't work when session expires and Reload is performed

https://support.d4science.org/issues/6278

Fixed getCurrentUserToken

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/data-miner-manager@141370 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-12-22 13:56:14 +00:00
parent c32fe92482
commit 6f05c59394
1 changed files with 21 additions and 5 deletions

View File

@ -34,12 +34,12 @@ public class SessionUtil {
public static ServiceCredentials getServiceCredentials( public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest) throws ServiceException { HttpServletRequest httpServletRequest) throws ServiceException {
return getServiceCredentials(httpServletRequest, null,null); return getServiceCredentials(httpServletRequest, null, null);
} }
public static ServiceCredentials getServiceCredentials( public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest, String scopeGroupId, String currUserId) HttpServletRequest httpServletRequest, String scopeGroupId,
throws ServiceException { String currUserId) throws ServiceException {
ServiceCredentials sCredentials = null; ServiceCredentials sCredentials = null;
String userName = null; String userName = null;
@ -83,6 +83,7 @@ public class SessionUtil {
} }
logger.debug("Scope: " + scope);
if (scope == null || scope.isEmpty()) { if (scope == null || scope.isEmpty()) {
String error = "Error retrieving scope: " + scope; String error = "Error retrieving scope: " + scope;
logger.error(error); logger.error(error);
@ -104,7 +105,7 @@ public class SessionUtil {
} else { } else {
gCubeUser = pContext.getCurrentUser(httpServletRequest); gCubeUser = pContext.getCurrentUser(httpServletRequest);
} }
if (gCubeUser == null) { if (gCubeUser == null) {
String error = "Error retrieving gCubeUser in scope " + scope String error = "Error retrieving gCubeUser in scope " + scope
+ ": " + gCubeUser; + ": " + gCubeUser;
@ -113,6 +114,7 @@ public class SessionUtil {
} }
userName = gCubeUser.getUsername(); userName = gCubeUser.getUsername();
logger.debug("UserName: " + userName);
if (userName == null || userName.isEmpty()) { if (userName == null || userName.isEmpty()) {
String error = "Error retrieving username in scope " + scope String error = "Error retrieving username in scope " + scope
@ -121,8 +123,22 @@ public class SessionUtil {
throw new ServiceException(error); 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()) { if (token == null || token.isEmpty()) {
String error = "Error retrieving token for " + userName String error = "Error retrieving token for " + userName
+ " in " + scope + ": " + token; + " in " + scope + ": " + token;