use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testCreateFileUnrecognizedContentType.
@Test(expected = UnifiedRepositoryException.class)
public void testCreateFileUnrecognizedContentType() 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(USERNAME_SUZY));
IRepositoryFileData content = new IRepositoryFileData() {
@Override
public long getDataSize() {
// TODO Auto-generated method stub
return 0;
}
};
repo.createFile(parentFolder.getId(), new RepositoryFile.Builder("helloworld.xaction").build(), content, null);
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testGetDataForReadInBatch_unversioned.
@Test
public void testGetDataForReadInBatch_unversioned() 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 });
final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
String sampleString1 = "sampleString1";
String sampleString2 = "sampleString2";
RepositoryFile newFile1 = createSampleFile(parentFolderPath, "helloworld.sample1", sampleString1, true, 1);
RepositoryFile newFile2 = createSampleFile(parentFolderPath, "file2", sampleString2, false, 2);
assertNotNull(newFile1.getId());
assertNull(newFile1.getVersionId());
assertNotNull(newFile2.getId());
assertNull(newFile2.getVersionId());
List<SampleRepositoryFileData> data = repo.getDataForReadInBatch(Arrays.asList(newFile1, newFile2), SampleRepositoryFileData.class);
assertEquals(2, data.size());
SampleRepositoryFileData d = data.get(0);
assertEquals(sampleString1, d.getSampleString());
d = data.get(1);
assertEquals(sampleString2, d.getSampleString());
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryContentIT method testMissingRef.
@Test
public void testMissingRef() throws Exception {
// if a user does not have permission to a reference, it is removed from the node structure and
// replaced with a missing link. previous releases would throw an exception.
// create a file that suzy does not have permission to
// create a file that suzy has permission to but references the one she doesn't
// load the file as suzy, make sure no exceptions occur and that the node is a missing reference
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);
DataNode node = new DataNode("kdjd");
RepositoryFile sampleFile = createSampleFile(ClientRepositoryPaths.getPublicFolderPath(), "helloworld2.sample", "dfdd", true, 83);
RepositoryFileAcl acl = repo.getAcl(sampleFile.getId());
RepositoryFileAcl newAcl = new RepositoryFileAcl.Builder(acl).entriesInheriting(false).clearAces().build();
repo.updateAcl(newAcl);
node.setProperty("urei2", new DataNodeRef(sampleFile.getId()));
final String parentFolderPath = ClientRepositoryPaths.getPublicFolderPath();
final String expectedName = "helloworld.doesnotmatter";
RepositoryFile parentFolder = repo.getFile(parentFolderPath);
assertNotNull(parentFolder);
final String expectedPath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
NodeRepositoryFileData data = new NodeRepositoryFileData(node);
RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).build(), data, null);
assertNotNull(newFile.getId());
// now check that the ref is missing
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile foundFile = repo.getFile(expectedPath);
assertNotNull(foundFile);
DataNode foundNode = repo.getDataForRead(newFile.getId(), NodeRepositoryFileData.class).getNode();
DataProperty d = foundNode.getProperty("urei2");
assertNotNull(d);
assertTrue(d.getType() == DataPropertyType.REF);
assertTrue(d.getRef().getId() == DataNodeRef.REF_MISSING);
// now change permissions back so she can get access to the node, confirm things are back to normal
login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
newAcl = new RepositoryFileAcl.Builder(acl).entriesInheriting(true).clearAces().build();
repo.updateAcl(newAcl);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
foundFile = repo.getFile(expectedPath);
assertNotNull(foundFile);
foundNode = repo.getDataForRead(newFile.getId(), NodeRepositoryFileData.class).getNode();
d = foundNode.getProperty("urei2");
assertNotNull(d);
assertTrue(d.getType() == DataPropertyType.REF);
assertTrue(d.getRef().getId().equals(sampleFile.getId()));
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryVersioningIT method testCircumventApiToGetVersionHistoryNodeAccessDenied.
@Test
public void testCircumventApiToGetVersionHistoryNodeAccessDenied() 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);
userRoleDao.createUser(tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null);
login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
RepositoryFile parentFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY));
RepositoryFile newFolder = new RepositoryFile.Builder("test").folder(true).versioned(true).build();
newFolder = repo.createFolder(parentFolder.getId(), newFolder, null);
final String absPath = ServerRepositoryPaths.getUserHomeFolderPath(tenantAcme, USERNAME_SUZY) + RepositoryFile.SEPARATOR + "test";
String versionHistoryAbsPath = SimpleJcrTestUtils.getVersionHistoryNodePath(testJcrTemplate, absPath);
login(USERNAME_TIFFANY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
assertNull(SimpleJcrTestUtils.getItem(testJcrTemplate, versionHistoryAbsPath));
}
use of org.pentaho.platform.api.mt.ITenant in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryVersioningIT method testCreateVersionedFile.
@Test
public void testCreateVersionedFile() 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 });
final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
RepositoryFile parentFolder = repo.getFile(parentFolderPath);
final String dataString = "Hello World!";
final String encoding = "UTF-8";
byte[] data = dataString.getBytes(encoding);
ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
final String mimeType = "text/plain";
final String fileName = "helloworld.xaction";
final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(fileName).versioned(true).build(), content, null);
assertTrue(newFile.isVersioned());
assertNotNull(newFile.getVersionId());
final String filePath = ServerRepositoryPaths.getUserHomeFolderPath(tenantAcme, USERNAME_SUZY) + RepositoryFile.SEPARATOR + fileName;
int versionCount = SimpleJcrTestUtils.getVersionCount(testJcrTemplate, filePath);
assertTrue(versionCount > 0);
repo.updateFile(newFile, content, null);
try {
repo.updateFile(newFile, content, null);
fail();
} catch (UnifiedRepositoryException e) {
// ignore
}
assertTrue(SimpleJcrTestUtils.getVersionCount(testJcrTemplate, filePath) > versionCount);
}
Aggregations