ref 6279: Statistical Algorithms Importer - getUserId doesn't work when session expires and Reload is performed
https://support.d4science.org/issues/6279 git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/statistical-algorithms-importer@141306 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
ea21cfe3bc
commit
ce7cfad579
|
@ -186,9 +186,11 @@ public class CodeUploadPanel extends FormPanel {
|
|||
parent.setButtonAlign(BoxLayoutPack.CENTER);
|
||||
|
||||
Hidden currGroupId=new Hidden(Constants.CURR_GROUP_ID, GCubeClientContext.getCurrentContextId());
|
||||
Hidden currUserId=new Hidden(Constants.CURR_USER_ID, GCubeClientContext.getCurrentUserId());
|
||||
|
||||
VerticalLayoutContainer vlc = new VerticalLayoutContainer();
|
||||
vlc.add(currGroupId);
|
||||
vlc.add(currUserId);
|
||||
vlc.add(fileUploadFieldLabel, new VerticalLayoutData(1, -1, new Margins(0)));
|
||||
vlc.add(uploadProgressBar, new VerticalLayoutData(1, -1, new Margins(5,0,0,0)));
|
||||
uploadProgressBar.setVisible(false);
|
||||
|
|
|
@ -67,16 +67,19 @@ public class LocalUploadServlet extends HttpServlet {
|
|||
logger.info("Code Import session id: " + session.getId());
|
||||
|
||||
try {
|
||||
String scopeGroupId=request.getParameter(Constants.CURR_GROUP_ID);
|
||||
ServiceCredentials aslSession = SessionUtil.getServiceCredentials(request, scopeGroupId);
|
||||
ScopeProvider.instance.set(aslSession.getScope());
|
||||
String scopeGroupId = request.getParameter(Constants.CURR_GROUP_ID);
|
||||
String currUserId = request.getParameter(Constants.CURR_USER_ID);
|
||||
ServiceCredentials serviceCredentials = SessionUtil
|
||||
.getServiceCredentials(request, scopeGroupId, currUserId);
|
||||
|
||||
ScopeProvider.instance.set(serviceCredentials.getScope());
|
||||
|
||||
} catch (StatAlgoImporterServiceException e) {
|
||||
logger.error(e.getLocalizedMessage());
|
||||
e.printStackTrace();
|
||||
throw new ServletException(e.getLocalizedMessage());
|
||||
}
|
||||
|
||||
|
||||
CodeFileUploadSession fileUploadSession = new CodeFileUploadSession();
|
||||
FileUploadMonitor fileUploadMonitor = new FileUploadMonitor();
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.file.FileUpl
|
|||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.project.Project;
|
||||
import org.gcube.portlets.user.statisticalalgorithmsimporter.shared.session.SessionConstants;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayGroupManager;
|
||||
import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeGroup;
|
||||
import org.gcube.vomanagement.usermanagement.model.GCubeUser;
|
||||
import org.slf4j.Logger;
|
||||
|
@ -38,11 +39,11 @@ public class SessionUtil {
|
|||
public static ServiceCredentials getServiceCredentials(
|
||||
HttpServletRequest httpServletRequest)
|
||||
throws StatAlgoImporterServiceException {
|
||||
return getServiceCredentials(httpServletRequest, null);
|
||||
return getServiceCredentials(httpServletRequest, null, null);
|
||||
}
|
||||
|
||||
public static ServiceCredentials getServiceCredentials(
|
||||
HttpServletRequest httpServletRequest, String scopeGroupId)
|
||||
HttpServletRequest httpServletRequest, String scopeGroupId, String currUserId)
|
||||
throws StatAlgoImporterServiceException {
|
||||
|
||||
ServiceCredentials sCredentials = null;
|
||||
|
@ -64,6 +65,7 @@ public class SessionUtil {
|
|||
logger.info("Retrieving credential in session!");
|
||||
PortalContext pContext = PortalContext.getConfiguration();
|
||||
boolean hasScopeGroupId = false;
|
||||
boolean hasCurrUserId = false;
|
||||
|
||||
if (scopeGroupId != null && !scopeGroupId.isEmpty()) {
|
||||
hasScopeGroupId = true;
|
||||
|
@ -72,6 +74,13 @@ public class SessionUtil {
|
|||
hasScopeGroupId = false;
|
||||
}
|
||||
|
||||
if (currUserId != null && !currUserId.isEmpty()) {
|
||||
hasCurrUserId = true;
|
||||
|
||||
} else {
|
||||
hasCurrUserId = false;
|
||||
}
|
||||
|
||||
if (hasScopeGroupId) {
|
||||
scope = pContext.getCurrentScope(scopeGroupId);
|
||||
} else {
|
||||
|
@ -85,8 +94,22 @@ public class SessionUtil {
|
|||
throw new StatAlgoImporterServiceException(error);
|
||||
}
|
||||
|
||||
GCubeUser gCubeUser = pContext.getCurrentUser(httpServletRequest);
|
||||
GCubeUser gCubeUser = null;
|
||||
|
||||
if (hasCurrUserId) {
|
||||
try {
|
||||
gCubeUser = new LiferayUserManager().getUserById(Long
|
||||
.valueOf(currUserId));
|
||||
} catch (Exception e) {
|
||||
String error = "Error retrieving gCubeUser for: [userId= "
|
||||
+ currUserId + ", scope: " + scope + "]";
|
||||
logger.error(error, e);
|
||||
throw new StatAlgoImporterServiceException(error);
|
||||
}
|
||||
} else {
|
||||
gCubeUser = pContext.getCurrentUser(httpServletRequest);
|
||||
}
|
||||
|
||||
if (gCubeUser == null) {
|
||||
String error = "Error retrieving gCubeUser in scope " + scope
|
||||
+ ": " + gCubeUser;
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package org.gcube.portlets.user.statisticalalgorithmsimporter.shared;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author giancarlo email: <a
|
||||
|
@ -25,7 +24,9 @@ public class Constants {
|
|||
public static final String FILE_UPLOADED_FIELD = "FileUploadedField";
|
||||
public static final String STATISTICAL_ALGORITHMS_IMPORTER_JAR_PUBLIC_LINK = "JarPublicLink";
|
||||
public static final String RECIPIENTS = "Recipients";
|
||||
|
||||
public static final String CURR_GROUP_ID="CURR_GROUP_ID";
|
||||
|
||||
|
||||
// Session
|
||||
public static final String CURR_GROUP_ID = "CURR_GROUP_ID";
|
||||
public static final String CURR_USER_ID = "CURR_USER_ID";
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue