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

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

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/portlets/user/data-miner-manager@141301 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Giancarlo Panichi 2016-12-21 10:06:33 +00:00
parent 29cac83598
commit c32fe92482
6 changed files with 63 additions and 32 deletions

View File

@ -500,10 +500,11 @@ public class ComputationsExecutedPanel extends FramedPanel {
+ selectedItem.getId()
+ "&"
+ Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER
+ "=" + selectedItem.getName()
+ "&"
+ "=" + selectedItem.getName() + "&"
+ Constants.CURR_GROUP_ID + "="
+ GCubeClientContext.getCurrentContextId());
+ GCubeClientContext.getCurrentContextId()
+ "&" + Constants.CURR_USER_ID + "="
+ GCubeClientContext.getCurrentUserId());
Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), selectedItem.getName(), "");

View File

@ -423,10 +423,11 @@ public class InputDataSetsPanel extends FramedPanel {
+ selectedItem.getId()
+ "&"
+ Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER
+ "=" + selectedItem.getName()
+ "&"
+ "=" + selectedItem.getName() + "&"
+ Constants.CURR_GROUP_ID + "="
+ GCubeClientContext.getCurrentContextId());
+ GCubeClientContext.getCurrentContextId()
+ "&" + Constants.CURR_USER_ID + "="
+ GCubeClientContext.getCurrentUserId());
Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), selectedItem.getName(), "");

View File

@ -257,7 +257,6 @@ public class OutputDataSetsPanel extends FramedPanel {
.addWorkspaceExplorerSelectNotificationListener(wsResourceExplorerListener);
wsResourcesExplorerPanel.ensureDebugId("wsResourceExplorerPanel");
wsResourcesExplorerPanel.setHeightToInternalScroll(300);
// DND
@ -354,16 +353,18 @@ public class OutputDataSetsPanel extends FramedPanel {
v.add(toolBar, new VerticalLayoutData(1, -1, new Margins(0)));
v.add(dnd, new VerticalLayoutData(1, 1, new Margins(0)));
add(v);
v.addResizeHandler(new ResizeHandler() {
@Override
public void onResize(ResizeEvent event) {
int scrollBarHeight=event.getHeight()-toolBar.getElement().getHeight(false);
Log.debug("ScrollBarHeight: "+scrollBarHeight);
wsResourcesExplorerPanel.setHeightToInternalScroll(scrollBarHeight);
int scrollBarHeight = event.getHeight()
- toolBar.getElement().getHeight(false);
Log.debug("ScrollBarHeight: " + scrollBarHeight);
wsResourcesExplorerPanel
.setHeightToInternalScroll(scrollBarHeight);
forceLayout();
}
});
forceLayout();
@ -421,10 +422,11 @@ public class OutputDataSetsPanel extends FramedPanel {
+ selectedItem.getId()
+ "&"
+ Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER
+ "=" + selectedItem.getName()
+ "&"
+ "=" + selectedItem.getName() + "&"
+ Constants.CURR_GROUP_ID + "="
+ GCubeClientContext.getCurrentContextId());
+ GCubeClientContext.getCurrentContextId()
+ "&" + Constants.CURR_USER_ID + "="
+ GCubeClientContext.getCurrentUserId());
Log.debug("Retrieved link: " + actionUrl);
Window.open(actionUrl.toString(), selectedItem.getName(), "");

View File

@ -21,10 +21,10 @@ import org.slf4j.LoggerFactory;
/**
*
* @author Giancarlo Panichi
* email: <a href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
* @author Giancarlo Panichi email: <a
* href="mailto:g.panichi@isti.cnr.it">g.panichi@isti.cnr.it</a>
*
* Download Folder Servlet
* Download Folder Servlet
*
*/
public class DownloadFolderServlet extends HttpServlet {
@ -76,19 +76,23 @@ public class DownloadFolderServlet extends HttpServlet {
}
logger.debug("DownloadFolderServlet session id: " + session.getId());
String scopeGroupId = request.getParameter(Constants.CURR_GROUP_ID);
String currUserId = request.getParameter(Constants.CURR_USER_ID);
String scopeGroupId=request.getParameter(Constants.CURR_GROUP_ID);
ServiceCredentials serviceCredentials = SessionUtil.getServiceCredentials(request, scopeGroupId);
ServiceCredentials serviceCredentials = SessionUtil
.getServiceCredentials(request, scopeGroupId, currUserId);
ScopeProvider.instance.set(serviceCredentials.getScope());
String itemId = request.getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER);
String folderName = request.getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER);
String itemId = request
.getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER);
String folderName = request
.getParameter(Constants.DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER);
logger.debug("Request: [itemId=" + itemId + ", folderName="
+ folderName + "]");
File tmpZip = StorageUtil.zipFolder(serviceCredentials.getUserName(),
itemId);
File tmpZip = StorageUtil.zipFolder(
serviceCredentials.getUserName(), itemId);
response.setHeader("Content-Disposition", "attachment; filename=\""
+ folderName + ".zip\"");
response.setContentType("application/zip");
@ -109,8 +113,7 @@ public class DownloadFolderServlet extends HttpServlet {
logger.error("Error in DownloadFolderServlet: "
+ e.getLocalizedMessage());
e.printStackTrace();
throw new ServletException("Error:"
+ e.getLocalizedMessage(), e);
throw new ServletException("Error:" + e.getLocalizedMessage(), e);
}
}

View File

@ -18,6 +18,7 @@ import org.gcube.portlets.user.dataminermanager.server.util.ServiceCredentials;
import org.gcube.portlets.user.dataminermanager.shared.Constants;
import org.gcube.portlets.user.dataminermanager.shared.exception.ServiceException;
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;
@ -33,11 +34,11 @@ public class SessionUtil {
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest) throws ServiceException {
return getServiceCredentials(httpServletRequest, null);
return getServiceCredentials(httpServletRequest, null,null);
}
public static ServiceCredentials getServiceCredentials(
HttpServletRequest httpServletRequest, String scopeGroupId)
HttpServletRequest httpServletRequest, String scopeGroupId, String currUserId)
throws ServiceException {
ServiceCredentials sCredentials = null;
@ -59,6 +60,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;
@ -67,6 +69,13 @@ public class SessionUtil {
hasScopeGroupId = false;
}
if (currUserId != null && !currUserId.isEmpty()) {
hasCurrUserId = true;
} else {
hasCurrUserId = false;
}
if (hasScopeGroupId) {
scope = pContext.getCurrentScope(scopeGroupId);
} else {
@ -80,8 +89,22 @@ public class SessionUtil {
throw new ServiceException(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 ServiceException(error);
}
} else {
gCubeUser = pContext.getCurrentUser(httpServletRequest);
}
if (gCubeUser == null) {
String error = "Error retrieving gCubeUser in scope " + scope
+ ": " + gCubeUser;

View File

@ -57,7 +57,8 @@ public class Constants {
public static final String DOWNLOAD_FOLDER_SERVLET_ITEM_ID_PARAMETER = "itemId";
public static final String DOWNLOAD_FOLDER_SERVLET_FOLDER_NAME_PARAMETER = "folderName";
//
//Session
public static final String CURR_GROUP_ID="CURR_GROUP_ID";
public static final String CURR_USER_ID = "CURR_USER_ID";
}