use of org.pentaho.platform.api.repository2.unified.RepositoryFilePermission in project pentaho-platform by pentaho.
the class OlapServiceImplTest method testGetOlap4jCatalogsWithoutAccess.
/**
* Validates getting a list of remote catalogs if we don't have access to them.
*/
@Test
public void testGetOlap4jCatalogsWithoutAccess() throws Exception {
stubGetChildren(repository, olapFolderPath, "myServer");
// Stub /etc/olap-servers/myServer
final String testServerPath = olapFolderPath + RepositoryFile.SEPARATOR + "myServer";
stubGetFolder(repository, testServerPath);
stubGetChildren(repository, testServerPath, "metadata");
// Stub /etc/olap-servers/myServer/metadata
final String metadataPath = testServerPath + RepositoryFile.SEPARATOR + "metadata";
stubGetFile(repository, metadataPath);
stubGetData(repository, metadataPath + RepositoryFile.SEPARATOR + "myServer", "server", pathPropertyPair("/server/name", "myServer"), pathPropertyPair("/server/user", "myUser"), pathPropertyPair("/server/password", "myPassword"), pathPropertyPair("/server/URL", "myUrl"), pathPropertyPair("/server/className", "someClass"));
// Stub the security
accessMock = new DefaultAccessImpl() {
public boolean hasAccess(String path, EnumSet<RepositoryFilePermission> perms, IPentahoSession session) {
if (!perms.contains(RepositoryFilePermission.READ)) {
fail();
}
return false;
}
};
// Get a list of catalogs.
final List<String> catalogs = olapService.getCatalogNames(session);
assertEquals(0, catalogs.size());
verify(repository).getChildren(eq(makeIdObject(olapFolderPath)));
// Now try obtaining it anyways.
try {
olapService.getConnection("myServer", session);
fail();
} catch (IOlapServiceException e) {
assertEquals(IOlapServiceException.Reason.ACCESS_DENIED, e.getReason());
assertTrue(e.getMessage().contains("OlapServiceImpl.ERROR_0003"));
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFilePermission in project pentaho-platform by pentaho.
the class DefaultUnifiedRepositoryAuthorizationIT method assertLocalAceExists.
private void assertLocalAceExists(final RepositoryFile file, final RepositoryFileSid sid, final EnumSet<RepositoryFilePermission> permissions) {
RepositoryFileAcl acl = repo.getAcl(file.getId());
List<RepositoryFileAce> aces = acl.getAces();
for (RepositoryFileAce ace : aces) {
if (sid.equals(ace.getSid()) && permissions.equals(ace.getPermissions())) {
return;
}
}
fail();
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFilePermission in project pentaho-platform by pentaho.
the class JcrAclNodeHelper method canAccess.
@Override
public boolean canAccess(final RepositoryFile repositoryFile, final EnumSet<RepositoryFilePermission> permissions) {
if (repositoryFile == null) {
return false;
}
// 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 true;
}
boolean notFound;
try {
// Check to see if user has READ access to file, this will return null if not.
notFound = (unifiedRepository.getFileById(aclNode.getId()) == null);
} catch (Exception e) {
if (logger.isWarnEnabled()) {
logger.warn("Error checking access for file", e);
}
notFound = true;
}
if (notFound) {
return false;
}
// if read passed, check the other permissions
return unifiedRepository.hasAccess(aclNode.getPath(), permissions);
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFilePermission in project pentaho-platform by pentaho.
the class DefaultPermissionConversionHelper method privilegesToPentahoPermissions.
public EnumSet<RepositoryFilePermission> privilegesToPentahoPermissions(final Session session, final Privilege[] privileges) throws RepositoryException {
Assert.notNull(session);
Assert.notNull(privileges);
new PentahoJcrConstants(session);
EnumSet<RepositoryFilePermission> permissions = EnumSet.noneOf(RepositoryFilePermission.class);
Privilege[] expandedPrivileges = JcrRepositoryFileAclUtils.expandPrivileges(privileges, true);
for (Privilege privilege : expandedPrivileges) {
// this privilege name is of the format xyz:blah where xyz is the namespace prefix;
// convert it to match the Privilege.JCR_* string constants
String extendedPrivilegeName = privilege.getName();
String privilegeName = privilege.getName();
// $NON-NLS-1$
int colonIndex = privilegeName.indexOf(':');
if (colonIndex > -1) {
String namespaceUri = session.getNamespaceURI(privilegeName.substring(0, colonIndex));
// $NON-NLS-1$ //$NON-NLS-2$
extendedPrivilegeName = "{" + namespaceUri + "}" + privilegeName.substring(colonIndex + 1);
}
if (privilegeNameToPermissionEnumsMap.containsKey(extendedPrivilegeName)) {
Collection<RepositoryFilePermission> permEnums = privilegeNameToPermissionEnumsMap.get(extendedPrivilegeName);
for (RepositoryFilePermission perm : permEnums) {
permissions.add(perm);
}
} else {
logger.debug(// $NON-NLS-1$
"skipping privilege with name=" + extendedPrivilegeName + // $NON-NLS-1$
" as it doesn't have any corresponding permissions");
}
}
Assert.isTrue(!permissions.isEmpty(), "no permissions; see previous 'skipping privilege' messages");
return permissions;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFilePermission in project pentaho-platform by pentaho.
the class ActionSequenceJCRHelper method getSolutionDocument.
public Document getSolutionDocument(final String documentPath, final RepositoryFilePermission actionOperation) {
RepositoryFile file = repository.getFile(documentPath);
Document document = null;
SimpleRepositoryFileData data = null;
if (file != null) {
data = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
if (data != null) {
try {
document = XmlDom4JHelper.getDocFromStream(data.getStream());
} catch (Throwable t) {
logger.error(Messages.getInstance().getErrorString("ActionSequenceJCRHelper.ERROR_0017_INVALID_XML_DOCUMENT", documentPath), // $NON-NLS-1$
t);
return null;
}
} else {
logger.error(Messages.getInstance().getErrorString("ActionSequenceJCRHelper.ERROR_0019_NO_DATA_IN_FILE", // $NON-NLS-1$
file.getName()));
return null;
}
if ((document == null) && (file != null) && (data != null)) {
// the document exists but cannot be parsed
logger.error(Messages.getInstance().getErrorString("ActionSequenceJCRHelper.ERROR_0009_INVALID_DOCUMENT", // $NON-NLS-1$
documentPath));
return null;
}
localizeDoc(document, file);
}
return document;
}
Aggregations