Changeset 30100
- Timestamp:
- 02/12/08 19:56:57 (9 months ago)
- Files:
-
- org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/ClientException.java (modified) (2 diffs)
- org.nuxeo.ecm.core/trunk/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/DocumentSecurityException.java (copied) (copied from org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/DocumentSecurityException.java)
- org.nuxeo.ecm.core/trunk/nuxeo-core-facade/src/test/java/org/nuxeo/ecm/core/api/TestSecurity.java (modified) (1 diff)
- org.nuxeo.ecm.core/trunk/nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java (modified) (5 diffs)
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 40 40 } 41 41 42 public ClientException(String message, ClientException cause) { 43 super(message, cause); 44 } 45 42 46 public ClientException(String message, Throwable cause) { 43 47 super(message, WrappedException.wrap(cause)); … … 48 52 } 49 53 54 public ClientException(ClientException cause) { 55 super(cause); 56 } 57 50 58 } org.nuxeo.ecm.core/trunk/nuxeo-core-facade/src/test/java/org/nuxeo/ecm/core/api/TestSecurity.java
r28983 r30100 203 203 folder2 = remote.createDocument(folder2); 204 204 fail("privilege is granted but should not be"); 205 } catch ( SecurityException e) {205 } catch (DocumentSecurityException e) { 206 206 // ok 207 207 } org.nuxeo.ecm.core/trunk/nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java
r29904 r30100 40 40 import org.nuxeo.common.utils.IdUtils; 41 41 import org.nuxeo.common.utils.Path; 42 import org.nuxeo.common.utils.StringUtils; 42 43 import org.nuxeo.ecm.core.NXCore; 43 44 import org.nuxeo.ecm.core.api.event.CoreEvent; … … 256 257 257 258 protected final void checkPermission(Document doc, String permission) 258 throws Document Exception {259 throws DocumentSecurityException, DocumentException { 259 260 if (!hasPermission(doc, permission)) { 260 throw new SecurityException("Privilege '" + permission261 throw new DocumentSecurityException("Privilege '" + permission 261 262 + "' is not granted to '" + getPrincipal().getName() + "'"); 262 263 } … … 1014 1015 Document doc = resolveReference(docRef); 1015 1016 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) 1019 1018 return null; 1019 if (!hasPermission(parentDoc, READ)) { 1020 throw new DocumentSecurityException("Provilege READ is not granted to " + getPrincipal().getName()); 1020 1021 } 1021 1022 return readModel(parentDoc, null); … … 2211 2212 } 2212 2213 if (!isAdministrator()) { 2213 throw new SecurityException(2214 throw new DocumentSecurityException( 2214 2215 "You need to be an Administrator to do this."); 2215 2216 } … … 2304 2305 return doc; 2305 2306 } 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 2309 2311 } else { 2310 2312 return getSuperSpace(parent); 2311 2313 } 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); 2312 2339 } 2313 2340 }
