Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 382147
Collapse All | Expand All

(-)a/bundles/org.eclipse.orion.server.git/src/org/eclipse/orion/server/git/servlets/GitCloneHandlerV1.java (-52 / +3 lines)
Lines 30-36 import org.eclipse.jgit.util.FileUtils; Link Here
30
import org.eclipse.orion.internal.server.servlets.*;
30
import org.eclipse.orion.internal.server.servlets.*;
31
import org.eclipse.orion.internal.server.servlets.task.TaskJobHandler;
31
import org.eclipse.orion.internal.server.servlets.task.TaskJobHandler;
32
import org.eclipse.orion.internal.server.servlets.workspace.*;
32
import org.eclipse.orion.internal.server.servlets.workspace.*;
33
import org.eclipse.orion.internal.server.servlets.workspace.authorization.AuthorizationService;
34
import org.eclipse.orion.server.core.LogHelper;
33
import org.eclipse.orion.server.core.LogHelper;
35
import org.eclipse.orion.server.core.ServerStatus;
34
import org.eclipse.orion.server.core.ServerStatus;
36
import org.eclipse.orion.server.git.GitConstants;
35
import org.eclipse.orion.server.git.GitConstants;
Lines 154-177 public class GitCloneHandlerV1 extends ServletResourceHandler<String> { Link Here
154
				// should not happen, we do not allow linking at this point
153
				// should not happen, we do not allow linking at this point
155
			}
154
			}
156
			WebWorkspace workspace = WebWorkspace.fromId(path.segment(1));
155
			WebWorkspace workspace = WebWorkspace.fromId(path.segment(1));
157
			//If all went well, add project to workspace
158
			workspace.addProject(webProject);
159
156
160
			//save the workspace and project metadata
161
			try {
157
			try {
162
				webProject.save();
158
				//If all went well, add project to workspace
163
				workspace.save();
159
				WorkspaceResourceHandler.addProject(request.getRemoteUser(), workspace, webProject);
164
			} catch (CoreException e) {
160
			} catch (CoreException e) {
165
				return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error persisting project state", e));
161
				return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error persisting project state", e));
166
			}
162
			}
167
163
168
			URI baseLocation = getURI(request);
164
			URI baseLocation = getURI(request);
169
			baseLocation = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), workspacePath, baseLocation.getQuery(), baseLocation.getFragment());
165
			baseLocation = new URI(baseLocation.getScheme(), baseLocation.getUserInfo(), baseLocation.getHost(), baseLocation.getPort(), workspacePath, baseLocation.getQuery(), baseLocation.getFragment());
170
			JSONObject jsonProject = WebProjectResourceHandler.toJSON(webProject, baseLocation);
171
			// give the clone creator access rights to the new project
172
			addProjectRights(request, response, jsonProject.optString(ProtocolConstants.KEY_LOCATION));
173
			addProjectRights(request, response, jsonProject.optString(ProtocolConstants.KEY_CONTENT_LOCATION));
174
175
			clone.setId(webProject.getId());
166
			clone.setId(webProject.getId());
176
			clone.setContentLocation(webProject.getProjectStore().toURI());
167
			clone.setContentLocation(webProject.getProjectStore().toURI());
177
		}
168
		}
Lines 438-465 public class GitCloneHandlerV1 extends ServletResourceHandler<String> { Link Here
438
					JSONObject project = projectsJSON.getJSONObject(j);
429
					JSONObject project = projectsJSON.getJSONObject(j);
439
					String projectId = project.getString(ProtocolConstants.KEY_ID);
430
					String projectId = project.getString(ProtocolConstants.KEY_ID);
440
					if (projectId.equals(webProject.getId())) {
431
					if (projectId.equals(webProject.getId())) {
441
442
						//If found, remove project from workspace
432
						//If found, remove project from workspace
443
						webWorkspace.removeProject(webProject);
444
445
						// remove the project folder
446
						try {
433
						try {
447
							WorkspaceResourceHandler.removeProject(webProject, userName);
434
							WorkspaceResourceHandler.removeProject(userName, webWorkspace, webProject);
448
						} catch (CoreException e) {
435
						} catch (CoreException e) {
449
							//we are unable to write in the platform location!
436
							//we are unable to write in the platform location!
450
							String msg = NLS.bind("Server content location could not be written: {0}", Activator.getDefault().getRootLocationURI());
437
							String msg = NLS.bind("Server content location could not be written: {0}", Activator.getDefault().getRootLocationURI());
451
							return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
438
							return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
452
						}
439
						}
453
440
454
						//save the workspace and project metadata
455
						try {
456
							webProject.save();
457
							webWorkspace.save();
458
						} catch (CoreException e) {
459
							String msg = "Error persisting project state";
460
							return new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
461
						}
462
463
						return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null);
441
						return new ServerStatus(IStatus.OK, HttpServletResponse.SC_OK, null, null);
464
					}
442
					}
