use of org.pentaho.platform.repository2.unified.jcr.JcrRepositoryDumpToFile in project pentaho-platform by pentaho.
the class MetadataRepositoryLifecycleManagerIT method testDoNewTenant.
@Test
public void testDoNewTenant() throws Exception {
loginAsRepositoryAdmin();
ITenant systemTenant = tenantManager.createTenant(null, ServerRepositoryPaths.getPentahoRootFolderName(), adminAuthorityName, tenantAuthenticatedAuthorityName, "Anonymous");
userRoleDao.createUser(systemTenant, sysAdminUserName, "password", "", new String[] { adminAuthorityName });
ITenant mainTenant_1 = tenantManager.createTenant(systemTenant, MAIN_TENANT_1, adminAuthorityName, tenantAuthenticatedAuthorityName, "Anonymous");
userRoleDao.createUser(mainTenant_1, "admin", "password", "", new String[] { adminAuthorityName, tenantAuthenticatedAuthorityName });
login("admin", mainTenant_1, new String[] { adminAuthorityName, tenantAuthenticatedAuthorityName });
JcrRepositoryDumpToFile dumpToFile = new JcrRepositoryDumpToFile(testJcrTemplate, jcrTransactionTemplate, repositoryAdminUsername, "c:/build/testrepo_3", Mode.CUSTOM);
dumpToFile.execute();
metadataRepositoryLifecycleManager.newTenant(mainTenant_1);
String metadataPath = ClientRepositoryPaths.getEtcFolderPath() + "/metadata";
RepositoryFile metadataRepositoryPath = repo.getFile(metadataPath);
assertTrue(metadataRepositoryPath.getPath() != null);
// Nothing should change if we run it again
metadataRepositoryLifecycleManager.newTenant(mainTenant_1);
metadataPath = ClientRepositoryPaths.getEtcFolderPath() + "/metadata";
metadataRepositoryPath = repo.getFile(metadataPath);
assertTrue(metadataRepositoryPath.getPath() != null);
cleanupUserAndRoles(mainTenant_1);
cleanupUserAndRoles(systemTenant);
}
use of org.pentaho.platform.repository2.unified.jcr.JcrRepositoryDumpToFile in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryAuthorizationIT method testGetFileAccessDenied.
@Test
public void testGetFileAccessDenied() 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 });
ITenant tenantDuff = tenantManager.createTenant(systemTenant, TENANT_ID_DUFF, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantDuff, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
userRoleDao.createUser(tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null);
login(USERNAME_ADMIN, tenantDuff, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
userRoleDao.createUser(tenantDuff, USERNAME_PAT, PASSWORD, "", null);
login(USERNAME_TIFFANY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile tiffanyHomeFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_TIFFANY));
assertNotNull(tiffanyHomeFolder);
assertNotNull(repo.createFolder(tiffanyHomeFolder.getId(), new RepositoryFile.Builder("test").folder(true).build(), null));
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
final String acmeTenantRootFolderPath = ClientRepositoryPaths.getRootFolderPath();
final String homeFolderPath = ClientRepositoryPaths.getHomeFolderPath();
final String tiffanyFolderPath = homeFolderPath + "/" + USERNAME_TIFFANY;
JcrRepositoryDumpToFile dumpToFile = new JcrRepositoryDumpToFile(testJcrTemplate, jcrTransactionTemplate, repositoryAdminUsername, "c:/build/testrepo_7", JcrRepositoryDumpToFile.Mode.CUSTOM);
// dumpToFile.execute();
// read access for suzy on home
assertNotNull(repo.getFile(homeFolderPath));
// no read access for suzy on tiffany's folder
assertNull(repo.getFile(tiffanyFolderPath));
// no read access for suzy on subfolder of tiffany's folder
final String tiffanySubFolderPath = tiffanyFolderPath + "/test";
assertNull(repo.getFile(tiffanySubFolderPath));
// make sure Pat can't see acme folder (pat is in the duff tenant)
login(USERNAME_PAT, tenantDuff, new String[] { tenantAuthenticatedRoleName });
assertNull(SimpleJcrTestUtils.getItem(testJcrTemplate, ServerRepositoryPaths.getTenantRootFolderPath(tenantAcme)));
assertFalse(SimpleJcrTestUtils.hasPrivileges(testJcrTemplate, ServerRepositoryPaths.getTenantRootFolderPath(tenantAcme), Privilege.JCR_READ));
assertFalse(SimpleJcrTestUtils.hasPrivileges(testJcrTemplate, ServerRepositoryPaths.getTenantRootFolderPath(tenantAcme), Privilege.JCR_READ_ACCESS_CONTROL));
}
use of org.pentaho.platform.repository2.unified.jcr.JcrRepositoryDumpToFile in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryAuthorizationIT method testAdminCreate.
@Test
public void testAdminCreate() 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 });
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
final String expectedName = "helloworld.sample";
final String sampleString = "Ciao World!";
final boolean sampleBoolean = true;
final int sampleInteger = 99;
final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
RepositoryFile newFile = createSampleFile(parentFolderPath, expectedName, sampleString, sampleBoolean, sampleInteger);
RepositoryFileAcl acls = repo.getAcl(newFile.getId());
RepositoryFileAcl.Builder newAclBuilder = new RepositoryFileAcl.Builder(acls);
newAclBuilder.entriesInheriting(false).ace(userNameUtils.getPrincipleId(tenantAcme, USERNAME_SUZY), RepositoryFileSid.Type.USER, RepositoryFilePermission.ALL);
repo.updateAcl(newAclBuilder.build());
// newFile = repo.getFile(newFile.getPath());
JcrRepositoryDumpToFile dumpToFile = new JcrRepositoryDumpToFile(testJcrTemplate, jcrTransactionTemplate, repositoryAdminUsername, "dumpTestAdminCreate", JcrRepositoryDumpToFile.Mode.CUSTOM);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
try {
repo.deleteFile(newFile.getId(), null);
} finally {
dumpToFile.execute();
}
}
use of org.pentaho.platform.repository2.unified.jcr.JcrRepositoryDumpToFile 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.repository2.unified.jcr.JcrRepositoryDumpToFile in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryJaxwsWebServiceIT method testEverything.
@Test
public void testEverything() throws Exception {
login(sysAdminUserName, systemTenant, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", new String[] { tenantAdminRoleName });
logout();
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
logger.info("getFile");
JcrRepositoryDumpToFile dumpToFile = new JcrRepositoryDumpToFile(testJcrTemplate, jcrTransactionTemplate, repositoryAdminUsername, "c:/build/testrepo_9", Mode.CUSTOM);
dumpToFile.execute();
RepositoryFile f = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY));
assertNotNull(f.getId());
assertEquals(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY), f.getPath());
assertNotNull(f.getCreatedDate());
assertEquals(USERNAME_SUZY, f.getName());
assertTrue(f.isFolder());
logger.info("getFileById");
assertNotNull(repo.getFileById(f.getId()));
logger.info("createFolder");
RepositoryFile folder1 = repo.createFolder(f.getId(), new RepositoryFile.Builder("folder1").folder(true).build(), null);
assertNotNull(folder1);
assertEquals("folder1", folder1.getName());
assertNotNull(folder1.getId());
NodeRepositoryFileData data = makeNodeRepositoryFileData1();
logger.info("createFile");
RepositoryFile file1 = repo.createFile(folder1.getId(), new RepositoryFile.Builder("file1.whatever").versioned(true).build(), data, null);
assertNotNull(file1);
assertNotNull(file1.getId());
logger.info("getDataForRead");
NodeRepositoryFileData file1Data = repo.getDataForRead(file1.getId(), NodeRepositoryFileData.class);
assertNotNull(file1Data);
assertEquals("testNode", file1Data.getNode().getName());
assertEquals("hello world", file1Data.getNode().getProperty("prop1").getString());
assertEquals(false, file1Data.getNode().getProperty("prop2").getBoolean());
assertEquals(DataPropertyType.BOOLEAN, file1Data.getNode().getProperty("prop2").getType());
assertEquals(12L, file1Data.getNode().getProperty("prop3").getLong());
logger.info("createFile (binary)");
SimpleRepositoryFileData simpleData = new SimpleRepositoryFileData(new ByteArrayInputStream("Hello World!".getBytes("UTF-8")), "UTF-8", "text/plain");
RepositoryFile simpleFile = repo.createFile(folder1.getId(), new RepositoryFile.Builder("file2.whatever").versioned(true).build(), simpleData, null);
Serializable simpleVersion = simpleFile.getVersionId();
logger.info("getDataForRead (binary)");
SimpleRepositoryFileData simpleFileData = repo.getDataForRead(simpleFile.getId(), SimpleRepositoryFileData.class);
assertNotNull(simpleFileData);
assertEquals("Hello World!", IOUtils.toString(simpleFileData.getInputStream(), simpleFileData.getEncoding()));
assertEquals("text/plain", simpleFileData.getMimeType());
assertEquals("UTF-8", simpleFileData.getEncoding());
logger.info("updateFile (binary)");
simpleData = new SimpleRepositoryFileData(new ByteArrayInputStream("Ciao World!".getBytes("UTF-8")), "UTF-8", "text/plain");
simpleFile = repo.updateFile(simpleFile, simpleData, null);
assertNotNull(simpleFile.getLastModifiedDate());
logger.info("getDataForRead (binary)");
simpleFileData = repo.getDataForRead(simpleFile.getId(), SimpleRepositoryFileData.class);
assertNotNull(simpleFileData);
assertEquals("Ciao World!", IOUtils.toString(simpleFileData.getInputStream(), simpleFileData.getEncoding()));
logger.info("getDataForReadAtVersion (binary)");
simpleFileData = repo.getDataAtVersionForRead(simpleFile.getId(), simpleVersion, SimpleRepositoryFileData.class);
assertNotNull(simpleFileData);
assertEquals("Hello World!", IOUtils.toString(simpleFileData.getInputStream(), simpleFileData.getEncoding()));
logger.info("getChildren");
List<RepositoryFile> folder1Children = repo.getChildren(new RepositoryRequest(String.valueOf(folder1.getId()), true, -1, null));
assertNotNull(folder1Children);
assertEquals(2, folder1Children.size());
logger.info("getChildren");
List<RepositoryFile> folder1ChildrenFiltered = repo.getChildren(new RepositoryRequest(String.valueOf(folder1.getId()), true, -1, "*.sample"));
assertNotNull(folder1ChildrenFiltered);
assertEquals(0, folder1ChildrenFiltered.size());
logger.info("getDeletedFiles");
assertEquals(0, repo.getDeletedFiles().size());
logger.info("deleteFile");
repo.deleteFile(file1.getId(), null);
logger.info("getDeletedFiles");
assertEquals(0, repo.getDeletedFiles(folder1.getPath(), "*.sample").size());
logger.info("hasAccess");
assertFalse(repo.hasAccess("/pentaho", EnumSet.of(RepositoryFilePermission.WRITE)));
logger.info("getEffectiveAces");
List<RepositoryFileAce> folder1EffectiveAces = repo.getEffectiveAces(folder1.getId());
assertEquals(1, folder1EffectiveAces.size());
logger.info("getAcl");
RepositoryFileAcl folder1Acl = repo.getAcl(folder1.getId());
assertEquals(USERNAME_SUZY, folder1Acl.getOwner().getName());
logger.info("updateAcl");
userRoleDao.createUser(tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null);
RepositoryFileAcl updatedFolder1Acl = repo.updateAcl(new RepositoryFileAcl.Builder(folder1Acl).entriesInheriting(false).ace(userNameUtils.getPrincipleId(tenantAcme, USERNAME_TIFFANY), RepositoryFileSid.Type.USER, RepositoryFilePermission.ALL).build());
assertNotNull(updatedFolder1Acl);
assertEquals(1, updatedFolder1Acl.getAces().size());
logger.info("lockFile");
assertFalse(file1.isLocked());
repo.lockFile(file1.getId(), "I locked this file");
logger.info("canUnlockFile");
assertTrue(repo.canUnlockFile(file1.getId()));
logger.info("unlockFile");
repo.unlockFile(file1.getId());
logger.info("moveFile");
repo.moveFile(file1.getId(), ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/folder1", null);
logger.info("copyFile");
repo.copyFile(file1.getId(), ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/folder1/fileB.whatever", null);
RepositoryFile copiedFile = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + "/folder1/fileB.whatever");
copiedFile = repo.updateFile(copiedFile, data, null);
logger.info("getVersionSummaries");
List<VersionSummary> versionSummaries = repo.getVersionSummaries(file1.getId());
assertNotNull(versionSummaries);
// copy doesn't increase version number
assertTrue(versionSummaries.size() >= 1);
assertEquals(USERNAME_SUZY, versionSummaries.get(0).getAuthor());
logger.info("getVersionSummary");
VersionSummary versionSummary = repo.getVersionSummary(file1.getId(), null);
assertNotNull(versionSummary);
assertNotNull(versionSummary.getId());
logger.info("getFileAtVersion");
RepositoryFile file1AtVersion = repo.getFileAtVersion(file1.getId(), versionSummary.getId());
assertNotNull(file1AtVersion);
assertEquals(versionSummary.getId(), file1AtVersion.getVersionId());
logger.info("getTree");
RepositoryFileTree tree = repo.getTree(new RepositoryRequest(ClientRepositoryPaths.getRootFolderPath(), true, -1, null));
assertNotNull(tree.getFile().getId());
logger.info("getDataForReadInBatch");
List<NodeRepositoryFileData> result = repo.getDataForReadInBatch(Arrays.asList(file1, copiedFile), NodeRepositoryFileData.class);
assertEquals(2, result.size());
logger.info("getVersionSummaryInBatch");
List<VersionSummary> vResult = repo.getVersionSummaryInBatch(Arrays.asList(file1, simpleFile));
assertEquals(2, vResult.size());
logger.info("getReservedChars");
assertFalse(repo.getReservedChars().isEmpty());
}
Aggregations