Search in sources :

Example 41 with ForbiddenException

use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.

the class ExtensionCasesTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    new File(root, "/project1").mkdir();
    List<ProjectConfig> projects = new ArrayList<>();
    projects.add(DtoFactory.newDto(ProjectConfigDto.class).withPath("/project1").withName("project1Name").withType("primary1"));
    workspaceHolder = new TestWorkspaceHolder(projects);
    ProjectTypeRegistry projectTypeRegistry = new ProjectTypeRegistry(new HashSet<>());
    projectTypeRegistry.registerProjectType(new PT1());
    //projectTypeRegistry.registerProjectType(new PT3());
    //ProjectHandlerRegistry projectHandlerRegistry = new ProjectHandlerRegistry(new HashSet<>());
    projectRegistry = new ProjectRegistry(workspaceHolder, vfsProvider, projectTypeRegistry, projectHandlerRegistry, eventService);
    projectRegistry.initProjects();
    pm = new ProjectManager(vfsProvider, projectTypeRegistry, projectRegistry, projectHandlerRegistry, null, fileWatcherNotificationHandler, fileTreeWatcher, workspaceHolder, fileWatcherManager);
    pm.initWatcher();
    projectHandlerRegistry.register(new ProjectInitHandler() {

        @Override
        public void onProjectInitialized(ProjectRegistry registry, FolderEntry projectFolder) throws ServerException, NotFoundException, ConflictException, ForbiddenException {
            projectFolder.createFile("generated", "test".getBytes());
            projectFolder.createFolder("project2");
            projectRegistry.setProjectType("/project1/project2", BaseProjectType.ID, false);
        //System.out.println(">>S>>> "+projectRegistry);
        }

        @Override
        public String getProjectType() {
            return "primary1";
        }
    });
}
Also used : ProjectTypeRegistry(org.eclipse.che.api.project.server.type.ProjectTypeRegistry) ProjectInitHandler(org.eclipse.che.api.project.server.handlers.ProjectInitHandler) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) ArrayList(java.util.ArrayList) NotFoundException(org.eclipse.che.api.core.NotFoundException) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) File(java.io.File) Before(org.junit.Before)

Example 42 with ForbiddenException

use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.

the class TarArchiverTest method failsExtractArchiveToFolderWhenItContainsLockedFile.

@Test
public void failsExtractArchiveToFolderWhenItContainsLockedFile() throws Exception {
    byte[] archive = createTestTarArchive();
    VirtualFile folder = vfsRoot.createFolder("folder");
    VirtualFile arc = folder.createFolder("arc");
    VirtualFile lockedFile = arc.createFolder("a").createFile("_a.txt", "xxx");
    lockedFile.lock(0);
    try {
        new TarArchiver(folder).extract(new ByteArrayInputStream(archive), true, 0);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException expected) {
        assertEquals("xxx", lockedFile.getContentAsString());
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 43 with ForbiddenException

use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.

the class ZipArchiverTest method failsExtractArchiveToFolderWhenItContainsLockedFile.

@Test
public void failsExtractArchiveToFolderWhenItContainsLockedFile() throws Exception {
    byte[] archive = createTestZipArchive();
    VirtualFile folder = vfsRoot.createFolder("folder");
    VirtualFile arc = folder.createFolder("arc");
    VirtualFile lockedFile = arc.createFolder("a").createFile("_a.txt", "xxx");
    lockedFile.lock(0);
    try {
        new ZipArchiver(folder).extract(new ByteArrayInputStream(archive), true, 0);
        thrown.expect(ForbiddenException.class);
    } catch (ForbiddenException expected) {
        assertEquals("xxx", lockedFile.getContentAsString());
    }
}
Also used : ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.Test)

Example 44 with ForbiddenException

use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.

the class ProjectService method uploadZip.

private static Response uploadZip(VirtualFile parent, Iterator<FileItem> formData) throws ForbiddenException, ConflictException, ServerException {
    try {
        FileItem contentItem = null;
        boolean overwrite = false;
        boolean skipFirstLevel = false;
        while (formData.hasNext()) {
            FileItem item = formData.next();
            if (!item.isFormField()) {
                if (contentItem == null) {
                    contentItem = item;
                } else {
                    throw new ServerException("More then one upload file is found but only one should be. ");
                }
            } else if ("overwrite".equals(item.getFieldName())) {
                overwrite = Boolean.parseBoolean(item.getString().trim());
            } else if ("skipFirstLevel".equals(item.getFieldName())) {
                skipFirstLevel = Boolean.parseBoolean(item.getString().trim());
            }
        }
        if (contentItem == null) {
            throw new ServerException("Cannot find file for upload. ");
        }
        try {
            importZip(parent, contentItem.getInputStream(), overwrite, skipFirstLevel);
        } catch (IOException ioe) {
            throw new ServerException(ioe.getMessage(), ioe);
        }
        return Response.ok("", MediaType.TEXT_HTML).build();
    } catch (ForbiddenException | ConflictException | ServerException e) {
        HtmlErrorFormatter.sendErrorAsHTML(e);
        // never thrown
        throw e;
    }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) IOException(java.io.IOException)

Example 45 with ForbiddenException

use of org.eclipse.che.api.core.ForbiddenException in project che by eclipse.

the class LocalVirtualFileSystem method createFolder.

LocalVirtualFile createFolder(LocalVirtualFile parent, String name) throws ForbiddenException, ConflictException, ServerException {
    checkName(name);
    if (parent.isFolder()) {
        final Path newPath = parent.getPath().newPath(name);
        final File newIoFile = new File(ioRoot, toIoPath(newPath));
        if (!newIoFile.mkdirs()) {
            if (newIoFile.exists()) {
                throw new ConflictException(String.format("Item '%s' already exists", newPath));
            }
        }
        return new LocalVirtualFile(newIoFile, newPath, this);
    } else {
        throw new ForbiddenException("Unable create folder. Item specified as parent is not a folder");
    }
}
Also used : Path(org.eclipse.che.api.vfs.Path) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ConflictException(org.eclipse.che.api.core.ConflictException) VirtualFile(org.eclipse.che.api.vfs.VirtualFile) File(java.io.File)

Aggregations

ForbiddenException (org.eclipse.che.api.core.ForbiddenException)88 VirtualFile (org.eclipse.che.api.vfs.VirtualFile)54 Test (org.junit.Test)44 ServerException (org.eclipse.che.api.core.ServerException)33 Path (org.eclipse.che.api.vfs.Path)29 ConflictException (org.eclipse.che.api.core.ConflictException)25 IOException (java.io.IOException)13 NotFoundException (org.eclipse.che.api.core.NotFoundException)12 File (java.io.File)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 List (java.util.List)6 BadRequestException (org.eclipse.che.api.core.BadRequestException)6 VirtualFileEntry (org.eclipse.che.api.project.server.VirtualFileEntry)6 LockedFileFinder (org.eclipse.che.api.vfs.LockedFileFinder)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiParam (io.swagger.annotations.ApiParam)3 ApiResponse (io.swagger.annotations.ApiResponse)3 ApiResponses (io.swagger.annotations.ApiResponses)3