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);
}
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;
}
}
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;
}
}
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;
}
Aggregations