|
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 |
/** |