use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project data-access by pentaho.
the class DataSourceWizardService method setDSWAcl.
/**
* Set ACL to both Mondrian Catalog and Metadata Schema
*
* @param dswId dsw id
* @param aclDto ACL
* @throws PentahoAccessControlException
* @throws FileNotFoundException
*/
public void setDSWAcl(String dswId, RepositoryFileAclDto aclDto) throws PentahoAccessControlException, FileNotFoundException {
checkDSWExists(dswId);
if (!endsWith(dswId, METADATA_EXT)) {
// if doesn't end in case-sensitive '.xmi' there will be trouble later on
final String errorMsg = "domainId must end in " + METADATA_EXT;
throw new IllegalArgumentException(errorMsg);
}
final RepositoryFileAcl acl = aclDto == null ? null : repositoryFileAclAdapter.unmarshal(aclDto);
if (aclAwareMondrianCatalogService != null) {
aclAwareMondrianCatalogService.setAclFor(dswId.substring(0, dswId.lastIndexOf(METADATA_EXT)), acl);
}
if (aclAwarePentahoMetadataDomainRepositoryImporter != null) {
aclAwarePentahoMetadataDomainRepositoryImporter.setAclFor(dswId, acl);
}
flushDataSources();
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class MondrianImportHandler method importFile.
/**
* **************************************** Main entry point from the Spring Interface
*
* @param IPlatformImportBundle
* @throws IOException
* @throws DomainStorageException
* @throws DomainAlreadyExistsException
* @throws DomainIdNullException
* @throws PlatformImportException
* @throws SAXException
* @throws ParserConfigurationException
*/
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
boolean overwriteInRepossitory = bundle.overwriteInRepository();
boolean xmla = "false".equalsIgnoreCase(findParameterPropertyValue(bundle, ENABLE_XMLA)) ? false : true;
final String domainId = (String) bundle.getProperty(DOMAIN_ID);
if (domainId == null) {
throw new PlatformImportException("Bundle missing required domain-id property");
}
try {
InputStream is = bundle.getInputStream();
MondrianCatalog catalog = this.createCatalogObject(domainId, xmla, bundle);
IPentahoSession session = PentahoSessionHolder.getSession();
if (mondrianRepositoryImporter instanceof IAclAwareMondrianCatalogService) {
RepositoryFileAcl acl = bundle.isApplyAclSettings() ? bundle.getAcl() : null;
IAclAwareMondrianCatalogService aware = (IAclAwareMondrianCatalogService) mondrianRepositoryImporter;
aware.addCatalog(is, catalog, overwriteInRepossitory, acl, session);
} else {
mondrianRepositoryImporter.addCatalog(is, catalog, overwriteInRepossitory, session);
}
} catch (MondrianCatalogServiceException mse) {
int statusCode = convertExceptionToStatus(mse);
throw new PlatformImportException(mse.getMessage(), statusCode);
} catch (Exception e) {
throw new PlatformImportException(e.getMessage(), PlatformImportException.PUBLISH_GENERAL_ERROR);
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class PDIImportFileHandler method updateFile.
@Override
protected RepositoryFile updateFile(final RepositoryFileImportBundle bundle, final RepositoryFile file, final IRepositoryFileData data) throws PlatformImportException {
RepositoryFile updatedFile = null;
if (isNodeRepositoryFileData(file)) {
updatedFile = getRepository().updateFile(file, data, bundle.getComment());
} else {
String fileName = bundle.getName();
getLogger().trace("The file [" + fileName + "] will be recreated because it content-type was changed.");
RepositoryFileAcl originFileAcl = getRepository().getAcl(file.getId());
getRepository().deleteFile(file.getId(), true, null);
RepositoryFileAcl newFileAcl = bundle.getAcl();
bundle.setAcl(originFileAcl);
updatedFile = createFile(bundle, file.getPath(), data);
bundle.setAcl(newFileAcl);
}
return updatedFile;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class FileService method doSetMetadata.
/**
* Set the metadata on a file
*
* @param pathId
* @param metadata
* @throws GeneralSecurityException
*/
public void doSetMetadata(String pathId, List<StringKeyStringValueDto> metadata) throws GeneralSecurityException {
RepositoryFileDto file = getRepoWs().getFile(idToPath(pathId));
RepositoryFileAclDto fileAcl = getRepoWs().getAcl(file.getId());
boolean canManage = getSession().getName().equals(fileAcl.getOwner()) || (getPolicy().isAllowed(RepositoryReadAction.NAME) && getPolicy().isAllowed(RepositoryCreateAction.NAME) && getPolicy().isAllowed(AdministerSecurityAction.NAME));
if (!canManage) {
if (fileAcl.isEntriesInheriting()) {
List<RepositoryFileAclAceDto> aces = getRepoWs().getEffectiveAces(file.getId());
fileAcl.setAces(aces, fileAcl.isEntriesInheriting());
}
for (int i = 0; i < fileAcl.getAces().size(); i++) {
RepositoryFileAclAceDto acl = fileAcl.getAces().get(i);
if (acl.getRecipient().equals(getSession().getName())) {
if (acl.getPermissions().contains(RepositoryFilePermission.ACL_MANAGEMENT.ordinal()) || acl.getPermissions().contains(RepositoryFilePermission.ALL.ordinal())) {
canManage = true;
break;
}
}
}
}
if (canManage) {
Map<String, Serializable> fileMetadata = getRepository().getFileMetadata(file.getId());
boolean isHidden = RepositoryFile.HIDDEN_BY_DEFAULT;
boolean isSchedulable = RepositoryFile.SCHEDULABLE_BY_DEFAULT;
fileMetadata.remove(RepositoryFile.HIDDEN_KEY);
for (StringKeyStringValueDto nv : metadata) {
// don't add hidden to the list because it is not actually part of the metadata node
String key = nv.getKey();
if (RepositoryFile.HIDDEN_KEY.equalsIgnoreCase(key)) {
isHidden = BooleanUtils.toBoolean(nv.getValue());
continue;
}
if (RepositoryFile.SCHEDULABLE_KEY.equalsIgnoreCase(key)) {
isSchedulable = BooleanUtils.toBoolean(nv.getValue());
}
fileMetadata.put(key, nv.getValue());
}
// now update the rest of the metadata
if (!file.isFolder()) {
getRepository().setFileMetadata(file.getId(), fileMetadata);
}
// handle hidden flag if it is different
if (file.isHidden() != isHidden) {
file.setHidden(isHidden);
file.setNotSchedulable(!isSchedulable);
/*
* Since we cannot simply set the new value, use the RepositoryFileAdapter to create a new instance and then
* update the original.
*/
RepositoryFile sourceFile = getRepository().getFileById(file.getId());
RepositoryFileDto destFileDto = toFileDto(sourceFile, null, false);
destFileDto.setHidden(isHidden);
destFileDto.setNotSchedulable(!isSchedulable);
RepositoryFile destFile = toFile(destFileDto);
// add the existing acls and file data
RepositoryFileAcl acl = getRepository().getAcl(sourceFile.getId());
if (!file.isFolder()) {
IRepositoryFileData data = RepositoryFileHelper.getFileData(sourceFile);
getRepository().updateFile(destFile, data, null);
getRepository().updateAcl(acl);
} else {
getRepository().updateFolder(destFile, null);
}
}
} else {
throw new GeneralSecurityException();
}
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl in project pentaho-platform by pentaho.
the class CopyFilesOperation method copyOverrideMode.
private void copyOverrideMode(RepositoryFile file) {
if (sourceAndDestDirAreSame(file.getPath())) {
return;
}
RepositoryFileAcl acl = getRepository().getAcl(file.getId());
RepositoryFile destFile = getRepository().getFile(destDir.getPath() + FileUtils.PATH_SEPARATOR + file.getName());
if (destFile == null) {
// destFile doesn't exist so we'll create it.
RepositoryFile duplicateFile = new RepositoryFile.Builder(file.getName()).hidden(file.isHidden()).versioned(file.isVersioned()).build();
final RepositoryFile repositoryFile = getRepository().createFile(destDir.getId(), duplicateFile, RepositoryFileHelper.getFileData(file), acl, null);
getRepository().setFileMetadata(repositoryFile.getId(), getRepository().getFileMetadata(file.getId()));
return;
}
RepositoryFileDto destFileDto = toFileDto(destFile, null, false);
destFileDto.setHidden(file.isHidden());
destFile = toFile(destFileDto);
final RepositoryFile repositoryFile = getRepository().updateFile(destFile, RepositoryFileHelper.getFileData(file), null);
getRepository().updateAcl(acl);
getRepository().setFileMetadata(repositoryFile.getId(), getRepository().getFileMetadata(file.getId()));
}
Aggregations