465
				}
443
				}
Lines 496-528 public class GitCloneHandlerV1 extends ServletResourceHandler<String> { Link Here
496
		return true;
474
		return true;
497
	}
475
	}
498
476
499
	/**
500
	 * It's a copy @see WorkspaceResourceHandler#addProjectRights().
501
	 * TODO: We can do better than that.
502
	 *
503
	 * @param request
504
	 * @param response
505
	 * @param location
506
	 * @throws ServletException
507
	 */
508
	private void addProjectRights(HttpServletRequest request, HttpServletResponse response, String location) throws ServletException {
509
		if (location == null)
510
			return;
511
		try {
512
			String locationPath = URI.create(location).getPath();
513
			//right to access the location
514
			AuthorizationService.addUserRight(request.getRemoteUser(), locationPath);
515
			//right to access all children of the location
516
			if (locationPath.endsWith("/")) //$NON-NLS-1$
517
				locationPath += "*"; //$NON-NLS-1$
518
			else
519
				locationPath += "/*"; //$NON-NLS-1$
520
			AuthorizationService.addUserRight(request.getRemoteUser(), locationPath);
521
		} catch (CoreException e) {
522
			statusHandler.handleRequest(request, response, e.getStatus());
523
		}
524
	}
525
526
	private boolean pull(HttpServletRequest request, HttpServletResponse response, GitCredentialsProvider cp, String path, boolean force) throws URISyntaxException, JSONException, IOException, ServletException {
477
	private boolean pull(HttpServletRequest request, HttpServletResponse response, GitCredentialsProvider cp, String path, boolean force) throws URISyntaxException, JSONException, IOException, ServletException {
527
		Path p = new Path(path); // /{file}/{path}
478
		Path p = new Path(path); // /{file}/{path}
528
		PullJob job = new PullJob(TaskJobHandler.getUserId(request), cp, p, force);
479
		PullJob job = new PullJob(TaskJobHandler.getUserId(request), cp, p, force);
(-)a/bundles/org.eclipse.orion.server.servlets/src/org/eclipse/orion/internal/server/servlets/workspace/WorkspaceResourceHandler.java (-61 / +45 lines)
Lines 140-183 public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks Link Here
140
140
141
	/**
141
	/**
142
	 * Adds the right for the user of the current request to access/modify the given location.
142
	 * Adds the right for the user of the current request to access/modify the given location.
143
	 * @throws CoreException 
143
	 */
144
	 */
144
	private void addProjectRights(HttpServletRequest request, HttpServletResponse response, String location) throws ServletException {
145
	private static void addProjectRights(String user, WebProject project) throws CoreException {
145
		if (location == null)
146
		String location = Activator.LOCATION_FILE_SERVLET + '/' + project.getId();
146
			return;
147
		//right to access the location
147
		try {
148
		AuthorizationService.addUserRight(user, location);
148
			String locationPath = URI.create(location).getPath();
149
		//right to access all children of the location
149
			//right to access the location
150
		AuthorizationService.addUserRight(user, location + "/*"); //$NON-NLS-1$
150
			AuthorizationService.addUserRight(request.getRemoteUser(), locationPath);
151
			//right to access all children of the location
152
			if (locationPath.endsWith("/")) //$NON-NLS-1$
153
				locationPath += "*"; //$NON-NLS-1$
154
			else
155
				locationPath += "/*"; //$NON-NLS-1$
156
			AuthorizationService.addUserRight(request.getRemoteUser(), locationPath);
157
		} catch (CoreException e) {
158
			statusHandler.handleRequest(request, response, e.getStatus());
159
		}
160
	}
151
	}
161
152
162
	/**
153
	/**
163
	 * Removes the right for the user of the current request to access/modify the given location.
154
	 * Removes the right for the user of the current request to access/modify the given location.
155
	 * @throws CoreException 
164
	 */
156
	 */
165
	private void removeProjectRights(HttpServletRequest request, HttpServletResponse response, String location) throws ServletException {
157
	private static void removeProjectRights(String user, WebProject project) throws CoreException {
166
		if (location == null)
158
		String location = Activator.LOCATION_FILE_SERVLET + '/' + project.getId();
167
			return;
159
		//right to access the location
168
		try {
160
		AuthorizationService.removeUserRight(user, location);
169
			String locationPath = URI.create(location).getPath();
161
		//right to access all children of the location
170
			//right to access the location
162
		AuthorizationService.removeUserRight(user, location + "/*"); //$NON-NLS-1$
171
			AuthorizationService.removeUserRight(request.getRemoteUser(), locationPath);
172
			//right to access all children of the location
173
			if (locationPath.endsWith("/")) //$NON-NLS-1$
174
				locationPath += "*"; //$NON-NLS-1$
175
			else
176
				locationPath += "/*"; //$NON-NLS-1$
177
			AuthorizationService.removeUserRight(request.getRemoteUser(), locationPath);
178
		} catch (CoreException e) {
179
			statusHandler.handleRequest(request, response, e.getStatus());
180
		}
181
	}
163
	}
182
164
183
	public static void computeProjectLocation(WebProject project, String location, String user, boolean init) throws URISyntaxException, CoreException {
165
	public static void computeProjectLocation(WebProject project, String location, String user, boolean init) throws URISyntaxException, CoreException {
Lines 295-302 public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks Link Here
295
		//If all went well, add project to workspace
277
		//If all went well, add project to workspace
296
		workspace.addProject(project);
278
		workspace.addProject(project);
297
279
298
		//save the workspace and project metadata
299
		try {
280
		try {
281
			// give the project creator access rights to the project
282
			addProjectRights(request.getRemoteUser(), project);
283
			//save the workspace and project metadata
300
			project.save();
284
			project.save();
301
			workspace.save();
285
			workspace.save();
302
		} catch (CoreException e) {
286
		} catch (CoreException e) {
Lines 314-321 public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks Link Here
314
		response.setHeader(ProtocolConstants.HEADER_LOCATION, result.optString(ProtocolConstants.KEY_LOCATION));
298
		response.setHeader(ProtocolConstants.HEADER_LOCATION, result.optString(ProtocolConstants.KEY_LOCATION));
315
		response.setStatus(HttpServletResponse.SC_CREATED);
299
		response.setStatus(HttpServletResponse.SC_CREATED);
316
300
317
		// give the project creator access rights to the project
318
		addProjectRights(request, response, result.optString(ProtocolConstants.KEY_CONTENT_LOCATION));
319
		return true;
301
		return true;
320
	}
302
	}
321
303
Lines 458-490 public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks Link Here
458
		}
440
		}
459
		WebProject project = WebProject.fromId(projectId);
441
		WebProject project = WebProject.fromId(projectId);
460
442
461
		//the baseLocation should be the workspace location
462
		//since deletion is on the project location we need to remove that suffix
463
		URI baseLocation = getURI(request).resolve("../../" + path.segment(0)); //$NON-NLS-1$
464
		JSONObject result = WebProjectResourceHandler.toJSON(project, baseLocation);
465
466
		// remove user rights for the project
467
		removeProjectRights(request, response, result.getString(ProtocolConstants.KEY_CONTENT_LOCATION));
468
469
		//If all went well, remove project from workspace
470
		workspace.removeProject(project);
471
472
		// remove the project folder
473
		try {
443
		try {
474
			removeProject(project, request.getRemoteUser());
444
			removeProject(request.getRemoteUser(), workspace, project);
475
		} catch (CoreException e) {
445
		} catch (CoreException e) {
476
			//we are unable to write in the platform location!
446
			ServerStatus error = new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error removing project", e);
477
			String msg = NLS.bind("Server content location could not be written: {0}", Activator.getDefault().getRootLocationURI());
447
			LogHelper.log(error);
478
			return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
448
			return statusHandler.handleRequest(request, response, error);
479
		}
480
481
		//save the workspace and project metadata
482
		try {
483
			project.save();
484
			workspace.save();
485
		} catch (CoreException e) {
486
			String msg = "Error persisting project state";
487
			return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e));
488
		}
449
		}
