Search in sources :

Example 1 with DocumentSecurityException

use of org.nuxeo.ecm.core.api.DocumentSecurityException in project nuxeo-drive-server by nuxeo.

the class DocumentBackedFolderItem method populateAncestorCache.

protected FolderItem populateAncestorCache(Map<DocumentRef, FolderItem> cache, DocumentModel doc, CoreSession session, boolean cacheItem) {
    DocumentRef parentDocRef = session.getParentDocumentRef(doc.getRef());
    if (parentDocRef == null) {
        throw new RootlessItemException("Reached repository root");
    }
    FolderItem parentItem = cache.get(parentDocRef);
    if (parentItem != null) {
        if (log.isTraceEnabled()) {
            log.trace(String.format("Found parent FolderItem in cache for doc %s: %s", doc.getPathAsString(), parentItem.getPath()));
        }
        return getFolderItem(cache, doc, parentItem, cacheItem);
    }
    if (log.isTraceEnabled()) {
        log.trace(String.format("No parent FolderItem found in cache for doc %s, computing ancestor cache", doc.getPathAsString()));
    }
    DocumentModel parentDoc;
    try {
        parentDoc = session.getDocument(parentDocRef);
    } catch (DocumentSecurityException e) {
        throw new RootlessItemException(String.format("User %s has no READ access on parent of document %s (%s).", principal.getName(), doc.getPathAsString(), doc.getId()), e);
    }
    parentItem = populateAncestorCache(cache, parentDoc, session, true);
    if (parentItem == null) {
        return null;
    }
    return getFolderItem(cache, doc, parentItem, cacheItem);
}
Also used : FolderItem(org.nuxeo.drive.adapter.FolderItem) DocumentRef(org.nuxeo.ecm.core.api.DocumentRef) RootlessItemException(org.nuxeo.drive.adapter.RootlessItemException) DocumentSecurityException(org.nuxeo.ecm.core.api.DocumentSecurityException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 2 with DocumentSecurityException

use of org.nuxeo.ecm.core.api.DocumentSecurityException in project nuxeo-drive-server by nuxeo.

the class AbstractFileSystemItemFactory method getFileSystemItemById.

@Override
public FileSystemItem getFileSystemItemById(String id, String parentId, Principal principal) {
    String[] idFragments = parseFileSystemId(id);
    String repositoryName = idFragments[1];
    String docId = idFragments[2];
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        FileSystemItem parentItem = Framework.getService(FileSystemItemAdapterService.class).getFileSystemItemFactoryForId(parentId).getFileSystemItemById(parentId, principal);
        if (!(parentItem instanceof FolderItem)) {
            throw new NuxeoException(String.format("FileSystemItem with id %s should be a FolderItem", parentId));
        }
        DocumentModel doc = getDocumentById(docId, session);
        return getFileSystemItem(doc, (FolderItem) parentItem);
    } catch (DocumentNotFoundException e) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("No doc related to id %s, returning null.", docId));
        }
        return null;
    } catch (DocumentSecurityException e) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("User %s cannot access doc %s, returning null.", principal.getName(), docId));
        }
        return null;
    }
}
Also used : AbstractFileSystemItem(org.nuxeo.drive.adapter.impl.AbstractFileSystemItem) FileSystemItem(org.nuxeo.drive.adapter.FileSystemItem) FolderItem(org.nuxeo.drive.adapter.FolderItem) DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentSecurityException(org.nuxeo.ecm.core.api.DocumentSecurityException) NuxeoException(org.nuxeo.ecm.core.api.NuxeoException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 3 with DocumentSecurityException

use of org.nuxeo.ecm.core.api.DocumentSecurityException in project nuxeo-drive-server by nuxeo.

the class AbstractFileSystemItemFactory method exists.

/**
 * The default factory considers that a {@link FileSystemItem} with the given id exists if the backing
 * {@link DocumentModel} can be fetched and {@link #isFileSystemItem(DocumentModel)} returns true.
 *
 * @see #isFileSystemItem(DocumentModel)
 */
@Override
public boolean exists(String id, Principal principal) {
    String[] idFragments = parseFileSystemId(id);
    String repositoryName = idFragments[1];
    String docId = idFragments[2];
    try (CloseableCoreSession session = CoreInstance.openCoreSession(repositoryName, principal)) {
        DocumentModel doc = getDocumentById(docId, session);
        return isFileSystemItem(doc);
    } catch (DocumentNotFoundException e) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("No doc related to id %s, returning false.", docId));
        }
        return false;
    } catch (DocumentSecurityException e) {
        if (log.isDebugEnabled()) {
            log.debug(String.format("User %s cannot access doc %s, returning false.", principal.getName(), docId));
        }
        return false;
    }
}
Also used : DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) CloseableCoreSession(org.nuxeo.ecm.core.api.CloseableCoreSession) DocumentSecurityException(org.nuxeo.ecm.core.api.DocumentSecurityException) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel)

