Search in sources :

Example 1 with UnifiedRepositoryAccessDeniedException

use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException in project pentaho-platform by pentaho.

the class PentahoPlatformImporter method importFile.

/**
 * this is the main method that uses the mime time (from Spring) to determine which handler to invoke.
 */
public void importFile(IPlatformImportBundle file) throws PlatformImportException {
    String mime = file.getMimeType() != null ? file.getMimeType() : mimeResolver.resolveMimeForBundle(file);
    try {
        if (mime == null) {
            log.trace(messages.getString("PentahoPlatformImporter.ERROR_0001_INVALID_MIME_TYPE") + file.getName());
            repositoryImportLogger.error(messages.getString("PentahoPlatformImporter.ERROR_0001_INVALID_MIME_TYPE") + file.getName());
            return;
        }
        IPlatformImportHandler handler = (importHandlers.containsKey(mime) == false) ? defaultHandler : importHandlers.get(mime);
        if (handler == null) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0002_MISSING_IMPORT_HANDLER"), PlatformImportException.PUBLISH_GENERAL_ERROR);
        // replace with default handler?
        }
        try {
            logImportFile(file);
            handler.importFile(file);
        } catch (DomainIdNullException e1) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0004_PUBLISH_TO_SERVER_FAILED"), PlatformImportException.PUBLISH_TO_SERVER_FAILED, e1);
        } catch (DomainAlreadyExistsException e1) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0007_PUBLISH_SCHEMA_EXISTS_ERROR"), PlatformImportException.PUBLISH_SCHEMA_EXISTS_ERROR, e1);
        } catch (DomainStorageException e1) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0004_PUBLISH_TO_SERVER_FAILED"), PlatformImportException.PUBLISH_DATASOURCE_ERROR, e1);
        } catch (IOException e1) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0005_PUBLISH_GENERAL_ERRORR", e1.getLocalizedMessage()), PlatformImportException.PUBLISH_GENERAL_ERROR, e1);
        } catch (PlatformImportException pe) {
            // if already converted - just rethrow
            throw pe;
        } catch (Exception e1) {
            throw new PlatformImportException(messages.getString("PentahoPlatformImporter.ERROR_0005_PUBLISH_GENERAL_ERRORR", e1.getLocalizedMessage()), PlatformImportException.PUBLISH_GENERAL_ERROR, e1);
        }
    } catch (Exception e) {
        e.printStackTrace();
        // If we are doing a logged import then we do not want to fail on a single file
        // so log the error and keep going.
        RepositoryFileImportBundle bundle = (RepositoryFileImportBundle) file;
        String repositoryFilePath = RepositoryFilenameUtils.concat(bundle.getPath(), bundle.getName());
        if (repositoryImportLogger.hasLogger() && repositoryFilePath != null && repositoryFilePath.length() > 0) {
            repositoryImportLogger.error(e);
        } else {
            if (e instanceof PlatformImportException) {
                throw (PlatformImportException) e;
            } else {
                // shouldn't happen but just in case
                throw new PlatformImportException(e.getMessage());
            }
        }
        if (e.getCause() instanceof UnifiedRepositoryAccessDeniedException) {
            throw new UnifiedRepositoryAccessDeniedException();
        }
    }
}
Also used : UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) IOException(java.io.IOException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)

Example 2 with UnifiedRepositoryAccessDeniedException

use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException in project pentaho-platform by pentaho.

the class FileResourceTest method testNoServerErrorCodeReturnedWhenUserHasNoWritePermissionsToFolder.

@Test
public void testNoServerErrorCodeReturnedWhenUserHasNoWritePermissionsToFolder() {
    UnifiedRepositoryAccessDeniedException mockedException = mock(UnifiedRepositoryAccessDeniedException.class);
    doThrow(mockedException).when(fileResource.fileService).doRestoreFiles(FILE_ID);
    doReturn("user/home").when(fileResource).getUserHomeFolder();
    doReturn(false).when(fileResource.fileService).canRestoreToFolderWithNoConflicts(anyString(), eq(FILE_ID));
    Response response = fileResource.doRestore(FILE_ID, null);
    assertNotEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
Also used : UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) Response(javax.ws.rs.core.Response) Test(org.junit.Test)

Example 3 with UnifiedRepositoryAccessDeniedException

use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException in project pentaho-platform by pentaho.

the class DefaultUnifiedRepository method updateAcl.

/**
 * {@inheritDoc}
 */
