Changeset 105:7417f5915181 in AnnotationManagerN4J
- Timestamp:
- Feb 10, 2017, 2:45:35 PM (8 years ago)
- Branch:
- default
- Tags:
- tip
- Location:
- src/main/java/de/mpiwg/itgroup/annotations
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
src/main/java/de/mpiwg/itgroup/annotations/Annotation.java
r95 r105 132 132 133 133 /** 134 * Enum of actions (for permissions). 135 */ 136 public static enum Action { 137 read, update, create, delete, admin 138 } 139 140 /** 134 141 * Returns if the requested action is allowed for the given user on this annotation. 135 142 * … … 139 146 * @return 140 147 */ 141 public boolean isActionAllowed( Stringaction, Person user, AnnotationStore store) {142 if (action .equals("read")) {148 public boolean isActionAllowed(Action action, Person user, AnnotationStore store) { 149 if (action == Action.read) { 143 150 Actor reader = getReadPermission(); 144 151 if (reader == null) { … … 148 155 return reader.isEquivalentWith(user, store); 149 156 } 150 } else if (action .equals("update")) {157 } else if (action == Action.update) { 151 158 // require at least an authenticated user 152 159 if (user == null) return false; … … 158 165 return updater.isEquivalentWith(user, store); 159 166 } 160 } else if (action .equals("delete")) {167 } else if (action == Action.delete) { 161 168 // require at least an authenticated user 162 169 if (user == null) return false; … … 167 174 } 168 175 return deleter.isEquivalentWith(user, store); 169 } else if (action .equals("admin")) {176 } else if (action == Action.admin) { 170 177 // require at least an authenticated user 171 178 if (user == null) return false; -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java
r102 r105 42 42 43 43 import de.mpiwg.itgroup.annotations.Annotation; 44 import de.mpiwg.itgroup.annotations.Annotation.Action; 44 45 import de.mpiwg.itgroup.annotations.Person; 45 46 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; … … 95 96 Annotation annot = store.getAnnotationById(id); 96 97 if (annot != null) { 97 if (!annot.isActionAllowed( "read", authUser, store)) {98 if (!annot.isActionAllowed(Action.read, authUser, store)) { 98 99 setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!"); 99 100 return null; … … 116 117 for (Annotation annotation : annotations) { 117 118 // check permission 118 if (!annotation.isActionAllowed( "read", authUser, store))119 if (!annotation.isActionAllowed(Action.read, authUser, store)) 119 120 continue; 120 121 // add annotation to list … … 238 239 return null; 239 240 } 240 if (!storedAnnot.isActionAllowed( "update", authUser, store)) {241 if (!storedAnnot.isActionAllowed(Action.update, authUser, store)) { 241 242 setStatus(Status.CLIENT_ERROR_FORBIDDEN); 242 243 return null; … … 287 288 Annotation annot = store.getAnnotationById(id); 288 289 if (annot != null) { 289 if (!annot.isActionAllowed( "delete", authUser, store)) {290 if (!annot.isActionAllowed(Action.delete, authUser, store)) { 290 291 setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!"); 291 292 return null; -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByResources.java
r91 r105 39 39 40 40 import de.mpiwg.itgroup.annotations.Annotation; 41 import de.mpiwg.itgroup.annotations.Annotation.Action; 41 42 import de.mpiwg.itgroup.annotations.Person; 42 43 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; … … 90 91 for (Annotation annot : annotations) { 91 92 // check permission 92 if (!annot.isActionAllowed( "read", authUser, store))93 if (!annot.isActionAllowed(Action.read, authUser, store)) 93 94 continue; 94 95 -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotationsByTags.java
r91 r105 38 38 39 39 import de.mpiwg.itgroup.annotations.Annotation; 40 import de.mpiwg.itgroup.annotations.Annotation.Action; 40 41 import de.mpiwg.itgroup.annotations.Person; 41 42 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; … … 79 80 for (Annotation annot : annotations) { 80 81 // check permission 81 if (!annot.isActionAllowed( "read", authUser, store))82 if (!annot.isActionAllowed(Action.read, authUser, store)) 82 83 continue; 83 84 -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorResourceImpl.java
r102 r105 57 57 import de.mpiwg.itgroup.annotations.Actor; 58 58 import de.mpiwg.itgroup.annotations.Annotation; 59 import de.mpiwg.itgroup.annotations.Annotation.Action; 59 60 import de.mpiwg.itgroup.annotations.Annotation.FragmentTypes; 60 61 import de.mpiwg.itgroup.annotations.Group; … … 680 681 * permissions 681 682 */ 682 if (jo.has("permissions")) { 683 JSONObject permissions = jo.getJSONObject("permissions"); 684 if (permissions.has("admin")) { 685 JSONArray perms = permissions.getJSONArray("admin"); 686 Actor actor = getActorFromPermissions(perms); 687 annot.setAdminPermission(actor); 688 } 689 if (permissions.has("delete")) { 690 JSONArray perms = permissions.getJSONArray("delete"); 691 Actor actor = getActorFromPermissions(perms); 692 annot.setDeletePermission(actor); 693 } 694 if (permissions.has("update")) { 695 JSONArray perms = permissions.getJSONArray("update"); 696 Actor actor = getActorFromPermissions(perms); 697 annot.setUpdatePermission(actor); 698 } 699 if (permissions.has("read")) { 700 JSONArray perms = permissions.getJSONArray("read"); 701 Actor actor = getActorFromPermissions(perms); 702 annot.setReadPermission(actor); 703 } 704 } 683 if (jo.has("permissions")) { 684 // change permissions only if user has admin permission 685 if (annot.isActionAllowed(Action.admin, authUser, getAnnotationStore())) { 686 JSONObject permissions = jo.getJSONObject("permissions"); 687 if (permissions.has("admin")) { 688 JSONArray perms = permissions.getJSONArray("admin"); 689 Actor actor = getActorFromPermissions(perms); 690 annot.setAdminPermission(actor); 691 } 692 if (permissions.has("delete")) { 693 JSONArray perms = permissions.getJSONArray("delete"); 694 Actor actor = getActorFromPermissions(perms); 695 annot.setDeletePermission(actor); 696 } 697 if (permissions.has("update")) { 698 JSONArray perms = permissions.getJSONArray("update"); 699 Actor actor = getActorFromPermissions(perms); 700 annot.setUpdatePermission(actor); 701 } 702 if (permissions.has("read")) { 703 JSONArray perms = permissions.getJSONArray("read"); 704 Actor actor = getActorFromPermissions(perms); 705 annot.setReadPermission(actor); 706 } 707 } 708 } 705 709 706 710 /* -
src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorSearch.java
r91 r105 36 36 37 37 import de.mpiwg.itgroup.annotations.Annotation; 38 import de.mpiwg.itgroup.annotations.Annotation.Action; 38 39 import de.mpiwg.itgroup.annotations.Person; 39 40 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; … … 77 78 for (Annotation annot : annots) { 78 79 // check permission 79 if (!annot.isActionAllowed( "read", authUser, store)) continue;80 if (!annot.isActionAllowed(Action.read, authUser, store)) continue; 80 81 JSONObject jo = createAnnotatorJson(annot, (authUser == null)); 81 82 if (jo != null) {
Note: See TracChangeset
for help on using the changeset viewer.