489
450
490
		return true;
451
		return true;
Lines 583-589 public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks Link Here
583
		return null;
544
		return null;
584
	}
545
	}
585
546
586
	public static void removeProject(WebProject project, String authority) throws CoreException {
547
	public static void addProject(String user, WebWorkspace workspace, WebProject project) throws CoreException {
548
		//add project to workspace
549
		workspace.addProject(project);
550
		// give the project creator access rights to the project
551
		addProjectRights(user, project);
552
		//save the workspace and project metadata
553
		project.save();
554
		workspace.save();
555
	}
556
557
	public static void removeProject(String user, WebWorkspace workspace, WebProject project) throws CoreException {
558
		// remove the project folder
587
		URI contentURI = project.getContentLocation();
559
		URI contentURI = project.getContentLocation();
588
560
589
		// don't remove linked projects
561
		// don't remove linked projects
Lines 596-602 public class WorkspaceResourceHandler extends WebElementResourceHandler<WebWorks Link Here
596
			}
568
			}
597
		}
569
		}
598
570
571
		// remove user rights for the project
572
		removeProjectRights(user, project);
573
574
		//If all went well, remove project from workspace
575
		workspace.removeProject(project);
576
577
		//remove project metadata
599
		project.remove();
578
		project.remove();
579
580
		//save the workspace and project metadata
581
		project.save();
582
		workspace.save();
583
600
	}
584
	}
601
585
602
	/**
586
	/**

Return to bug 382147