Changeset 29127

Show
Ignore:
Timestamp:
01/17/08 20:11:29 (11 months ago)
Author:
tdelprat
Message:

NXP-1941
working on security exception propagation

Files:

Legend:

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

    r28367 r29127  
    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/branches/1.4/nuxeo-core-facade/src/test/java/org/nuxeo/ecm/core/api/TestSecurity.java

    r28980 r29127  
    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/branches/1.4/nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java

    r28924 r29127  
    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        } 
     
    10001001            Document doc = resolveReference(docRef); 
    10011002            Document parentDoc = doc.getParent(); 
    1002             // XXX either we raise a ClientException after checkPermission but 
    1003             // we can't raise a uncaught SecurityException here. 
    1004             if (parentDoc == null || !hasPermission(parentDoc, READ)) { 
     1003            if (parentDoc == null) 
    10051004                return null; 
     1005            if (!hasPermission(parentDoc, READ)) { 
     1006                throw new DocumentSecurityException("Provilege READ is not granted to " + getPrincipal().getName()); 
    10061007            } 
    10071008            return readModel(parentDoc, null); 
     
    21832184        } 
    21842185        if (!isAdministrator()) { 
    2185             throw new SecurityException( 
     2186            throw new DocumentSecurityException( 
    21862187                    "You need to be an Administrator to do this."); 
    21872188        } 
     
    22762277            return doc; 
    22772278        } else { 
    2278             DocumentModel parent = getParentDocument(doc.getRef()); 
    2279             if (parent == null) { 
    2280                 return doc; // return Root instead of null 
     2279 
     2280            DocumentModel parent = getDirectAccessibleParent(doc.getRef()); 
     2281            if (parent == null ||"/".equals(parent.getPathAsString())) { 
     2282                return getRootDocument(); // return Root instead of null 
    22812283            } else { 
    22822284                return getSuperSpace(parent); 
    22832285            } 
     2286        } 
     2287    } 
     2288 
     2289 
     2290    // walk the tree up until a accessible doc is found 
     2291    private DocumentModel getDirectAccessibleParent(DocumentRef docRef) throws ClientException 
     2292    { 
     2293        try { 
     2294            Document doc = resolveReference(docRef); 
     2295            Document parentDoc = doc.getParent(); 
     2296            if (parentDoc==null) 
     2297                return readModel(doc,null); 
     2298            if (!hasPermission(parentDoc, READ)) { 
     2299                String parentPath = parentDoc.getPath(); 
     2300                if ("/".equals(parentPath)){ 
     2301                    return getRootDocument(); 
     2302                } 
     2303                else{ 
     2304                    // try on parent 
     2305                    return getDirectAccessibleParent(new PathRef(parentDoc.getPath())); 
     2306                } 
     2307            } 
     2308            return readModel(parentDoc, null); 
     2309        } catch (DocumentException e) { 
     2310            throw new ClientException(e); 
    22842311        } 
    22852312    }