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(
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;