Changeset 30100

Show
Ignore:
Timestamp:
02/12/08 19:56:57 (9 months ago)
Author:
bstefanescu
Message:

merged from branch 29127

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/ClientException.java

    r28368 r30100  
    4040    } 
    4141 
     42    public ClientException(String message, ClientException cause) { 
     43        super(message, cause); 
     44    } 
     45 
    4246    public ClientException(String message, Throwable cause) { 
    4347        super(message, WrappedException.wrap(cause)); 
     
    4852    } 
    4953 
     54    public ClientException(ClientException cause) { 
     55        super(cause); 
     56    } 
     57 
    5058} 
  • org.nuxeo.ecm.core/trunk/nuxeo-core-facade/src/test/java/org/nuxeo/ecm/core/api/TestSecurity.java

    r28983 r30100  
    203203            folder2 = remote.createDocument(folder2); 
    204204            fail("privilege is granted but should not be"); 
    205         } catch (SecurityException e) { 
     205        } catch (DocumentSecurityException e) { 
    206206            // ok 
    207207        } 
  • org.nuxeo.ecm.core/trunk/nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java

    r29904 r30100  
    4040import org.nuxeo.common.utils.IdUtils; 
    4141import org.nuxeo.common.utils.Path; 
     42import org.nuxeo.common.utils.StringUtils; 
    4243import org.nuxeo.ecm.core.NXCore; 
    4344import org.nuxeo.ecm.core.api.event.CoreEvent; 
     
    256257 
    257258    protected final void checkPermission(Document doc, String permission) 
    258             throws DocumentException { 
     259            throws DocumentSecurityException, DocumentException { 
    259260        if (!hasPermission(doc, permission)) { 
    260             throw new SecurityException("Privilege '" + permission 
     261            throw new DocumentSecurityException("Privilege '" + permission 
    261262                    + "' is not granted to '" + getPrincipal().getName() + "'"); 
    262263        } 
     
    10141015            Document doc = resolveReference(docRef); 
    10151016            Document parentDoc = doc.getParent(); 
    1016             // XXX either we raise a ClientException after checkPermission but 
    1017             // we can't raise a uncaught SecurityException here. 
    1018             if (parentDoc == null || !hasPermission(parentDoc, READ)) { 
     1017            if (parentDoc == null) 
    10191018                return null; 
     1019            if (!hasPermission(parentDoc, READ)) { 
     1020                throw new DocumentSecurityException("Provilege READ is not granted to " + getPrincipal().getName()); 
    10201021            } 
    10211022            return readModel(parentDoc, null); 
     
    22112212        } 
    22122213        if (!isAdministrator()) { 
    2213             throw new SecurityException( 
     2214            throw new DocumentSecurityException( 
    22142215                    "You need to be an Administrator to do this."); 
    22152216        } 
     
    23042305            return doc; 
    23052306        } else { 
    2306             DocumentModel parent = getParentDocument(doc.getRef()); 
    2307             if (parent == null) { 
    2308                 return doc; // return Root instead of null 
     2307 
     2308            DocumentModel parent = getDirectAccessibleParent(doc.getRef()); 
     2309            if (parent == null ||"/".equals(parent.getPathAsString())) { 
     2310                return getRootDocument(); // return Root instead of null 
    23092311            } else { 
    23102312                return getSuperSpace(parent); 
    23112313            } 
     2314        } 
     2315    } 
     2316 
     2317 
     2318    // walk the tree up until a accessible doc is found 
     2319    private DocumentModel getDirectAccessibleParent(DocumentRef docRef) throws ClientException 
     2320    { 
     2321        try { 
     2322            Document doc = resolveReference(docRef); 
     2323            Document parentDoc = doc.getParent(); 
     2324            if (parentDoc==null) 
     2325                return readModel(doc,null); 
     2326            if (!hasPermission(parentDoc, READ)) { 
     2327                String parentPath = parentDoc.getPath(); 
     2328                if ("/".equals(parentPath)){ 
     2329                    return getRootDocument(); 
     2330                } 
     2331                else{ 
     2332                    // try on parent 
     2333                    return getDirectAccessibleParent(new PathRef(parentDoc.getPath())); 
     2334                } 
     2335            } 
     2336            return readModel(parentDoc, null); 
     2337        } catch (DocumentException e) { 
     2338            throw new ClientException(e); 
    23122339        } 
    23132340    }