use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class WorkspaceService method updateCommand.
@PUT
@Path("/{id}/command/{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Update the workspace command by replacing the command with a new one", notes = "This operation can be performed only by the workspace owner")
@ApiResponses({ @ApiResponse(code = 200, message = "The command successfully updated"), @ApiResponse(code = 400, message = "Missed required parameters, parameters are not valid"), @ApiResponse(code = 403, message = "The user does not have access to update the workspace"), @ApiResponse(code = 404, message = "The workspace or the command not found"), @ApiResponse(code = 409, message = "The Command with such name already exists"), @ApiResponse(code = 500, message = "Internal server error occurred") })
public WorkspaceDto updateCommand(@ApiParam("The workspace id") @PathParam("id") String id, @ApiParam("The name of the command") @PathParam("name") String cmdName, @ApiParam(value = "The command update", required = true) CommandDto update) throws ServerException, BadRequestException, NotFoundException, ConflictException, ForbiddenException {
requiredNotNull(update, "Command update");
final WorkspaceImpl workspace = workspaceManager.getWorkspace(id);
final List<CommandImpl> commands = workspace.getConfig().getCommands();
if (!commands.removeIf(cmd -> cmd.getName().equals(cmdName))) {
throw new NotFoundException(format("Workspace '%s' doesn't contain command '%s'", id, cmdName));
}
commands.add(new CommandImpl(update));
validator.validateConfig(workspace.getConfig());
return linksInjector.injectLinks(asDto(workspaceManager.updateWorkspace(workspace.getId(), workspace)), getServiceContext());
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class FactoryEditValidatorImpl method validate.
/**
* Validates given factory by checking the current user is granted to edit the factory
*
* @param factory
* factory object to validate
* @throws ForbiddenException
* occurs if the current user is not granted to edit the factory
* @throws ServerException
* when any server error occurs
*/
@Override
public void validate(Factory factory) throws ForbiddenException, ServerException {
// Checks if there is an author from the factory (It may be missing for some old factories)
final Author author = factory.getCreator();
if (author == null || author.getUserId() == null) {
throw new ServerException(format("Invalid factory without author stored. Please contact the support about the factory ID '%s'", factory.getId()));
}
// ensure user has the correct permissions
final String userId = EnvironmentContext.getCurrent().getSubject().getUserId();
if (!author.getUserId().equals(userId)) {
throw new ForbiddenException(format("You are not authorized for the factory '%s'", factory.getId()));
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest method failsLockFolder.
@Test
public void failsLockFolder() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
try {
folder.lock(0);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertFalse(folder.isLocked());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest method failsRenamesFolderWheItContainsLockedFile.
@Test
public void failsRenamesFolderWheItContainsLockedFile() throws Exception {
VirtualFile folder = getRoot().createFolder(generateFolderName());
VirtualFile lockedFile = folder.createFile(generateFileName(), DEFAULT_CONTENT);
lockedFile.lock(0);
Path renamedFolderPath = Path.of("/new_name");
try {
folder.rename("new_name");
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException e) {
assertNull(getRoot().getChild(renamedFolderPath.newPath(lockedFile.getName())));
assertNull(getRoot().getChild(renamedFolderPath));
assertNotNull(getRoot().getChild(folder.getPath()));
assertEquals(DEFAULT_CONTENT, lockedFile.getContentAsString());
assertTrue(lockedFile.isLocked());
}
}
use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.
the class MemoryVirtualFileTest method failsCreateFileWhenParenIsNotFolder.
@Test
public void failsCreateFileWhenParenIsNotFolder() throws Exception {
VirtualFile parent = getRoot().createFile("parent", "");
try {
parent.createFile("file", DEFAULT_CONTENT);
thrown.expect(ForbiddenException.class);
} catch (ForbiddenException expected) {
assertNull(getRoot().getChild(parent.getPath().newPath("file")));
}
}
Aggregations