diff --git a/distro/changelog.xml b/distro/changelog.xml index 432e61d..759d878 100644 --- a/distro/changelog.xml +++ b/distro/changelog.xml @@ -1,7 +1,8 @@ + date="2016-01-20"> Added a loader on share window when contacts are loading from server + Removed currUserId parameter from client side required for external servlets diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java index d3dc606..d420e35 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/AppControllerExplorer.java @@ -945,7 +945,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt // Add currentContextId parameter String currentContextId = GCubeClientContext.getCurrentContextId(); String currentUserId = GCubeClientContext.getCurrentUserId(); - String queryString = "id="+fileDownloadEvent.getItemIdentifier()+"&viewContent=true&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"="+currentContextId+"&"+ConstantsExplorer.CURRENT_USER_ID+"="+currentUserId; + String queryString = "id="+fileDownloadEvent.getItemIdentifier()+"&viewContent=true&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"="+currentContextId; new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET, ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE, queryString, "_blank", downloadHandlerCallback); } catch (Exception e) { @@ -968,7 +968,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt // Add currentContextId parameter String currentContextId = GCubeClientContext.getCurrentContextId(); String currentUserId = GCubeClientContext.getCurrentUserId(); - String queryString = "id="+fileDownloadEvent.getItemIdentifier()+"&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"="+currentContextId+"&"+ConstantsExplorer.CURRENT_USER_ID+"="+currentUserId; + String queryString = "id="+fileDownloadEvent.getItemIdentifier()+"&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"="+currentContextId; new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET,ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE, queryString, "_self", downloadHandlerCallback); } catch (Exception e) { explorerPanel.getAsycTreePanel().unmask(); diff --git a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java index a79bf25..17200b3 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java +++ b/src/main/java/org/gcube/portlets/user/workspace/client/ConstantsExplorer.java @@ -230,7 +230,6 @@ public static enum WS_UPLOAD_TYPE {File, Archive}; public static final String ERROR_ITEM_DOES_NOT_EXIST = "Item does not exist. It may have been deleted by another user"; public static final String VALIDATEITEM = "validateitem"; public static final String CURRENT_CONTEXT_ID = "contextID"; - public static final String CURRENT_USER_ID = "currUserId"; public static final String REDIRECTONERROR = "redirectonerror"; //UPLOAD SERVLET PARAMETERS diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java b/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java index de2b2ab..ab24748 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/DownloadServlet.java @@ -35,11 +35,13 @@ import org.gcube.common.homelibrary.home.workspace.folder.items.ts.TimeSeries; import org.gcube.common.homelibrary.util.Extensions; import org.gcube.common.homelibrary.util.MimeTypeUtil; import org.gcube.common.homelibrary.util.zip.ZipUtil; +import org.gcube.common.portal.PortalContext; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.server.property.PortalUrlGroupGatewayProperty; import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.shared.HandlerResultMessage; import org.gcube.portlets.user.workspace.shared.SessionExpiredException; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; /** @@ -74,14 +76,15 @@ public class DownloadServlet extends HttpServlet{ boolean isValidItem = req.getParameter(ConstantsExplorer.VALIDATEITEM)==null?false:req.getParameter(ConstantsExplorer.VALIDATEITEM).equals("true"); boolean urlRedirectOnError = req.getParameter(ConstantsExplorer.REDIRECTONERROR)==null?false:req.getParameter(ConstantsExplorer.REDIRECTONERROR).equals("true"); String contextID = req.getParameter(ConstantsExplorer.CURRENT_CONTEXT_ID); - String userID = req.getParameter(ConstantsExplorer.CURRENT_USER_ID); + //String userID = req.getParameter(ConstantsExplorer.CURRENT_USER_ID); - logger.debug("Input Params [id: "+itemId + ", viewContent: "+viewContent+", "+ConstantsExplorer.VALIDATEITEM +": " +isValidItem+", urlRedirectOnError:" +urlRedirectOnError+", contextID: "+contextID+", userID: "+userID+"]"); + logger.debug("Input Params [id: "+itemId + ", viewContent: "+viewContent+", "+ConstantsExplorer.VALIDATEITEM +": " +isValidItem+", urlRedirectOnError:" +urlRedirectOnError+", contextID: "+contextID+"]"); if(itemId==null || itemId.isEmpty()){ sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Item id is null"); return; } + logger.debug("FILE DOWNLOAD REQUEST "+itemId); Workspace wa = null; try { @@ -90,7 +93,11 @@ public class DownloadServlet extends HttpServlet{ // if(WsUtil.isSessionExpired(req)) // throw new SessionExpiredException(); - wa = WsUtil.getWorkspace(req, contextID, userID); + if(WsUtil.isSessionExpired(req)) + throw new SessionExpiredException(); + + GCubeUser gcubeUser = PortalContext.getConfiguration().getCurrentUser(req); + wa = WsUtil.getWorkspace(req, contextID, gcubeUser); } catch (Exception e) { if (e instanceof SessionExpiredException){ diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java index d0357fe..5c645cf 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/GWTWorkspaceBuilder.java @@ -272,8 +272,8 @@ public class GWTWorkspaceBuilder { sb.append(requestType.toString()); sb.append("&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"="); sb.append(currentGroupId); - sb.append("&"+ConstantsExplorer.CURRENT_USER_ID+"="); - sb.append(currUserId); +// sb.append("&"+ConstantsExplorer.CURRENT_USER_ID+"="); +// sb.append(currUserId); sb.append("&random="); sb.append(UUID.randomUUID().toString()); return sb.toString(); diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java b/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java index 640ebd8..04ea18b 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/ImageServlet.java @@ -22,9 +22,12 @@ import org.gcube.common.homelibrary.home.workspace.WorkspaceItem; import org.gcube.common.homelibrary.home.workspace.exceptions.ItemNotFoundException; import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; import org.gcube.common.homelibrary.home.workspace.folder.items.Image; +import org.gcube.common.portal.PortalContext; import org.gcube.portlets.user.workspace.client.ConstantsExplorer; import org.gcube.portlets.user.workspace.client.util.ImageRequestType; import org.gcube.portlets.user.workspace.server.util.WsUtil; +import org.gcube.portlets.user.workspace.shared.SessionExpiredException; +import org.gcube.vomanagement.usermanagement.model.GCubeUser; /** @@ -59,7 +62,7 @@ public class ImageServlet extends HttpServlet{ String imageId = req.getParameter("id"); String imageType = req.getParameter("type"); String contextID = req.getParameter(ConstantsExplorer.CURRENT_CONTEXT_ID); - String currUserId = req.getParameter(ConstantsExplorer.CURRENT_USER_ID); + //String currUserId = req.getParameter(ConstantsExplorer.CURRENT_USER_ID); logger.info("request image id: "+imageId+", type: "+imageType +", "+ConstantsExplorer.CURRENT_CONTEXT_ID+ ": "+contextID); @@ -70,11 +73,19 @@ public class ImageServlet extends HttpServlet{ requestType = ImageRequestType.IMAGE; } else requestType = ImageRequestType.valueOf(imageType); - Workspace wa = null; try { - wa = WsUtil.getWorkspace(req, contextID, currUserId); + + if(WsUtil.isSessionExpired(req)) + throw new SessionExpiredException(); + + GCubeUser gcubeUser = PortalContext.getConfiguration().getCurrentUser(req); + wa = WsUtil.getWorkspace(req, contextID, gcubeUser); } catch (Exception e) { + if (e instanceof SessionExpiredException){ + resp.sendError(HttpServletResponse.SC_UNAUTHORIZED, "Error the user session is expired"); + return; + } logger.error("Error during workspace retrieving", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Error during workspace retrieving"); return; diff --git a/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java b/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java index dab5f9c..7a26d37 100644 --- a/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java +++ b/src/main/java/org/gcube/portlets/user/workspace/server/util/WsUtil.java @@ -27,7 +27,6 @@ import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParame import org.gcube.portlets.user.workspace.server.resolver.UriResolverReaderParameterForResolverIndex.RESOLVER_TYPE; import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader; import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter; -import org.gcube.vomanagement.usermanagement.impl.LiferayUserManager; import org.gcube.vomanagement.usermanagement.model.GCubeUser; import com.liferay.portal.service.UserLocalServiceUtil; @@ -120,8 +119,7 @@ public class WsUtil { */ public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception { logger.trace("workspace session validating..."); - PortalContextInfo info = getPortalContext(httpServletRequest); - return info.getUsername()==null; + return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null; } @@ -148,21 +146,20 @@ public class WsUtil { } - /** * Gets the workspace. * * @param httpServletRequest the http servlet request * @param contextID the context id - * @param currUserId the curr user id + * @param user the user * @return the workspace * @throws InternalErrorException the internal error exception * @throws HomeNotFoundException the home not found exception * @throws WorkspaceFolderNotFoundException the workspace folder not found exception */ - public static Workspace getWorkspace(HttpServletRequest httpServletRequest, String contextID, String currUserId) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException + public static Workspace getWorkspace(HttpServletRequest httpServletRequest, String contextID, GCubeUser user) throws InternalErrorException, HomeNotFoundException, WorkspaceFolderNotFoundException { - logger.info("Get workspace using contextID: "+contextID +", currUserId: "+currUserId); + logger.info("Get workspace using contextID: "+contextID +", current user: "+user.getUsername()); String currentScope = PortalContext.getConfiguration().getCurrentScope(contextID); logger.info("For ContextID: "+contextID +", read scope from Portal Context: "+currentScope); PortalContextInfo info = getPortalContext(httpServletRequest, currentScope); @@ -173,21 +170,17 @@ public class WsUtil { String username = null; try { - GCubeUser gCubeUser = new LiferayUserManager().getUserById(Long.valueOf(currUserId)); - logger.debug("Gcube user read from liferay: "+gCubeUser); - if(gCubeUser!=null && gCubeUser.getUsername()!=null) - username = gCubeUser.getUsername(); + if(user.getUsername().compareTo(info.getUsername())!=0){ + logger.debug("Gcube user read from Portal Context "+user.getUsername()+" is different by GCubeUser passed, using the second one: "+info.getUsername()); + username = user.getUsername(); + } + } catch (Exception e) { - String error = "Error retrieving gCubeUser for: [userId= " - + currUserId + ", scope: " + currentScope + "]"; - logger.error(error, e); + logger.error("Error comparing username read from input parameter and Portal context"); } - if(username==null || username.isEmpty()) - username = PortalContext.getConfiguration().getCurrentUser(httpServletRequest).getUsername(); - - //overriding username - info.setUsername(username); + if(username!=null) + info.setUsername(username); Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername()); return workspace;