Example 4 with DocumentSecurityException

use of org.nuxeo.ecm.core.api.DocumentSecurityException in project nuxeo-drive-server by nuxeo.

the class NuxeoDriveManagerImpl method queryAndFetchSynchronizationRoots.

protected Map<String, SynchronizationRoots> queryAndFetchSynchronizationRoots(CoreSession session, String query) {
    Map<String, SynchronizationRoots> syncRoots = new HashMap<String, SynchronizationRoots>();
    Set<IdRef> references = new LinkedHashSet<IdRef>();
    Set<String> paths = new LinkedHashSet<String>();
    IterableQueryResult results = session.queryAndFetch(query, NXQL.NXQL);
    try {
        for (Map<String, Serializable> result : results) {
            IdRef docRef = new IdRef(result.get("ecm:uuid").toString());
            try {
                DocumentModel doc = session.getDocument(docRef);
                references.add(docRef);
                paths.add(doc.getPathAsString());
            } catch (DocumentNotFoundException e) {
                log.warn(String.format("Document %s not found, not adding it to the list of synchronization roots for user %s.", docRef, session.getPrincipal().getName()));
            } catch (DocumentSecurityException e) {
                log.warn(String.format("User %s cannot access document %s, not adding it to the list of synchronization roots.", session.getPrincipal().getName(), docRef));
            }
        }
    } finally {
        results.close();
    }
    SynchronizationRoots repoSyncRoots = new SynchronizationRoots(session.getRepositoryName(), paths, references);
    syncRoots.put(session.getRepositoryName(), repoSyncRoots);
    return syncRoots;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Serializable(java.io.Serializable) DocumentNotFoundException(org.nuxeo.ecm.core.api.DocumentNotFoundException) HashMap(java.util.HashMap) SynchronizationRoots(org.nuxeo.drive.service.SynchronizationRoots) DocumentSecurityException(org.nuxeo.ecm.core.api.DocumentSecurityException) IdRef(org.nuxeo.ecm.core.api.IdRef) DocumentModel(org.nuxeo.ecm.core.api.DocumentModel) IterableQueryResult(org.nuxeo.ecm.core.api.IterableQueryResult)

Aggregations

DocumentModel (org.nuxeo.ecm.core.api.DocumentModel)4 DocumentSecurityException (org.nuxeo.ecm.core.api.DocumentSecurityException)4 DocumentNotFoundException (org.nuxeo.ecm.core.api.DocumentNotFoundException)3 FolderItem (org.nuxeo.drive.adapter.FolderItem)2 CloseableCoreSession (org.nuxeo.ecm.core.api.CloseableCoreSession)2 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 FileSystemItem (org.nuxeo.drive.adapter.FileSystemItem)1 RootlessItemException (org.nuxeo.drive.adapter.RootlessItemException)1 AbstractFileSystemItem (org.nuxeo.drive.adapter.impl.AbstractFileSystemItem)1 SynchronizationRoots (org.nuxeo.drive.service.SynchronizationRoots)1 DocumentRef (org.nuxeo.ecm.core.api.DocumentRef)1 IdRef (org.nuxeo.ecm.core.api.IdRef)1 IterableQueryResult (org.nuxeo.ecm.core.api.IterableQueryResult)1 NuxeoException (org.nuxeo.ecm.core.api.NuxeoException)1