use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class ExportManifestTest method testUnMarshal.
@Test
public void testUnMarshal() {
String xml = XmlToString();
ExportManifest importManifest = null;
ByteArrayInputStream input = new ByteArrayInputStream(xml.getBytes());
try {
importManifest = ExportManifest.fromXml(input);
} catch (JAXBException e) {
fail("Could not un-marshal to object " + e);
}
ExportManifestEntity fileEntity = importManifest.getExportManifestEntity("dir2/file1");
assertNotNull(fileEntity);
assertEquals("dir2/file1", fileEntity.getPath());
assertNotNull(fileEntity.getEntityMetaData());
assertFalse(fileEntity.getEntityMetaData().isIsFolder());
fileEntity = importManifest.getExportManifestEntity("dir2");
assertNotNull(fileEntity);
assertNotNull(fileEntity.getEntityMetaData());
assertTrue(fileEntity.getEntityMetaData().isIsFolder());
RepositoryFile r = fileEntity.getRepositoryFile();
try {
RepositoryFileAcl rfa = fileEntity.getRepositoryFileAcl();
assertNotNull(rfa.getAces());
} catch (ExportManifestFormatException e) {
e.printStackTrace();
fail("Could not un-marshal to RepositoryFileAcl");
}
assertEquals(1, importManifest.getMetadataList().size());
assertEquals(1, importManifest.getMondrianList().size());
assertEquals(1, importManifest.getScheduleList().size());
assertEquals(1, importManifest.getDatasourceList().size());
ExportManifestMondrian mondrian1 = importManifest.getMondrianList().get(0);
assertEquals("cat1", mondrian1.getCatalogName());
assertTrue(mondrian1.getParameters().containsKey("testKey"));
assertEquals("testValue", mondrian1.getParameters().get("testKey"));
assertEquals("testMondrian.xml", mondrian1.getFile());
ExportManifestMetadata metadata1 = importManifest.getMetadataList().get(0);
assertEquals("testDomain", metadata1.getDomainId());
assertEquals("testMetadata.xml", metadata1.getFile());
DatabaseConnection connection = importManifest.getDatasourceList().get(0);
assertEquals("SampleData", connection.getDatabaseName());
assertEquals("9001", connection.getDatabasePort());
assertEquals("Hypersonic", connection.getDatabaseType().getName());
assertEquals("HYPERSONIC", connection.getDatabaseType().getShortName());
assertEquals("localhost", connection.getHostname());
assertEquals("pentaho_user", connection.getUsername());
assertEquals("password", connection.getPassword());
assertEquals(20, connection.getMaximumPoolSize());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrAclNodeHelper method getAclFor.
/**
* {@inheritDoc}
*/
@Override
public RepositoryFileAcl getAclFor(final RepositoryFile repositoryFile) {
if (repositoryFile == null) {
return null;
}
// Obtain a reference to ACL node as "system", guaranteed access
final RepositoryFile aclNode = getAclNode(repositoryFile);
// Removed redundant call to getAclNode via BISERVER-12780
if (aclNode == null) {
return null;
}
RepositoryFileAcl acl;
try {
acl = unifiedRepository.getAcl(aclNode.getId());
} catch (Exception e) {
return null;
}
RepositoryFileAcl.Builder aclBuilder = new RepositoryFileAcl.Builder(acl.getId(), acl.getOwner().getName(), RepositoryFileSid.Type.ROLE);
aclBuilder.aces(acl.getAces());
// add the Administrator role
if (canAdminister()) {
String adminRoleName = PentahoSystem.get(String.class, "singleTenantAdminAuthorityName", PentahoSessionHolder.getSession());
RepositoryFileAce adminGroup = new RepositoryFileAce(new RepositoryFileSid(adminRoleName, RepositoryFileSid.Type.ROLE), RepositoryFilePermission.ALL);
aclBuilder.ace(adminGroup);
}
return aclBuilder.build();
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrRepositoryFileAclDao method createAcl.
public RepositoryFileAcl createAcl(final Serializable fileId, final RepositoryFileAcl acl) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
return (RepositoryFileAcl) jcrTemplate.execute(new JcrCallback() {
public Object doInJcr(final Session session) throws RepositoryException, IOException {
PentahoJcrConstants pentahoJcrConstants = new PentahoJcrConstants(session);
Node node = session.getNodeByIdentifier(fileId.toString());
String absPath = node.getPath();
AccessControlManager acMgr = session.getAccessControlManager();
AccessControlList acList = getAccessControlList(acMgr, absPath);
acMgr.setPolicy(absPath, acList);
return internalUpdateAcl(session, pentahoJcrConstants, fileId, acl);
}
});
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrRepositoryFileAclDao method addAce.
public void addAce(final Serializable id, final RepositoryFileSid recipient, final EnumSet<RepositoryFilePermission> permission) {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
Assert.notNull(id);
Assert.notNull(recipient);
Assert.notNull(permission);
RepositoryFileAcl acl = getAcl(id);
Assert.notNull(acl);
// TODO mlowery find an ACE with the recipient and update that rather than adding a new ACE
RepositoryFileSid newRecipient = recipient;
if (recipient.getType().equals(Type.USER)) {
if (JcrTenantUtils.getUserNameUtils().getTenant(recipient.getName()) == null) {
newRecipient = new RepositoryFileSid(JcrTenantUtils.getTenantedUser(recipient.getName()), recipient.getType());
}
} else {
if (JcrTenantUtils.getRoleNameUtils().getTenant(recipient.getName()) == null) {
newRecipient = new RepositoryFileSid(JcrTenantUtils.getTenantedRole(recipient.getName()), recipient.getType());
}
}
RepositoryFileAcl updatedAcl = new RepositoryFileAcl.Builder(acl).ace(newRecipient, permission).build();
updateAcl(updatedAcl);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
logger.debug("added ace: id=" + id + ", sid=" + recipient + ", permission=" + permission);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class JcrRepositoryFileAclDao method internalUpdateAcl.
protected RepositoryFileAcl internalUpdateAcl(final Session session, final PentahoJcrConstants pentahoJcrConstants, final Serializable fileId, final RepositoryFileAcl acl) throws RepositoryException {
if (isKioskEnabled()) {
// $NON-NLS-1$
throw new RuntimeException(Messages.getInstance().getString("JcrRepositoryFileDao.ERROR_0006_ACCESS_DENIED"));
}
DefaultPermissionConversionHelper permissionConversionHelper = new DefaultPermissionConversionHelper(session);
Node node = session.getNodeByIdentifier(fileId.toString());
if (node == null) {
throw new RepositoryException(Messages.getInstance().getString("JackrabbitRepositoryFileAclDao.ERROR_0001_NODE_NOT_FOUND", // $NON-NLS-1$
fileId.toString()));
}
String absPath = node.getPath();
AccessControlManager acMgr = session.getAccessControlManager();
AccessControlList acList = getAccessControlList(acMgr, absPath);
// clear all entries
AccessControlEntry[] acEntries = acList.getAccessControlEntries();
for (int i = 0; i < acEntries.length; i++) {
acList.removeAccessControlEntry(acEntries[i]);
}
JcrRepositoryFileAclUtils.setAclMetadata(session, absPath, acList, new AclMetadata(acl.getOwner().getName(), acl.isEntriesInheriting()));
// add entries to now empty list but only if not inheriting; force user to start with clean slate
boolean adminPrincipalExist = false;
ITenant principalTenant = null;
if (!acl.isEntriesInheriting()) {
for (RepositoryFileAce ace : acl.getAces()) {
Principal principal = null;
if (RepositoryFileSid.Type.ROLE == ace.getSid().getType()) {
String principalName = JcrTenantUtils.getRoleNameUtils().getPrincipleName(ace.getSid().getName());
if (tenantAdminAuthorityName.equals(principalName)) {
adminPrincipalExist = true;
}
principal = new SpringSecurityRolePrincipal(JcrTenantUtils.getTenantedRole(ace.getSid().getName()));
} else {
principal = new SpringSecurityUserPrincipal(JcrTenantUtils.getTenantedUser(ace.getSid().getName()));
}
acList.addAccessControlEntry(principal, permissionConversionHelper.pentahoPermissionsToPrivileges(session, ace.getPermissions()));
}
if (!adminPrincipalExist) {
if (acl.getAces() != null && acl.getAces().size() > 0) {
principalTenant = JcrTenantUtils.getRoleNameUtils().getTenant(acl.getAces().get(0).getSid().getName());
}
if (principalTenant == null || principalTenant.getId() == null) {
principalTenant = JcrTenantUtils.getTenant();
}
List<RepositoryFilePermission> permissionList = new ArrayList<RepositoryFilePermission>();
permissionList.add(RepositoryFilePermission.ALL);
Principal adminPrincipal = new SpringSecurityRolePrincipal(JcrTenantUtils.getRoleNameUtils().getPrincipleId(principalTenant, tenantAdminAuthorityName));
acList.addAccessControlEntry(adminPrincipal, permissionConversionHelper.pentahoPermissionsToPrivileges(session, EnumSet.copyOf(permissionList)));
}
}
acMgr.setPolicy(absPath, acList);
session.save();
return getAcl(fileId);
}
Aggregations