# HG changeset patch # User dwinter # Date 1322131152 -3600 # Node ID 6888ae3287b8b9edd5f672ae86b0b4cda3b33bfd # Parent f2f41d0dedf5880c0bad59ec184b159fb6c7c3b7 changed to namespace handling for users diff -r f2f41d0dedf5 -r 6888ae3287b8 .project --- a/.project Wed Nov 23 15:26:33 2011 +0100 +++ b/.project Thu Nov 24 11:39:12 2011 +0100 @@ -36,4 +36,11 @@ org.eclipse.jdt.core.javanature org.eclipse.wst.jsdt.core.jsNature + + + docs/annotations.owl + 1 + PARENT-1-PROJECT_LOC/NamedIdentityManager/ontologies/annotations.owl + + diff -r f2f41d0dedf5 -r 6888ae3287b8 WebContent/WEB-INF/web.xml.template --- a/WebContent/WEB-INF/web.xml.template Wed Nov 23 15:26:33 2011 +0100 +++ b/WebContent/WEB-INF/web.xml.template Thu Nov 24 11:39:12 2011 +0100 @@ -11,11 +11,16 @@ de.mpiwg.itgroup.annotationManager.restlet.RestServer + +de.mpiwg.itgroup.annotationManager.jaas.configFilePath +file:///etc/jaasAuth.conf + de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUser USERNAME + de.mpiwg.itgroup.annotationManager.virtuoso.tripleStoreUserPassword PASSWORD diff -r f2f41d0dedf5 -r 6888ae3287b8 src/de/mpiwg/itgroup/annotationManager/Constants/NS.java --- a/src/de/mpiwg/itgroup/annotationManager/Constants/NS.java Wed Nov 23 15:26:33 2011 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/Constants/NS.java Thu Nov 24 11:39:12 2011 +0100 @@ -1,6 +1,7 @@ package de.mpiwg.itgroup.annotationManager.Constants; public class NS { + public static final String MPIWG_PERSONS = "http://www.mpiwg-berlin.mpg.de/en/staff/members/"; public static String ANNOTATION_TYPE="http://www.w3.org/2000/10/annotationType#"; public static String ANNOTATION_NS="http://www.w3.org/2000/10/annotation-ns#"; public static String RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"; diff -r f2f41d0dedf5 -r 6888ae3287b8 src/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java --- a/src/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java Wed Nov 23 15:26:33 2011 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/RDFHandling/Convert.java Thu Nov 24 11:39:12 2011 +0100 @@ -48,7 +48,27 @@ public String type=null; public String url; public List xpointers=null; // list of xpointers on the page url, can be empty or null if there is only one. + public String annotationUri=null; // uri der annotation im triplestore + + /** + * @param xpointer Beschreibt die Annotation + * @param creator Username des Creators oder URI der Creators + * @param time Erstellungszeit, wenn null wird das aktuelle Datum verwenden beim Konvertieren + * @param text der Annotation + * @param type Annotationstype (Entsprechend den in http://www.w3.org/2000/10/annotationType# definierten.) + * @param url Url einer Annotation + * @param annotationUri Uri der Annotation im Triplestore + */ + public Annotation(String xpointer, String creator, String time, String text, String type, String url,String annotationUri){ + this.xpointer=xpointer; + this.creator=creator; + this.time=time; + this.text=text; + this.type=type; + this.url=url; + this.annotationUri=annotationUri; + } /** * @param xpointer Beschreibt die Annotation * @param creator Username des Creators @@ -120,7 +140,13 @@ retQuad.add(new Quadruple(annotation, NS.RDF+"type", NS.ANNOTATION_TYPE+annot.type, ctx)); //add author - retQuad.add(new LiteralQuadruple(annotation, NS.ANNOTATION_NS+"author", annot.creator, ctx)); + + + if (annot.creator.startsWith("http")){ + retQuad.add(new Quadruple(annotation, NS.ANNOTATION_NS+"author", annot.creator, ctx)); + } else { + retQuad.add(new LiteralQuadruple(annotation, NS.ANNOTATION_NS+"author", annot.creator, ctx)); + } // creation time retQuad.add(new LiteralQuadruple(annotation, NS.ANNOTATION_NS+"created", annot.time, ctx)); @@ -133,7 +159,7 @@ } // now add the xpointers - retQuad.add(new Quadruple(annotation, NS.MPIWG_annot+"docuviewerText", xpointerSplitted[0], ctx)); + retQuad.add(new Quadruple(annotation, NS.MPIWG_annot+"annotatesDocuviewerText", xpointerSplitted[0], ctx)); retQuad.add(new Quadruple(annotation, NS.MPIWG_annot+"textSelection", annot.xpointer, ctx)); String annotationtext =createRessourceURL("annotText:"); diff -r f2f41d0dedf5 -r 6888ae3287b8 src/de/mpiwg/itgroup/annotationManager/RDFHandling/RDFSearcher.java --- a/src/de/mpiwg/itgroup/annotationManager/RDFHandling/RDFSearcher.java Wed Nov 23 15:26:33 2011 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/RDFHandling/RDFSearcher.java Thu Nov 24 11:39:12 2011 +0100 @@ -10,6 +10,8 @@ import org.restlet.Context; import org.restlet.engine.component.ChildContext; +import sun.security.action.GetBooleanAction; + import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreSearchError; import de.mpiwg.itgroup.annotationManager.RDFHandling.Convert.Annotation; import de.mpiwg.itgroup.nimanager.exceptions.TripleStoreHandlerException; @@ -31,6 +33,15 @@ + /** Sucht im Triplestore nach Annotationen + * @param uri Adresse der Annotierten Ressource, in der Regel nicht mit dem xpointer, sonder die URI der kompletten Ressource oder NULL oder leer + * @param user Author der Annotationen, entweder als uri der Person oder ein Username, je nachdem wie die Annotatinen angelegt wurden. + * @param limit + * @param offset + * @return + * @throws TripleStoreHandlerException + * @throws TripleStoreSearchError + */ public List search(String uri, String user, String limit, String offset) throws TripleStoreHandlerException, TripleStoreSearchError { @@ -46,15 +57,19 @@ //whereString +="?s ?link."; if(uri!=null && !uri.equals("")){ - whereString +=String.format("?s <%s>.",uri);} + whereString +=String.format("?s <%s>.",uri);} else { - whereString +=String.format("?s ?uri."); + whereString +=String.format("?s ?uri."); } whereString +=String.format("?s ?xpointer."); whereString +=String.format("?s ?annotText."); if(user!=null && !user.equals("")){ - whereString +=String.format("?s \"%s\".",user); + if (user.startsWith("http")){ + whereString +=String.format("?s <%s>.",user); + } else { + whereString +=String.format("?s \"%s\".",user); + } } else { whereString +=String.format("?s ?author."); } @@ -91,7 +106,7 @@ Annotation annot = new Annotation(result.getBinding("xpointer").getValue().stringValue(), annotUser, result.getBinding("created").getValue().stringValue(), result.getBinding("text").getValue().stringValue(), null, - annotUri); + annotUri,result.getBinding("s").getValue().stringValue()); retAnnots.add(annot); } } catch (Exception e) { diff -r f2f41d0dedf5 -r 6888ae3287b8 src/de/mpiwg/itgroup/annotationManager/restlet/AddAndSearchAnnotations.java --- a/src/de/mpiwg/itgroup/annotationManager/restlet/AddAndSearchAnnotations.java Wed Nov 23 15:26:33 2011 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/restlet/AddAndSearchAnnotations.java Thu Nov 24 11:39:12 2011 +0100 @@ -28,6 +28,7 @@ import org.restlet.resource.ServerResource; import org.restlet.security.User; +import de.mpiwg.itgroup.annotationManager.Constants.NS; import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreSearchError; import de.mpiwg.itgroup.annotationManager.Errors.TripleStoreStoreError; import de.mpiwg.itgroup.annotationManager.RDFHandling.Convert; @@ -65,8 +66,67 @@ responseHeaders.add("Access-Control-Max-Age", "60"); } + @Get("html") + public Representation doGetHTML(Representation entity){ + + doOptions(entity); + Form form = getRequest().getResourceRef().getQueryAsForm(); + String uri = form.getFirstValue("uri"); + String user = form.getFirstValue("user"); + + String limit=form.getFirstValue("limit"); + String offset=form.getFirstValue("offset"); + + +// + RDFSearcher searcher = new RDFSearcher("file:///annotations"); //TODO should ge into config file + + String retString=""; + String lineFormat="" + + ""; + try { + + List annots=searcher.search(uri,user,limit,offset); + + for (Convert.Annotation annot:annots){ + + + RestServer restServer = (RestServer) getApplication(); + String userName=restServer.getUserNameFromLdap(annot.creator); + List xpointer = new ArrayList(); + + if (annot.xpointers==null || annot.xpointers.size()==0) + retString+=String.format(lineFormat, userName,annot.url,annot.url,annot.time,annot.text,annot.xpointer,annot.xpointer,annot.annotationUri,annot.annotationUri); + else { + for(String xpointerString:annot.xpointers){ + retString+=String.format(lineFormat, userName,annot.url,annot.url,annot.time,annot.text,xpointerString,xpointerString,annot.annotationUri,annot.annotationUri); + + } + } + + } + } catch (TripleStoreHandlerException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + setStatus(Status.SERVER_ERROR_INTERNAL,"TripleStoreHandler Error"); + return null; + } catch (TripleStoreSearchError e) { + // TODO Auto-generated catch block + e.printStackTrace(); + setStatus(Status.SERVER_ERROR_INTERNAL,"TripleStoreSearch Error"); + return null; + } + + retString+="
%s%s%s%s%s%s
"; + + logger.debug("sending:"); + logger.debug(retString); + return new StringRepresentation(retString,MediaType.TEXT_HTML); + } + + @Get("json") - public Representation doGetHTML(Representation entity){ + public Representation doGetJSON(Representation entity){ doOptions(entity); Form form = getRequest().getResourceRef().getQueryAsForm(); @@ -95,7 +155,12 @@ userObject.put("id",annot.creator); RestServer restServer = (RestServer) getApplication(); - String userName=restServer.getUserNameFromLdap(annot.creator); + + String userID= annot.creator; + if (userID.startsWith(NS.MPIWG_PERSONS)){ + userID=userID.replace(NS.MPIWG_PERSONS, ""); //entferne NAMESPACE + } + String userName=restServer.getUserNameFromLdap(userID); userObject.put("name",userName); jo.put("user",userObject); @@ -302,6 +367,19 @@ } } + + /** + * + * @param entity should contain a form with the parameters "username", "password", "xpointer","text","uri","type" + * + * username,password is optional, if not given BasicAuthentification is used. + * + * + * + * If username given as a URI, the username will be transformed to an URI, username will be added to the MPIWG namespace defined in de.mpiwg.itgroup.annotationManager.Constants.NS + * + * @return + */ protected Convert.Annotation handleForm(Representation entity) { Convert.Annotation annot; Form form = new Form(entity); @@ -338,6 +416,10 @@ username = authUser.getIdentifier(); } + //username should be a URI, if not it will set to the MPIWG namespace defined in de.mpiwg.itgroup.annotationManager.Constants.NS + if (!username.startsWith("http")) + username=NS.MPIWG_PERSONS+username; + annot = new Convert.Annotation(xpointer, username, null, text, type, url); return annot; @@ -370,6 +452,8 @@ * be used. * @param authUser * user object + * The username will be transformed to an URI if not given already as URI, if not it will set to the MPIWG namespace defined in de.mpiwg.itgroup.annotationManager.Constants.NS + * @return * @throws JSONException */ @@ -396,6 +480,10 @@ if (username == null) username = authUser.getIdentifier(); + //username should be a URI, if not it will set to the MPIWG namespace defined in de.mpiwg.itgroup.annotationManager.Constants.NS + if (!username.startsWith("http")) + username=NS.MPIWG_PERSONS+username; + return new Convert.Annotation(xpointer, username, null, text, type, url); } @@ -410,7 +498,7 @@ * basic * authentification * is used. - * + * The username will be transformed to an URI if not given already as URI, if not it will set to the MPIWG namespace defined in de.mpiwg.itgroup.annotationManager.Constants.NS * @param jo * @param authUser * @return @@ -476,6 +564,11 @@ } else { xpointer = url; } + + //username should be a URI, if not it will set to the MPIWG namespace defined in de.mpiwg.itgroup.annotationManager.Constants.NS + if (!username.startsWith("http")) + username=NS.MPIWG_PERSONS+username; + return new Convert.Annotation(xpointer, username, null, text, null); } diff -r f2f41d0dedf5 -r 6888ae3287b8 src/de/mpiwg/itgroup/annotationManager/restlet/RestServer.java --- a/src/de/mpiwg/itgroup/annotationManager/restlet/RestServer.java Wed Nov 23 15:26:33 2011 +0100 +++ b/src/de/mpiwg/itgroup/annotationManager/restlet/RestServer.java Thu Nov 24 11:39:12 2011 +0100 @@ -32,6 +32,7 @@ import org.restlet.data.ChallengeScheme; import org.restlet.data.ClientInfo; +import org.restlet.engine.component.ChildContext; import org.restlet.ext.jaas.JaasVerifier; import org.restlet.routing.Router; import org.restlet.routing.Template; @@ -62,10 +63,6 @@ ChallengeScheme challengeScheme = ChallengeScheme.HTTP_BASIC; String realm = "Annotation Service"; - // MapVerifier isn't very secure; see docs for alternatives - //MapVerifier verifier = new MapVerifier(); - //verifier.getLocalSecrets().put("user", "password".toCharArray()); - JaasVerifier verifier = new JaasVerifier("BasicJaasAuthenticationApplication"); @@ -90,11 +87,21 @@ return auth; } + /** + * Konfiguration fŸr den Authentificator in Jaas. Pfad zum JAAS-Konfigurationsfile liegt im Context-Parameter + * "de.mpiwg.itgroup.annotationManager.jaas.configFilePath". + * @return + */ protected Configuration createConfiguration() { Configuration jaasConfig; URI confUri; + + Context context = getContext(); + String configFilePath = context.getParameters().getFirstValue("de.mpiwg.itgroup.annotationManager.jaas.configFilePath"); + + try { - confUri = new URI("file:///etc/jaasAuth.conf"); //TODO shoould be configurable + confUri = new URI(configFilePath); } catch (URISyntaxException e) { e.printStackTrace(); confUri = null; @@ -131,7 +138,13 @@ } - public boolean authenticate(Request request, Response response) { + /** + * Authentifiziere den Benutzer aus dem Request (BasicAuthenfication) + * @param request + * @param response + * @return + */ + public boolean authenticate(Request request, Response response) { if (!request.getClientInfo().isAuthenticated()) { authenticator.challenge(response, false); return false; @@ -142,9 +155,19 @@ authenticator.challenge(response, false); return false; } + + return true; } + /** + * Authentifiziere den Benutzer + * + * @param username + * @param password + * @param request + * @return + */ public boolean authenticate(String username, String password,Request request) { LoginContext lc; @@ -169,6 +192,11 @@ return true; } + /** + * Hole den vollen Benutzernamen aus dem LDAP + * @param creator + * @return + */ public String getUserNameFromLdap(String creator) { String retString=creator; // falls nichts gefunden wird einfach den creator zurueckgeben Hashtable env = new Hashtable();