public RepositoryFileAcl updateAcl(final RepositoryFileAcl acl) {
    Assert.notNull(acl);
    RepositoryFile file = getFileById(acl.getId());
    List<RepositoryFilePermission> perms = new ArrayList<RepositoryFilePermission>();
    perms.add(RepositoryFilePermission.ACL_MANAGEMENT);
    if (!hasAccess(file.getPath(), EnumSet.copyOf(perms))) {
        throw new UnifiedRepositoryAccessDeniedException(Messages.getInstance().getString("DefaultUnifiedRepository.ERROR_0001_ACCESS_DENIED_UPDATE_ACL", acl.getId()));
    }
    return repositoryFileAclDao.updateAcl(acl);
}
Also used : UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) RepositoryFilePermission(org.pentaho.platform.api.repository2.unified.RepositoryFilePermission) ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 4 with UnifiedRepositoryAccessDeniedException

use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryContentIT method testWriteOnFileToMove.

@Test
public void testWriteOnFileToMove() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
    defaultBackingRepositoryLifecycleManager.newTenant();
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    RepositoryFile parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
    RepositoryFile srcFolder = new RepositoryFile.Builder("src").folder(true).build();
    RepositoryFile destFolder = new RepositoryFile.Builder("dest").folder(true).build();
    srcFolder = repo.createFolder(parentFolder.getId(), srcFolder, null);
    destFolder = repo.createFolder(parentFolder.getId(), destFolder, null);
    RepositoryFile newFile = createSampleFile(srcFolder.getPath(), "helloworld.sample", "ddfdf", false, 83);
    RepositoryFileAcl acl = new RepositoryFileAcl.Builder(newFile.getId(), userNameUtils.getPrincipleId(tenantAcme, USERNAME_TIFFANY), RepositoryFileSid.Type.USER).entriesInheriting(false).ace(userNameUtils.getPrincipleId(tenantAcme, USERNAME_SUZY), RepositoryFileSid.Type.USER, RepositoryFilePermission.READ).build();
    repo.updateAcl(acl);
    // moved; this should fail
    try {
        repo.moveFile(newFile.getId(), destFolder.getPath(), null);
        fail();
    } catch (UnifiedRepositoryAccessDeniedException e) {
    // ignore
    }
}
Also used : UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) Test(org.junit.Test)

Example 5 with UnifiedRepositoryAccessDeniedException

use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException in project pentaho-platform by pentaho.

the class FileService method doMoveFiles.

/**
 * Moves a list of files from its current location to another.
 * <p/>
 * Moves a list of files from its current location to another, the list should be comma separated.
 *
 * @param destPathId colon separated path for the repository file
 * <pre function="syntax.xml">
 *    :path:to:file:id
 * </pre>
 * @param params comma separated list of files to be moved
 * <pre function="syntax.xml">
 *    path1,path2,...
 * </pre>
 *
 * @return boolean <code>true</code>  if all files were moved correctly or <code>false</code> if the destiny path is
 * not available
 * @throws FileNotFoundException
 */
public void doMoveFiles(String destPathId, String params) throws FileNotFoundException {
    String idToPath = idToPath(destPathId);
    RepositoryFileDto repositoryFileDto = getRepoWs().getFile(idToPath);
    if (repositoryFileDto == null) {
        throw new FileNotFoundException(idToPath);
    }
    String[] sourceFileIds = FileUtils.convertCommaSeparatedStringToArray(params);
    int i = 0;
    try {
        for (; i < sourceFileIds.length; i++) {
            getRepoWs().moveFile(sourceFileIds[i], repositoryFileDto.getPath(), null);
        }
    } catch (IllegalArgumentException | UnifiedRepositoryAccessDeniedException e) {
        throw e;
    } catch (Exception e) {
        throw new InternalError();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) GeneralSecurityException(java.security.GeneralSecurityException) InvalidParameterException(java.security.InvalidParameterException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) UnifiedRepositoryAccessDeniedException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException) FileNotFoundException(java.io.FileNotFoundException) PlatformImportException(org.pentaho.platform.plugin.services.importer.PlatformImportException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ExportException(org.pentaho.platform.plugin.services.importexport.ExportException) IllegalSelectorException(java.nio.channels.IllegalSelectorException) IOException(java.io.IOException)

Aggregations

UnifiedRepositoryAccessDeniedException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryAccessDeniedException)6 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 IOException (java.io.IOException)2 Test (org.junit.Test)2 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)2 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)2 FileNotFoundException (java.io.FileNotFoundException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 IllegalSelectorException (java.nio.channels.IllegalSelectorException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 InvalidParameterException (java.security.InvalidParameterException)1 ArrayList (java.util.ArrayList)1 Response (javax.ws.rs.core.Response)1 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)1 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)1 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)1 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)1 ITenant (org.pentaho.platform.api.mt.ITenant)1 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)1 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)1