Changeset 29127
- Timestamp:
- 01/17/08 20:11:29 (11 months ago)
- Files:
-
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/ClientException.java (modified) (2 diffs)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/DocumentSecurityException.java (added)
- org.nuxeo.ecm.core/branches/1.4/nuxeo-core-facade/src/test/java/org/nuxeo/ecm/core/api/TestSecurity.java (modified) (1 diff)
- org.nuxeo.ecm.core/branches/1.4/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/branches/1.4/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/ClientException.java
r28367 r29127 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/branches/1.4/nuxeo-core-facade/src/test/java/org/nuxeo/ecm/core/api/TestSecurity.java
r28980 r29127 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/branches/1.4/nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java
r28924 r29127 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 } … … 1000 1001 Document doc = resolveReference(docRef); 1001 1002 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) 1005 1004 return null; 1005 if (!hasPermission(parentDoc, READ)) { 1006 throw new DocumentSecurityException("Provilege READ is not granted to " + getPrincipal().getName()); 1006 1007 } 1007 1008 return readModel(parentDoc, null); … … 2183 2184 } 2184 2185 if (!isAdministrator()) { 2185 throw new SecurityException(2186 throw new DocumentSecurityException( 2186 2187 "You need to be an Administrator to do this."); 2187 2188 } … … 2276 2277 return doc; 2277 2278 } 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 2281 2283 } else { 2282 2284 return getSuperSpace(parent); 2283 2285 } 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); 2284 2311 } 2285 2312 }
