Search in sources :

Example 66 with RepositoryFileAcl

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();
}
Also used : RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 67 with RepositoryFileAcl

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);
    }
}
Also used : MondrianCatalog(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalog) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) IAclAwareMondrianCatalogService(org.pentaho.platform.plugin.action.mondrian.catalog.IAclAwareMondrianCatalogService) InputStream(java.io.InputStream) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) IOException(java.io.IOException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) SAXException(org.xml.sax.SAXException)

Example 68 with RepositoryFileAcl

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;
}
Also used : RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 69 with RepositoryFileAcl

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();
    }
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) StringKeyStringValueDto(org.pentaho.platform.repository2.unified.webservices.StringKeyStringValueDto) IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) Serializable(java.io.Serializable) RepositoryFileAclAceDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclAceDto) RepositoryFileAclDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileAclDto) GeneralSecurityException(java.security.GeneralSecurityException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Example 70 with RepositoryFileAcl

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()));
}
Also used : RepositoryFileDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryFileAcl(org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)

Aggregations

RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)99 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)73 Test (org.junit.Test)50 ITenant (org.pentaho.platform.api.mt.ITenant)25 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)23 RepositoryFileAce (org.pentaho.platform.api.repository2.unified.RepositoryFileAce)15 Node (javax.jcr.Node)13 Matchers.anyString (org.mockito.Matchers.anyString)13 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)13 Serializable (java.io.Serializable)12 Session (javax.jcr.Session)12 JcrCallback (org.springframework.extensions.jcr.JcrCallback)12 ArrayList (java.util.ArrayList)11 RepositoryException (javax.jcr.RepositoryException)10 ByteArrayInputStream (java.io.ByteArrayInputStream)9 IOException (java.io.IOException)9 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)9 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)8 RepositoryFilePermission (org.pentaho.platform.api.repository2.unified.RepositoryFilePermission)8 InputStream (java.io.InputStream)7