Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 217105 Details for
Bug 382147
GitCloneHandlerV1 doesn't correctly add/remove project permissions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Fix
patch.txt (text/plain), 12.44 KB, created by
John Arthorne
on 2012-06-08 16:59:23 EDT
(
hide
)
Description:
Fix
Filename:
MIME Type:
Creator:
John Arthorne
Created:
2012-06-08 16:59:23 EDT
Size:
12.44 KB
patch
obsolete
>diff --git a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCloneHandlerV1.java b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCloneHandlerV1.java >index 53d97b5..1ada093 100644 >--- a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCloneHandlerV1.java >+++ b/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCloneHandlerV1.java >@@ -30,7 +30,6 @@ import org.eclipse.jgit.util.FileUtils; > import org.eclipse.orion.internal.server.servlets.*; > import org.eclipse.orion.internal.server.servlets.task.TaskJobHandler; > import org.eclipse.orion.internal.server.servlets.workspace.*; >-import org.eclipse.orion.internal.server.servlets.workspace.authorization.AuthorizationService; > import org.eclipse.orion.server.core.LogHelper; > import org.eclipse.orion.server.core.ServerStatus; > import org.eclipse.orion.server.git.GitConstants; >@@ -154,24 +153,16 @@ public class GitCloneHandlerV1 extends ServletResourceHandler<String> { > // should not happen, we do not allow linking at this point > } > WebWorkspace workspace = WebWorkspace.fromId(path.segment(1)); >- //If all went well, add project to workspace >- workspace.addProject(webProject); > >- //save the workspace and project metadata > try { >- webProject.save(); >- workspace.save(); >+ //If all went well, add project to workspace >+ WorkspaceResourceHandler.addProject(request.getRemoteUser(), workspace, webProject); > } catch (CoreException e) { > return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error persisting project state", e)); > } > > URI baseLocation = getURI(request); > baseLocation = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), workspacePath, baseLocation.getQuery(), baseLocation.getFragment()); >- JSONObject jsonProject = WebProjectResourceHandler.toJSON(webProject, baseLocation); >- // give the clone creator access rights to the new project >- addProjectRights(request, response, jsonProject.optString(ProtocolConstants.KEY_LOCATION)); >- addProjectRights(request, response, jsonProject.optString(ProtocolConstants.KEY_CONTENT_LOCATION)); >- > clone.setId(webProject.getId()); > clone.setContentLocation(webProject.getProjectStore().toURI()); > } >@@ -438,28 +429,15 @@ public class GitCloneHandlerV1 extends ServletResourceHandler<String> { > JSONObject project = projectsJSON.getJSONObject(j); > String projectId = project.getString(ProtocolConstants.KEY_ID); > if (projectId.equals(webProject.getId())) { >- > //If found, remove project from workspace >- webWorkspace.removeProject(webProject); >- >- // remove the project folder > try { >- WorkspaceResourceHandler.removeProject(webProject, userName); >+ WorkspaceResourceHandler.removeProject(userName, webWorkspace, webProject); > } catch (CoreException e) { > //we are unable to write in the platform location! > String msg = NLS.bind("Server content location could not be written: {0}", Activator.getDefault().getRootLocationURI()); > return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); > } > >- //save the workspace and project metadata >- try { >- webProject.save(); >- webWorkspace.save(); >- } catch (CoreException e) { >- String msg = "Error persisting project state"; >- return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e); >- } >- > return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null); > } > } >@@ -496,33 +474,6 @@ public class GitCloneHandlerV1 extends ServletResourceHandler<String> { > return true; > } > >- /** >- * It's a copy @see WorkspaceResourceHandler#addProjectRights(). >- * TODO: We can do better than that. >- * >- * @param request >- * @param response >- * @param location >- * @throws ServletException >- */ >- private void addProjectRights(HttpServletRequest request, HttpServletResponse response, String location) throws ServletException { >- if (location == null) >- return; >- try { >- String locationPath = URI.create(location).getPath(); >- //right to access the location >- AuthorizationService.addUserRight(request.getRemoteUser(), locationPath); >- //right to access all children of the location >- if (locationPath.endsWith("/")) //$NON-NLS-1$ >- locationPath += "*"; //$NON-NLS-1$ >- else >- locationPath += "/*"; //$NON-NLS-1$ >- AuthorizationService.addUserRight(request.getRemoteUser(), locationPath); >- } catch (CoreException e) { >- statusHandler.handleRequest(request, response, e.getStatus()); >- } >- } >- > private boolean pull(HttpServletRequest request, HttpServletResponse response, GitCredentialsProvider cp, String path, boolean force) throws URISyntaxException, JSONException, IOException, ServletException { > Path p = new Path(path); // /{file}/{path} > PullJob job = new PullJob(TaskJobHandler.getUserId(request), cp, p, force); >diff --git a/bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/workspace/WorkspaceResourceHandler.java b/bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/workspace/WorkspaceResourceHandler.java >index 1817641..6ded1fd 100644 >--- a/bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/workspace/WorkspaceResourceHandler.java >+++ b/bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/workspace/WorkspaceResourceHandler.java >@@ -140,44 +140,26 @@ public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks > > /** > * Adds the right for the user of the current request to access/modify the given location. >+ * @throws CoreException > */ >- private void addProjectRights(HttpServletRequest request, HttpServletResponse response, String location) throws ServletException { >- if (location == null) >- return; >- try { >- String locationPath = URI.create(location).getPath(); >- //right to access the location >- AuthorizationService.addUserRight(request.getRemoteUser(), locationPath); >- //right to access all children of the location >- if (locationPath.endsWith("/")) //$NON-NLS-1$ >- locationPath += "*"; //$NON-NLS-1$ >- else >- locationPath += "/*"; //$NON-NLS-1$ >- AuthorizationService.addUserRight(request.getRemoteUser(), locationPath); >- } catch (CoreException e) { >- statusHandler.handleRequest(request, response, e.getStatus()); >- } >+ private static void addProjectRights(String user, WebProject project) throws CoreException { >+ String location = Activator.LOCATION_FILE_SERVLET + '/' + project.getId(); >+ //right to access the location >+ AuthorizationService.addUserRight(user, location); >+ //right to access all children of the location >+ AuthorizationService.addUserRight(user, location + "/*"); //$NON-NLS-1$ > } > > /** > * Removes the right for the user of the current request to access/modify the given location. >+ * @throws CoreException > */ >- private void removeProjectRights(HttpServletRequest request, HttpServletResponse response, String location) throws ServletException { >- if (location == null) >- return; >- try { >- String locationPath = URI.create(location).getPath(); >- //right to access the location >- AuthorizationService.removeUserRight(request.getRemoteUser(), locationPath); >- //right to access all children of the location >- if (locationPath.endsWith("/")) //$NON-NLS-1$ >- locationPath += "*"; //$NON-NLS-1$ >- else >- locationPath += "/*"; //$NON-NLS-1$ >- AuthorizationService.removeUserRight(request.getRemoteUser(), locationPath); >- } catch (CoreException e) { >- statusHandler.handleRequest(request, response, e.getStatus()); >- } >+ private static void removeProjectRights(String user, WebProject project) throws CoreException { >+ String location = Activator.LOCATION_FILE_SERVLET + '/' + project.getId(); >+ //right to access the location >+ AuthorizationService.removeUserRight(user, location); >+ //right to access all children of the location >+ AuthorizationService.removeUserRight(user, location + "/*"); //$NON-NLS-1$ > } > > public static void computeProjectLocation(WebProject project, String location, String user, boolean init) throws URISyntaxException, CoreException { >@@ -295,8 +277,10 @@ public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks > //If all went well, add project to workspace > workspace.addProject(project); > >- //save the workspace and project metadata > try { >+ // give the project creator access rights to the project >+ addProjectRights(request.getRemoteUser(), project); >+ //save the workspace and project metadata > project.save(); > workspace.save(); > } catch (CoreException e) { >@@ -314,8 +298,6 @@ public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks > response.setHeader(ProtocolConstants.HEADER_LOCATION, result.optString(ProtocolConstants.KEY_LOCATION)); > response.setStatus(HttpServletResponse.SC_CREATED); > >- // give the project creator access rights to the project >- addProjectRights(request, response, result.optString(ProtocolConstants.KEY_CONTENT_LOCATION)); > return true; > } > >@@ -458,33 +440,12 @@ public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks > } > WebProject project = WebProject.fromId(projectId); > >- //the baseLocation should be the workspace location >- //since deletion is on the project location we need to remove that suffix >- URI baseLocation = getURI(request).resolve("../../" + path.segment(0)); //$NON-NLS-1$ >- JSONObject result = WebProjectResourceHandler.toJSON(project, baseLocation); >- >- // remove user rights for the project >- removeProjectRights(request, response, result.getString(ProtocolConstants.KEY_CONTENT_LOCATION)); >- >- //If all went well, remove project from workspace >- workspace.removeProject(project); >- >- // remove the project folder > try { >- removeProject(project, request.getRemoteUser()); >+ removeProject(request.getRemoteUser(), workspace, project); > } catch (CoreException e) { >- //we are unable to write in the platform location! >- String msg = NLS.bind("Server content location could not be written: {0}", Activator.getDefault().getRootLocationURI()); >- return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e)); >- } >- >- //save the workspace and project metadata >- try { >- project.save(); >- workspace.save(); >- } catch (CoreException e) { >- String msg = "Error persisting project state"; >- return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e)); >+ ServerStatus error = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error removing project", e); >+ LogHelper.log(error); >+ return statusHandler.handleRequest(request, response, error); > } > > return true; >@@ -583,7 +544,18 @@ public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks > return null; > } > >- public static void removeProject(WebProject project, String authority) throws CoreException { >+ public static void addProject(String user, WebWorkspace workspace, WebProject project) throws CoreException { >+ //add project to workspace >+ workspace.addProject(project); >+ // give the project creator access rights to the project >+ addProjectRights(user, project); >+ //save the workspace and project metadata >+ project.save(); >+ workspace.save(); >+ } >+ >+ public static void removeProject(String user, WebWorkspace workspace, WebProject project) throws CoreException { >+ // remove the project folder > URI contentURI = project.getContentLocation(); > > // don't remove linked projects >@@ -596,7 +568,19 @@ public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks > } > } > >+ // remove user rights for the project >+ removeProjectRights(user, project); >+ >+ //If all went well, remove project from workspace >+ workspace.removeProject(project); >+ >+ //remove project metadata > project.remove(); >+ >+ //save the workspace and project metadata >+ project.save(); >+ workspace.save(); >+ > } > > /**
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 382147
:
217097
| 217105