changeset 15:6c7c4140630d

on the way to updating annotations.
author casties
date Wed, 21 Mar 2012 18:12:45 +0100
parents 0f64de5fff5a
children 667d98fd28bd
files src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorAnnotations.java src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorResourceImpl.java src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorSearch.java src/de/mpiwg/itgroup/annotationManager/restlet/RestServer.java
diffstat 4 files changed, 21 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorAnnotations.java	Wed Mar 21 16:38:50 2012 +0100
+++ b/src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorAnnotations.java	Wed Mar 21 18:12:45 2012 +0100
@@ -52,11 +52,15 @@
     @Get("json")
     public Representation doGetJSON(Representation entity) {
         logger.debug("AnnotatorAnnotations doGetJSON!");
-        doOptions(entity);
+        setCorsHeaders();
+        // id from URI /annotations/{id}
+        String id = (String) getRequest().getAttributes().get("id");
+        logger.debug("annotation-id="+id);
+
         // TODO: what to do with authentication?
         boolean authenticated = isAuthenticated(entity);
         logger.debug("request authenticated=" + authenticated);
-
+        
         // TODO: Annotator read request does not use parameters
         Form form = getRequest().getResourceRef().getQueryAsForm();
         String uri = form.getFirstValue("uri");
--- a/src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorResourceImpl.java	Wed Mar 21 16:38:50 2012 +0100
+++ b/src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorResourceImpl.java	Wed Mar 21 18:12:45 2012 +0100
@@ -144,9 +144,10 @@
         String computedToken = getSha256Digest(consumerSecret + userId + issueTime);
         // compare to the token we got
         String authToken = requestHeaders.getFirstValue("x-annotator-auth-token", true);
-        logger.debug(String.format("got: authToken=%s consumerSecret=%s userId=%s issueTime=%s", authToken, consumerSecret, userId,
-                issueTime));
-        if (!computedToken.equals(authToken)) {
+        logger.debug(String.format("got: authToken=%s consumerSecret=%s userId=%s issueTime=%s computedToken=%s", 
+                authToken, consumerSecret, userId, issueTime, computedToken));
+        if (!computedToken.equalsIgnoreCase(authToken)) {
+            logger.warn("authToken differ!");
             return null;
         }
         // check token lifetime
@@ -164,10 +165,13 @@
         } catch (NumberFormatException e) {
             e.printStackTrace();
         }
-        if (tokenValidity == null || tokenValidity.isAfterNow() || tokenExpiry.isBeforeNow()) {
-            return null;
+        if (tokenValidity == null || tokenValidity.isAfterNow() || tokenExpiry == null || tokenExpiry.isBeforeNow()) {
+            logger.warn(String.format("authToken invalid! tokenValidity=%s tokenExpiry=%s now=%s", tokenValidity, tokenExpiry, DateTime.now()));
+            // we dont care about validity right now
+            //return null;
         }
         // must be ok then
+        logger.debug("auth OK! user="+userId);
         return userId;
     }
 
--- a/src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorSearch.java	Wed Mar 21 16:38:50 2012 +0100
+++ b/src/de/mpiwg/itgroup/annotationManager/restlet/AnnotatorSearch.java	Wed Mar 21 18:12:45 2012 +0100
@@ -47,8 +47,8 @@
      */
     @Get("json")
     public Representation doGetJSON(Representation entity) {
-
-        doOptions(entity);
+        logger.debug("AnnotatorSearch doGetJSON!");
+        setCorsHeaders();
         //TODO: what to do with authentication? 
         boolean authenticated = isAuthenticated(entity);
         logger.debug("request authenticated="+authenticated);
@@ -110,7 +110,7 @@
      */
     @Get("html")
     public Representation doGetHTML(Representation entity) {
-
+        logger.debug("AnnotatorSearch doGetHTML!");
         doOptions(entity);
         Form form = getRequest().getResourceRef().getQueryAsForm();
         String uri = form.getFirstValue("uri");
--- a/src/de/mpiwg/itgroup/annotationManager/restlet/RestServer.java	Wed Mar 21 16:38:50 2012 +0100
+++ b/src/de/mpiwg/itgroup/annotationManager/restlet/RestServer.java	Wed Mar 21 18:12:45 2012 +0100
@@ -187,12 +187,9 @@
         Router router = new Router(getContext());
 
         router.attach("/annotator/annotations", AnnotatorAnnotations.class);
-        router.attach("/annotator/search", AnnotatorSearch.class); // annotator api askes
-                                                         // for different uris
-                                                         // for search and
-                                                         // adding
-        // router.attach("/search",SearchAnnotations.class); // annotator api
-        // askes for different uris for search and adding
+        router.attach("/annotator/annotations/{id}", AnnotatorAnnotations.class);
+        router.attach("/annotator/search", AnnotatorSearch.class);
+        
         router.attach("/dummy", Dummy.class);
 
         // router.attach("",redirector);