use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryAuthorizationIT method testDeleteWhenNoDeletePermissionOnFile.
/**
* Tests deleting a file when no delete permission is given to the role
*/
@Test
public void testDeleteWhenNoDeletePermissionOnFile() 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 });
defaultBackingRepositoryLifecycleManager.newTenant();
RepositoryFile publicFolderFile = createSampleFile(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName())).getPath(), "helloworld.sample", "ddfdf", false, 83);
RepositoryFileAcl publicFolderFileAcl = new RepositoryFileAcl.Builder(publicFolderFile.getId(), userNameUtils.getPrincipleId(tenantAcme, USERNAME_ADMIN), RepositoryFileSid.Type.USER).entriesInheriting(false).ace(new RepositoryFileSid(roleNameUtils.getPrincipleId(tenantAcme, tenantAuthenticatedRoleName), RepositoryFileSid.Type.ROLE), RepositoryFilePermission.READ, RepositoryFilePermission.WRITE).build();
repo.updateAcl(publicFolderFileAcl);
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", new String[] { tenantAuthenticatedRoleName });
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
try {
repo.deleteFile(publicFolderFile.getId(), null);
fail();
} catch (UnifiedRepositoryException e) {
assertNotNull(e);
}
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
try {
repo.deleteFile(publicFolderFile.getId(), null);
assertTrue(true);
} catch (UnifiedRepositoryException e) {
fail();
}
}
use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testMoveFile.
@Test
public void testMoveFile() 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);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
RepositoryFile moveTest1Folder = new RepositoryFile.Builder("moveTest1").folder(true).versioned(true).build();
moveTest1Folder = repo.createFolder(parentFolder.getId(), moveTest1Folder, null);
RepositoryFile moveTest2Folder = new RepositoryFile.Builder("moveTest2").folder(true).versioned(true).build();
moveTest2Folder = repo.createFolder(parentFolder.getId(), moveTest2Folder, null);
RepositoryFile testFolder = new RepositoryFile.Builder("test").folder(true).build();
testFolder = repo.createFolder(moveTest1Folder.getId(), testFolder, null);
// move folder into new folder
repo.moveFile(testFolder.getId(), moveTest2Folder.getPath() + RepositoryFile.SEPARATOR + testFolder.getName(), null);
assertNull(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "moveTest1" + RepositoryFile.SEPARATOR + "test"));
assertNotNull(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "moveTest2" + RepositoryFile.SEPARATOR + "test"));
// rename within same folder
repo.moveFile(testFolder.getId(), moveTest2Folder.getPath() + RepositoryFile.SEPARATOR + "newTest", null);
assertNull(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "moveTest2" + RepositoryFile.SEPARATOR + "test"));
assertNotNull(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "moveTest2" + RepositoryFile.SEPARATOR + "newTest"));
RepositoryFile newFile = createSampleFile(moveTest2Folder.getPath(), "helloworld.sample", "ddfdf", false, 83);
try {
repo.moveFile(testFolder.getId(), moveTest2Folder.getPath() + RepositoryFile.SEPARATOR + "doesnotexist" + RepositoryFile.SEPARATOR + "newTest2", null);
fail();
} catch (UnifiedRepositoryException e) {
// moving a folder to a path with a non-existent parent folder is illegal
}
try {
repo.moveFile(testFolder.getId(), newFile.getPath(), null);
fail();
} catch (UnifiedRepositoryException e) {
// moving a folder to a file is illegal
}
}
use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCopyFile.
@Test
public void testCopyFile() 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);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
RepositoryFile copyTest1Folder = new RepositoryFile.Builder("copyTest1").folder(true).versioned(true).build();
RepositoryFileSid fileOwnerSid = new RepositoryFileSid(userNameUtils.getPrincipleId(tenantAcme, USERNAME_SUZY));
copyTest1Folder = repo.createFolder(parentFolder.getId(), copyTest1Folder, new RepositoryFileAcl.Builder(fileOwnerSid).build(), null);
RepositoryFile copyTest2Folder = new RepositoryFile.Builder("copyTest2").folder(true).versioned(true).build();
copyTest2Folder = repo.createFolder(parentFolder.getId(), copyTest2Folder, new RepositoryFileAcl.Builder(fileOwnerSid).build(), null);
RepositoryFile testFolder = new RepositoryFile.Builder("test").folder(true).build();
testFolder = repo.createFolder(copyTest1Folder.getId(), testFolder, new RepositoryFileAcl.Builder(fileOwnerSid).build(), null);
// copy folder into new folder
repo.copyFile(testFolder.getId(), copyTest2Folder.getPath() + RepositoryFile.SEPARATOR + testFolder.getName(), null);
assertNotNull(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "copyTest1" + RepositoryFile.SEPARATOR + "test"));
assertNotNull(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "copyTest2" + RepositoryFile.SEPARATOR + "test"));
// copy folder into new folder and rename
repo.copyFile(testFolder.getId(), copyTest2Folder.getPath() + RepositoryFile.SEPARATOR + "newTest2", null);
assertNotNull(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "copyTest1" + RepositoryFile.SEPARATOR + "test"));
assertNotNull(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "copyTest2" + RepositoryFile.SEPARATOR + "newTest2"));
// copy within same folder
repo.copyFile(testFolder.getId(), copyTest2Folder.getPath() + RepositoryFile.SEPARATOR + "newTest", null);
assertNotNull(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "copyTest2" + RepositoryFile.SEPARATOR + "test"));
assertNotNull(repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "copyTest2" + RepositoryFile.SEPARATOR + "newTest"));
RepositoryFile newFile = createSampleFile(copyTest2Folder.getPath(), "helloworld.sample", "ddfdf", false, 83);
try {
repo.copyFile(testFolder.getId(), copyTest2Folder.getPath() + RepositoryFile.SEPARATOR + "doesnotexist" + RepositoryFile.SEPARATOR + "newTest2", null);
fail();
} catch (UnifiedRepositoryException e) {
// copying a folder to a path with a non-existent parent folder is illegal
}
try {
repo.copyFile(testFolder.getId(), newFile.getPath(), null);
fail();
} catch (UnifiedRepositoryException e) {
// copying a folder to a file is illegal
}
JcrRepositoryDumpToFile dumpToFile = new JcrRepositoryDumpToFile(testJcrTemplate, jcrTransactionTemplate, repositoryAdminUsername, "c:/build/testrepo_17", Mode.CUSTOM);
dumpToFile.execute();
}
use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtService method deleteDatasourceByName.
public void deleteDatasourceByName(String name) throws NonExistingDatasourceException, DatasourceMgmtServiceException {
RepositoryFile fileToDelete = null;
try {
fileToDelete = repository.getFile(getPath(name));
} catch (UnifiedRepositoryException ure) {
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0002_UNABLE_TO_DELETE_DATASOURCE", fileToDelete.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
ure);
}
deleteDatasource(fileToDelete);
}
use of org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException in project pentaho-platform by pentaho.
the class JcrBackedDatasourceMgmtService method getDatasources.
public List<IDatabaseConnection> getDatasources() throws DatasourceMgmtServiceException {
try {
List<IDatabaseConnection> datasourceList = new ArrayList<IDatabaseConnection>();
List<RepositoryFile> repositoryFiles = getRepositoryFiles();
if (repositoryFiles != null) {
for (RepositoryFile file : repositoryFiles) {
NodeRepositoryFileData data = repository.getDataForRead(file.getId(), NodeRepositoryFileData.class);
IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection(file.getId(), file.getTitle(), data.getNode());
// IPasswordService passwordService = PentahoSystem.get(IPasswordService.class,
// PentahoSessionHolder.getSession());
// databaseMeta.setPassword(passwordService.decrypt(databaseMeta.getPassword()));
datasourceList.add(databaseConnection);
}
}
return datasourceList;
// } catch(PasswordServiceException pse) {
// throw new DatasourceMgmtServiceException(Messages.getInstance()
// .getErrorString("DatasourceMgmtService.ERROR_0008_UNABLE_TO_DECRYPT_PASSWORD"), pse ); //$NON-NLS-1$
} catch (UnifiedRepositoryException ure) {
throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", ure.getLocalizedMessage()), // $NON-NLS-1$ //$NON-NLS-2$
ure);
}
}
Aggregations