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();
}
}
}
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());
}
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);
}
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
}
}
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();
}
}
Aggregations