comparison src/main/java/de/mpiwg/itgroup/annotations/restlet/AnnotatorAnnotations.java @ 88:b406507a953d

upped version to 0.5. can use display name and groups from auth token.
author casties
date Tue, 03 Feb 2015 19:01:27 +0100
parents 25eb2e1df106
children cf44d9e1a4a7
comparison
equal deleted inserted replaced
87:2beafb8e19e4 88:b406507a953d
1 /**
2 * Implements the "annotations" uri of the Annotator API. see
3 * <https://github.com/okfn/annotator/wiki/Storage>
4 */
5 package de.mpiwg.itgroup.annotations.restlet; 1 package de.mpiwg.itgroup.annotations.restlet;
6 2
7 /* 3 /*
8 * #%L 4 * #%L
9 * AnnotationManager 5 * AnnotationManager
85 id = decodeJsonId(jsonId); 81 id = decodeJsonId(jsonId);
86 logger.fine("annotation-id=" + id); 82 logger.fine("annotation-id=" + id);
87 } 83 }
88 84
89 // do authentication 85 // do authentication
90 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); 86 Person authUser = getUserFromAuthToken(entity);
91 logger.fine("request authenticated=" + authUser); 87 logger.fine("request authenticated=" + authUser);
92 88
93 if (id == null) { 89 if (id == null) {
94 // no id -- send all annotations 90 // no id -- send all annotations
95 Form form = getRequest().getResourceRef().getQueryAsForm(); 91 Form form = getRequest().getResourceRef().getQueryAsForm();
170 logger.fine("AnnotatorAnnotations doPostJSON!"); 166 logger.fine("AnnotatorAnnotations doPostJSON!");
171 // set headers 167 // set headers
172 setCorsHeaders(); 168 setCorsHeaders();
173 169
174 // do authentication TODO: who's allowed to create? 170 // do authentication TODO: who's allowed to create?
175 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); 171 Person authUser = getUserFromAuthToken(entity);
176 logger.fine("request authenticated=" + authUser); 172 logger.fine("request authenticated=" + authUser);
177 if (authUser == null) { 173 if (authUser == null) {
178 setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!"); 174 setStatus(Status.CLIENT_ERROR_FORBIDDEN, "Not Authorized!");
179 return null; 175 return null;
180 } 176 }
187 setStatus(Status.SERVER_ERROR_INTERNAL); 183 setStatus(Status.SERVER_ERROR_INTERNAL);
188 return null; 184 return null;
189 } 185 }
190 // make sure id is not set for POST 186 // make sure id is not set for POST
191 jo.remove("id"); 187 jo.remove("id");
192 // get Annotation object from posted JSON 188 // create Annotation object from posted JSON
193 annot = createAnnotation(jo, entity); 189 annot = createAnnotation(jo, entity);
194 } catch (IOException e1) { 190 } catch (IOException e1) {
195 setStatus(Status.SERVER_ERROR_INTERNAL); 191 setStatus(Status.SERVER_ERROR_INTERNAL);
196 return null; 192 return null;
197 } catch (JSONException e) { 193 } catch (JSONException e) {
228 String jsonId = (String) getRequest().getAttributes().get("id"); 224 String jsonId = (String) getRequest().getAttributes().get("id");
229 String id = decodeJsonId(jsonId); 225 String id = decodeJsonId(jsonId);
230 logger.fine("annotation-id=" + id); 226 logger.fine("annotation-id=" + id);
231 227
232 // do authentication 228 // do authentication
233 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); 229 Person authUser = getUserFromAuthToken(entity);
234 logger.fine("request authenticated=" + authUser); 230 logger.fine("request authenticated=" + authUser);
235 231
236 Annotation annot = null; 232 Annotation annot = null;
237 AnnotationStore store = getAnnotationStore(); 233 AnnotationStore store = getAnnotationStore();
238 try { 234 try {
291 String jsonId = (String) getRequest().getAttributes().get("id"); 287 String jsonId = (String) getRequest().getAttributes().get("id");
292 String id = decodeJsonId(jsonId); 288 String id = decodeJsonId(jsonId);
293 logger.fine("annotation-id=" + id); 289 logger.fine("annotation-id=" + id);
294 290
295 // do authentication 291 // do authentication
296 Person authUser = Person.createPersonWithId(this.checkAuthToken(entity)); 292 Person authUser = getUserFromAuthToken(entity);
297 logger.fine("request authenticated=" + authUser); 293 logger.fine("request authenticated=" + authUser);
298 AnnotationStore store = getAnnotationStore(); 294 AnnotationStore store = getAnnotationStore();
299 Annotation annot = store.getAnnotationById(id); 295 Annotation annot = store.getAnnotationById(id);
300 if (annot != null) { 296 if (annot != null) {
301 if (!annot.isActionAllowed("delete", authUser, store)) { 297 if (!annot.isActionAllowed("delete", authUser, store)) {