Removed currUserId parameter from client side required by external servlets

git-svn-id: http://svn.d4science-ii.research-infrastructures.eu/gcube/trunk/portlets/user/workspace-tree-widget@141663 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2017-01-20 11:45:38 +00:00
parent efbc34a52b
commit eb618e3dd3
7 changed files with 42 additions and 31 deletions

View File

@ -1,7 +1,8 @@
<ReleaseNotes> <ReleaseNotes>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-15-2" <Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-15-2"
date="2016-01-09"> date="2016-01-20">
<Change>Added a loader on share window when contacts are loading from server</Change> <Change>Added a loader on share window when contacts are loading from server</Change>
<Change>Removed currUserId parameter from client side required for external servlets</Change>
</Changeset> </Changeset>
<Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-15-1" <Changeset component="org.gcube.portlets-user.workspace-portlet-tree.6-15-1"
date="2016-01-05"> date="2016-01-05">

View File

@ -945,7 +945,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
// Add currentContextId parameter // Add currentContextId parameter
String currentContextId = GCubeClientContext.getCurrentContextId(); String currentContextId = GCubeClientContext.getCurrentContextId();
String currentUserId = GCubeClientContext.getCurrentUserId(); 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); new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET, ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE, queryString, "_blank", downloadHandlerCallback);
} catch (Exception e) { } catch (Exception e) {
@ -968,7 +968,7 @@ public class AppControllerExplorer implements EventHandler, TreeAppControllerInt
// Add currentContextId parameter // Add currentContextId parameter
String currentContextId = GCubeClientContext.getCurrentContextId(); String currentContextId = GCubeClientContext.getCurrentContextId();
String currentUserId = GCubeClientContext.getCurrentUserId(); 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); new RequestBuilderWorkspaceValidateItem(RequestBuilder.GET,ConstantsExplorer.DOWNLOAD_WORKSPACE_SERVICE, queryString, "_self", downloadHandlerCallback);
} catch (Exception e) { } catch (Exception e) {
explorerPanel.getAsycTreePanel().unmask(); explorerPanel.getAsycTreePanel().unmask();

View File

@ -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 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 VALIDATEITEM = "validateitem";
public static final String CURRENT_CONTEXT_ID = "contextID"; public static final String CURRENT_CONTEXT_ID = "contextID";
public static final String CURRENT_USER_ID = "currUserId";
public static final String REDIRECTONERROR = "redirectonerror"; public static final String REDIRECTONERROR = "redirectonerror";
//UPLOAD SERVLET PARAMETERS //UPLOAD SERVLET PARAMETERS

View File

@ -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.Extensions;
import org.gcube.common.homelibrary.util.MimeTypeUtil; import org.gcube.common.homelibrary.util.MimeTypeUtil;
import org.gcube.common.homelibrary.util.zip.ZipUtil; 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.client.ConstantsExplorer;
import org.gcube.portlets.user.workspace.server.property.PortalUrlGroupGatewayProperty; import org.gcube.portlets.user.workspace.server.property.PortalUrlGroupGatewayProperty;
import org.gcube.portlets.user.workspace.server.util.WsUtil; import org.gcube.portlets.user.workspace.server.util.WsUtil;
import org.gcube.portlets.user.workspace.shared.HandlerResultMessage; import org.gcube.portlets.user.workspace.shared.HandlerResultMessage;
import org.gcube.portlets.user.workspace.shared.SessionExpiredException; 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 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"); boolean urlRedirectOnError = req.getParameter(ConstantsExplorer.REDIRECTONERROR)==null?false:req.getParameter(ConstantsExplorer.REDIRECTONERROR).equals("true");
String contextID = req.getParameter(ConstantsExplorer.CURRENT_CONTEXT_ID); 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()){ if(itemId==null || itemId.isEmpty()){
sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Item id is null"); sendError(resp,HttpServletResponse.SC_INTERNAL_SERVER_ERROR +": Item id is null");
return; return;
} }
logger.debug("FILE DOWNLOAD REQUEST "+itemId); logger.debug("FILE DOWNLOAD REQUEST "+itemId);
Workspace wa = null; Workspace wa = null;
try { try {
@ -90,7 +93,11 @@ public class DownloadServlet extends HttpServlet{
// if(WsUtil.isSessionExpired(req)) // if(WsUtil.isSessionExpired(req))
// throw new SessionExpiredException(); // 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) { } catch (Exception e) {
if (e instanceof SessionExpiredException){ if (e instanceof SessionExpiredException){

View File

@ -272,8 +272,8 @@ public class GWTWorkspaceBuilder {
sb.append(requestType.toString()); sb.append(requestType.toString());
sb.append("&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"="); sb.append("&"+ConstantsExplorer.CURRENT_CONTEXT_ID+"=");
sb.append(currentGroupId); sb.append(currentGroupId);
sb.append("&"+ConstantsExplorer.CURRENT_USER_ID+"="); // sb.append("&"+ConstantsExplorer.CURRENT_USER_ID+"=");
sb.append(currUserId); // sb.append(currUserId);
sb.append("&random="); sb.append("&random=");
sb.append(UUID.randomUUID().toString()); sb.append(UUID.randomUUID().toString());
return sb.toString(); return sb.toString();

View File

@ -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.exceptions.ItemNotFoundException;
import org.gcube.common.homelibrary.home.workspace.folder.FolderItem; import org.gcube.common.homelibrary.home.workspace.folder.FolderItem;
import org.gcube.common.homelibrary.home.workspace.folder.items.Image; 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.ConstantsExplorer;
import org.gcube.portlets.user.workspace.client.util.ImageRequestType; import org.gcube.portlets.user.workspace.client.util.ImageRequestType;
import org.gcube.portlets.user.workspace.server.util.WsUtil; 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 imageId = req.getParameter("id");
String imageType = req.getParameter("type"); String imageType = req.getParameter("type");
String contextID = req.getParameter(ConstantsExplorer.CURRENT_CONTEXT_ID); 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); 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; requestType = ImageRequestType.IMAGE;
} else requestType = ImageRequestType.valueOf(imageType); } else requestType = ImageRequestType.valueOf(imageType);
Workspace wa = null; Workspace wa = null;
try { 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) { } 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); logger.error("Error during workspace retrieving", e);
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Error during workspace retrieving"); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Error during workspace retrieving");
return; return;

View File

@ -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.resolver.UriResolverReaderParameterForResolverIndex.RESOLVER_TYPE;
import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader; import org.gcube.portlets.user.workspace.server.util.resource.PropertySpecialFolderReader;
import org.gcube.portlets.user.workspace.server.util.scope.ScopeUtilFilter; 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 org.gcube.vomanagement.usermanagement.model.GCubeUser;
import com.liferay.portal.service.UserLocalServiceUtil; import com.liferay.portal.service.UserLocalServiceUtil;
@ -120,8 +119,7 @@ public class WsUtil {
*/ */
public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception { public static boolean isSessionExpired(HttpServletRequest httpServletRequest) throws Exception {
logger.trace("workspace session validating..."); logger.trace("workspace session validating...");
PortalContextInfo info = getPortalContext(httpServletRequest); return PortalContext.getConfiguration().getCurrentUser(httpServletRequest)==null;
return info.getUsername()==null;
} }
@ -148,21 +146,20 @@ public class WsUtil {
} }
/** /**
* Gets the workspace. * Gets the workspace.
* *
* @param httpServletRequest the http servlet request * @param httpServletRequest the http servlet request
* @param contextID the context id * @param contextID the context id
* @param currUserId the curr user id * @param user the user
* @return the workspace * @return the workspace
* @throws InternalErrorException the internal error exception * @throws InternalErrorException the internal error exception
* @throws HomeNotFoundException the home not found exception * @throws HomeNotFoundException the home not found exception
* @throws WorkspaceFolderNotFoundException the workspace folder 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); String currentScope = PortalContext.getConfiguration().getCurrentScope(contextID);
logger.info("For ContextID: "+contextID +", read scope from Portal Context: "+currentScope); logger.info("For ContextID: "+contextID +", read scope from Portal Context: "+currentScope);
PortalContextInfo info = getPortalContext(httpServletRequest, currentScope); PortalContextInfo info = getPortalContext(httpServletRequest, currentScope);
@ -173,21 +170,17 @@ public class WsUtil {
String username = null; String username = null;
try { try {
GCubeUser gCubeUser = new LiferayUserManager().getUserById(Long.valueOf(currUserId)); if(user.getUsername().compareTo(info.getUsername())!=0){
logger.debug("Gcube user read from liferay: "+gCubeUser); logger.debug("Gcube user read from Portal Context "+user.getUsername()+" is different by GCubeUser passed, using the second one: "+info.getUsername());
if(gCubeUser!=null && gCubeUser.getUsername()!=null) username = user.getUsername();
username = gCubeUser.getUsername(); }
} catch (Exception e) { } catch (Exception e) {
String error = "Error retrieving gCubeUser for: [userId= " logger.error("Error comparing username read from input parameter and Portal context");
+ currUserId + ", scope: " + currentScope + "]";
logger.error(error, e);
} }
if(username==null || username.isEmpty()) if(username!=null)
username = PortalContext.getConfiguration().getCurrentUser(httpServletRequest).getUsername(); info.setUsername(username);
//overriding username
info.setUsername(username);
Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername()); Workspace workspace = HomeLibrary.getUserWorkspace(info.getUsername());
return workspace; return workspace;