From: Richard Millet Date: Wed, 29 Apr 2009 06:11:54 +0000 (+0000) Subject: CSPACE-84: Created a new source structure for all services. Moved v0.1 CollectionObj... X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=5e686e71ba3b9fe87e78785816f129e8199ee46b;p=tmp%2Fjakarta-migration.git CSPACE-84: Created a new source structure for all services. Moved v0.1 CollectionObject service to this new structure. --- diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/build.properties b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/build.properties new file mode 100644 index 000000000..c26799aa9 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/build.properties @@ -0,0 +1,15 @@ +# Example for Windows +jboss.dir=c:/dev/jboss-4.2.3.GA +# Example for Unix +#jboss.dir=/opt/jboss + +# Which JBoss server config to use +jboss.config=default + +# nuxeo deployment +jboss.nuxeo.ear.dir=${jboss.dir}/server/${jboss.config}/deploy/nuxeo.ear + + +# additional command line parameters for mvn commands +# e.g. to work offline: +#mvn.opts=-o diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/build.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/build.xml new file mode 100644 index 000000000..d4e3b266c --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/build.xml @@ -0,0 +1,14 @@ + + + + + + + + + + + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/pom.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/pom.xml new file mode 100644 index 000000000..540859ee7 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/pom.xml @@ -0,0 +1,30 @@ + + 4.0.0 + + + org.nuxeo.ecm.platform + nuxeo-platform-parent + 5.2-SNAPSHOT + + + nuxeo-platform-collectionspace + jar + Nuxeo CS extensions + + Nuxeo Enterprise Platform: CS extensions + + + + + org.nuxeo.ecm.core + nuxeo-core-schema + + + org.nuxeo.ecm.platform + nuxeo-platform-types-core + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/META-INF/MANIFEST.MF b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 000000000..91c534186 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,22 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 1 +Bundle-Name: NuxeoCS +Bundle-SymbolicName: org.collectionspace.collectionobject;singleton:=true +Bundle-Version: 1.0.0 +Bundle-Localization: plugin +Bundle-Vendor: Nuxeo +Require-Bundle: org.nuxeo.runtime, + org.nuxeo.ecm.core.api, + org.nuxeo.ecm.core, + org.nuxeo.ecm.core.api, + org.nuxeo.ecm.platform.types.api, + org.nuxeo.ecm.platform.versioning.api, + org.nuxeo.ecm.platform.ui, + org.nuxeo.ecm.platform.forms.layout.client, + org.nuxeo.ecm.platform.publishing.api, + org.nuxeo.ecm.platform.ws +Provide-Package: org.collectionspace.collectionobject +Nuxeo-Component: OSGI-INF/core-types-contrib.xml, + OSGI-INF/ecm-types-contrib.xml, + OSGI-INF/layouts-contrib.xml + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/core-types-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/core-types-contrib.xml new file mode 100644 index 000000000..72aa5ef19 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/core-types-contrib.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/deployment-fragment.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/deployment-fragment.xml new file mode 100644 index 000000000..88b94ffd1 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/deployment-fragment.xml @@ -0,0 +1,408 @@ + + + + + + ${bundle.fileName} + + + + + nuxeo.war + /nuxeo + + + + + + + + + + + + Seam Context Filter + /ws/FileManageWS + + + + Seam Context Filter + /DocumentManagerWS + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + #{currentServerLocation.name}/#{currentTabAction.label} + + + + Create new document in #{currentDocument.name} + + + + Create new document in #{currentDocument.name} + + + + breadcrumb=command.user_dashboard + + + + breadcrumb=command.manageMembers + + + + breadcrumb=command.manageMembers + + + + breadcrumb=title.vocabularies + + + + breadcrumb=command.advancedSearch + + + + + + en + en_GB + en_US + fr + de + es + it + ar + ru + ja + vn + + + messages + + + + config/addWorkspace.jpdl.xml + + + + + + generic_error_page + /generic_error_page.xhtml + + + + + generic_message_page + /generic_message_page.xhtml + + + + + home + /nxstartup.xhtml + + + + + user_login + /login.xhtml + + + + + user_logout + /logout.xhtml + + + + + view_servers + /view_servers.xhtml + + + + + + + view_domains + /view_domains.xhtml + + + + + select_document_type + /select_document_type.xhtml + + + + + create_document + /create_document.xhtml + + + + + edit_document + /edit_document.xhtml + + + + + view_documents + /view_documents.xhtml + + + + + create_file + /create_file.xhtml + + + + + create_workspace_wizard + /createWorkspaceWizard.xhtml + + + + + send_email + /document_email.xhtml + + + + + + view_workspaces + /view_workspaces.xhtml + + + + + + create_domain + /create_domain.xhtml + + + + + + edit_domain + /edit_domain.xhtml + + + + + + create_workspace + /create_workspace.xhtml + + + + + + edit_workspace + /edit_workspace.xhtml + + + + + + + members_management + /members_management.xhtml + + + + + view_users + /view_users.xhtml + + + + + view_many_users + /view_many_users.xhtml + + + + + edit_user + /edit_user.xhtml + + + + + edit_user_password + /edit_user_password.xhtml + + + + + view_user + /view_user.xhtml + + + + + create_user + /create_user.xhtml + + + + + view_groups + /view_groups.xhtml + + + + + view_group + /view_group.xhtml + + + + + edit_group + /edit_group.xhtml + + + + + create_group + /create_group.xhtml + + + + + view_vocabularies + /view_vocabularies.xhtml + + + + + view_vocabulary + /view_vocabulary.xhtml + + + + + + + search_form + /search/search_form.xhtml + + + + + search_results_nxql + /search/search_results_nxql.xhtml + + + + + search_results_advanced + + /search/search_results_advanced.xhtml + + + + + + search_results_simple + /search/search_results_simple.xhtml + + + + + + + clipboard + /incl/clipboard.xhtml + + + + + user_dashboard + /user_dashboard.xhtml + + + + + select_workspace_template + /select_workspace_template.xhtml + + + + + pdf_generation_error + /pdf_generation_error.xhtml + + + + + mass_edit + /massedit_documents.xhtml + + + + + mass_edit_confirm + /massedit_documents_preview.xhtml + + + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/ecm-types-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/ecm-types-contrib.xml new file mode 100644 index 000000000..541251f1e --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/ecm-types-contrib.xml @@ -0,0 +1,28 @@ + + + + + + + view_documents + + + heading + collectionobject + + + + + + CollectionObject + + + + + + CollectionObject + + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/layouts-contrib.xml b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/layouts-contrib.xml new file mode 100644 index 000000000..ee35a77d4 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/OSGI-INF/layouts-contrib.xml @@ -0,0 +1,129 @@ + + + + + + + + + + + + objectNumber + otherNumber + briefDescription + comments + distFeatures + objectName + responsibleDept + title + + + + + + + true + + objectNumber + + + dataInputText + + + + + + + + true + + otherNumber + + + dataInputText + + + + + + + + true + + briefDescription + + + dataInputText + + + + + + + + true + + comments + + + dataInputText + + + + + + + + true + + distFeatures + + + dataInputText + + + + + + + + true + + objectName + + + dataInputText + + + + + + + + true + + responsibleDept + + + dataInputText + + + + + + + + true + + title + + + dataInputText + + + + + + diff --git a/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/schemas/collectionobject.xsd b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/schemas/collectionobject.xsd new file mode 100644 index 000000000..d37b63e13 --- /dev/null +++ b/services/collectionobject/3rdparty/nuxeo-platform-cs-collectionobject/src/main/resources/schemas/collectionobject.xsd @@ -0,0 +1,18 @@ + + + + + + + + + + + + + diff --git a/services/collectionobject/jaxb/.classpath b/services/collectionobject/jaxb/.classpath new file mode 100644 index 000000000..a92b24a87 --- /dev/null +++ b/services/collectionobject/jaxb/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/services/collectionobject/jaxb/.project b/services/collectionobject/jaxb/.project new file mode 100644 index 000000000..db1c789f7 --- /dev/null +++ b/services/collectionobject/jaxb/.project @@ -0,0 +1,23 @@ + + + javaee-addressbook-jaxb + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.maven.ide.eclipse.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.maven.ide.eclipse.maven2Nature + + diff --git a/services/collectionobject/jaxb/.settings/org.eclipse.jdt.core.prefs b/services/collectionobject/jaxb/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..8780c51c5 --- /dev/null +++ b/services/collectionobject/jaxb/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,5 @@ +#Thu Feb 26 16:32:52 PST 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.source=1.5 diff --git a/services/collectionobject/jaxb/.settings/org.maven.ide.eclipse.prefs b/services/collectionobject/jaxb/.settings/org.maven.ide.eclipse.prefs new file mode 100644 index 000000000..c6e4123cd --- /dev/null +++ b/services/collectionobject/jaxb/.settings/org.maven.ide.eclipse.prefs @@ -0,0 +1,8 @@ +#Thu Feb 26 16:30:28 PST 2009 +activeProfiles= +eclipse.preferences.version=1 +fullBuildGoals=process-test-resources +includeModules=false +resolveWorkspaceProjects=true +resourceFilterGoals=process-resources resources\:testResources +version=1 diff --git a/services/collectionobject/jaxb/pom.xml b/services/collectionobject/jaxb/pom.xml new file mode 100644 index 000000000..2db18b9d0 --- /dev/null +++ b/services/collectionobject/jaxb/pom.xml @@ -0,0 +1,119 @@ + + + + + + 4.0.0 + org.collectionspace.services + collectionobject-jaxb + 0.1 + CollectionObject Service JAXB + + + + java.net + java.net Maven Repository + https://maven-repository.dev.java.net/nonav/repository + legacy + + + maven2-repository.dev.java.net + Java.net Maven 2 Repository + http://download.java.net/maven/2 + + + + + + com.sun.xml.bind + jaxb-impl + 2.0.2 + + + org.jvnet.jaxb2-commons + property-listener-injector + 1.0 + + + org.jvnet.jaxb2_commons + runtime + 0.4.1.4 + + + + install + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + generate + + + + + + + javax.activation + activation + 1.1 + + + com.sun.xml.bind + jaxb-impl + 2.1.2 + + + + + -XtoString + -Xinject-listener-code + + + + + + + org.jvnet.jaxb2_commons + + basic + 0.4.1 + + + + org.jvnet.jaxb2-commons + + + property-listener-injector + + 1.0 + + + + + + + + maven-compiler-plugin + 2.0.2 + + 1.5 + 1.5 + + + + + diff --git a/services/collectionobject/jaxb/src/main/java/org/collectionspace/services/CollectionObjectJAXBSchema.java b/services/collectionobject/jaxb/src/main/java/org/collectionspace/services/CollectionObjectJAXBSchema.java new file mode 100644 index 000000000..721e439f4 --- /dev/null +++ b/services/collectionobject/jaxb/src/main/java/org/collectionspace/services/CollectionObjectJAXBSchema.java @@ -0,0 +1,21 @@ +/** + * + */ +package org.collectionspace.services; + +/** + * @author remillet + * + */ +public interface CollectionObjectJAXBSchema { + final static String OBJECT_NUMBER = "objectNumber"; + final static String OTHER_NUMBER = "otherNumber"; + final static String BRIEF_DESCRIPTION = "briefDescription"; + final static String COMMENTS = "comments"; + final static String DIST_FEATURES = "distFeatures"; + final static String OBJECT_NAME = "objectName"; + final static String RESPONSIBLE_DEPT = "responsibleDept"; + final static String TITLE = "title"; +} + + diff --git a/services/collectionobject/jaxb/src/main/java/org/collectionspace/services/CollectionObjectListItemJAXBSchema.java b/services/collectionobject/jaxb/src/main/java/org/collectionspace/services/CollectionObjectListItemJAXBSchema.java new file mode 100644 index 000000000..39a6b50a0 --- /dev/null +++ b/services/collectionobject/jaxb/src/main/java/org/collectionspace/services/CollectionObjectListItemJAXBSchema.java @@ -0,0 +1,7 @@ +package org.collectionspace.services; + +public interface CollectionObjectListItemJAXBSchema { + final static String OBJECT_NUMBER = "objectNumber"; + final static String CSID = "csid"; + final static String URI = "url"; +} diff --git a/services/collectionobject/jaxb/src/main/resources/collectionobject.xsd b/services/collectionobject/jaxb/src/main/resources/collectionobject.xsd new file mode 100644 index 000000000..bb9575e8b --- /dev/null +++ b/services/collectionobject/jaxb/src/main/resources/collectionobject.xsd @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/services/collectionobject/src/main/java/org/collectionspace/services/CollectionObjectResource.java b/services/collectionobject/src/main/java/org/collectionspace/services/CollectionObjectResource.java new file mode 100644 index 000000000..3b1c16001 --- /dev/null +++ b/services/collectionobject/src/main/java/org/collectionspace/services/CollectionObjectResource.java @@ -0,0 +1,374 @@ +package org.collectionspace.services; + +import java.io.ByteArrayInputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import java.util.Map; +import javax.ws.rs.DELETE; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.PathParam; +import javax.ws.rs.WebApplicationException; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.UriBuilder; +import javax.ws.rs.core.UriInfo; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.Marshaller; + +import org.collectionspace.*; +import org.collectionspace.services.nuxeo.NuxeoRESTClient; +import org.collectionspace.services.collectionobject.*; +import org.collectionspace.services.collectionobject.CollectionObjectList.*; +import org.collectionspace.services.CollectionObjectJAXBSchema; +import org.collectionspace.services.CollectionObjectListItemJAXBSchema; + +import org.dom4j.Document; +import org.dom4j.Element; +import org.dom4j.Namespace; +import org.dom4j.io.SAXReader; +import org.restlet.resource.Representation; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Path("/collectionobjects") +@Consumes("application/xml") +@Produces("application/xml") +public class CollectionObjectResource extends CollectionSpaceResource { + + final static String CO_NUXEO_DOCTYPE = "CollectionObject"; + final static String CO_NUXEO_SCHEMA_NAME = "collectionobject"; + final static String CO_NUXEO_DC_TITLE = "CollectionSpace-CollectionObject"; + + final Logger logger = LoggerFactory.getLogger(CollectionObjectResource.class); + + public CollectionObjectResource() { + // do nothing + } + + @GET + public CollectionObjectList getCollectionObjectList(@Context UriInfo ui) { + CollectionObjectList p = new CollectionObjectList(); + try{ + NuxeoRESTClient nxClient = getClient(); + + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + pathParams = Arrays.asList("default", CS_COLLECTIONOBJECT_WORKSPACE_UID, "browse"); + Representation res = nxClient.get(pathParams, queryParams); + SAXReader reader = new SAXReader(); + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + + //debug + System.err.println(res.toString()); + System.err.println(document.asXML()); + + List list = p.getCollectionObjectListItem(); + for(Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + //debug + System.err.println();element.asXML(); + + // set the CollectionObject list item entity elements + CollectionObjectListItem pli = new CollectionObjectListItem(); + pli.setObjectNumber(element.attributeValue("title")); + pli.setUri(element.attributeValue("url")); + pli.setCsid(element.attributeValue("id")); + list.add(pli); + } + + }catch(Exception e){ + e.printStackTrace(); + } + + return p; + } + + @POST + public Response createCollectionObject(CollectionObject co) { + + NuxeoRESTClient nxClient = getClient(); + + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + pathParams.add("default"); + pathParams.add(CS_COLLECTIONOBJECT_WORKSPACE_UID); + pathParams.add("createDocument"); + queryParams.put("docType", CO_NUXEO_DOCTYPE); + + // a default title for the Dublin Core schema + queryParams.put("dublincore:title", CO_NUXEO_DC_TITLE); + + // CollectionObject core values + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.OBJECT_NUMBER, + co.getObjectNumber()); + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.OTHER_NUMBER, + co.getOtherNumber()); + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.BRIEF_DESCRIPTION, + co.getBriefDescription()); + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.COMMENTS, + co.getComments()); + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.DIST_FEATURES, + co.getDistFeatures()); + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.OBJECT_NAME, + co.getObjectName()); + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.RESPONSIBLE_DEPT, + co.getResponsibleDept()); + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.TITLE, + co.getTitle()); + + ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); + Representation res = nxClient.post(pathParams, queryParams, bais); + + String csid = null; + SAXReader reader = new SAXReader(); + try { + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for (Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + if ("docRef".equals(element.getName())){ + csid = (String) element.getData(); + co.setCsid(csid); + } + } + } catch(Exception e){ + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Create failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + + + verbose("createCollectionObject: ", co); + UriBuilder path = UriBuilder.fromResource(CollectionObjectResource.class); + path.path("" + csid); + Response response = Response.created(path.build()).build(); + + return response; + } + + @GET + @Path("{csid}") + public CollectionObject getCollectionObject(@PathParam("csid") String csid) { + + CollectionObject co = null; + try { + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + + pathParams.add("default"); + pathParams.add(csid); + pathParams.add("export"); + queryParams.put("format", "XML"); + + NuxeoRESTClient nxClient = getClient(); + Representation res = nxClient.get(pathParams, queryParams); + + SAXReader reader = new SAXReader(); + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + co = new CollectionObject(); + + // TODO: recognize schema thru namespace uri +// Namespace ns = new Namespace("collectionobject", "http://collectionspace.org/collectionobject"); + + Iterator siter = root.elementIterator("schema"); + while (siter.hasNext()) { + + Element schemaElement = siter.next(); + System.err.println("CollectionObject.getCollectionObject() called."); + + //TODO: recognize schema thru namespace uri + if (CO_NUXEO_SCHEMA_NAME.equals(schemaElement.attribute("name").getValue())){ + Element ele = schemaElement.element(CollectionObjectJAXBSchema.OBJECT_NUMBER); + if(ele != null){ + co.setObjectNumber((String) ele.getData()); + } + ele = schemaElement.element(CollectionObjectJAXBSchema.OTHER_NUMBER); + if(ele != null){ + co.setOtherNumber((String) ele.getData()); + } + ele = schemaElement.element(CollectionObjectJAXBSchema.BRIEF_DESCRIPTION); + if(ele != null){ + co.setBriefDescription((String) ele.getData()); + } + ele = schemaElement.element(CollectionObjectJAXBSchema.COMMENTS); + if(ele != null){ + co.setComments((String) ele.getData()); + } + ele = schemaElement.element(CollectionObjectJAXBSchema.DIST_FEATURES); + if(ele != null){ + co.setDistFeatures((String) ele.getData()); + } + ele = schemaElement.element(CollectionObjectJAXBSchema.OBJECT_NAME); + if(ele != null){ + co.setObjectName((String) ele.getData()); + } + ele = schemaElement.element(CollectionObjectJAXBSchema.RESPONSIBLE_DEPT); + if(ele != null){ + co.setResponsibleDept((String) ele.getData()); + } + ele = schemaElement.element(CollectionObjectJAXBSchema.TITLE); + if(ele != null){ + co.setTitle((String) ele.getData()); + } + } + } + } catch(Exception e){ + e.printStackTrace(); + Response response = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( + "Get failed").type("text/plain").build(); + throw new WebApplicationException(response); + } + if (co == null) { + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Get failed, the requested CollectionObject CSID:" + csid + ": was not found.").type("text/plain").build(); + throw new WebApplicationException(response); + } + verbose("getCollectionObject: ", co); + + return co; + } + + @PUT + @Path("{csid}") + public CollectionObject updateCollectionObject( + @PathParam("csid") String csid, + CollectionObject theUpdate) { + + verbose("updateCollectionObject with input: ", theUpdate); + + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + pathParams.add("default"); + pathParams.add(csid); + pathParams.add("updateDocumentRestlet"); + + //todo: intelligent merge needed + if(theUpdate.getObjectNumber() != null){ + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.OBJECT_NUMBER, + theUpdate.getObjectNumber()); + } + + if(theUpdate.getOtherNumber() != null){ + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.OTHER_NUMBER, + theUpdate.getOtherNumber()); + } + + if(theUpdate.getBriefDescription()!= null){ + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.BRIEF_DESCRIPTION, + theUpdate.getBriefDescription()); + } + + if(theUpdate.getComments() != null){ + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.COMMENTS, + theUpdate.getComments()); + } + + if(theUpdate.getDistFeatures() != null){ + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.DIST_FEATURES, + theUpdate.getDistFeatures()); + } + + if(theUpdate.getObjectName() != null){ + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.OBJECT_NAME, + theUpdate.getObjectName()); + } + + if(theUpdate.getResponsibleDept() != null){ + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.RESPONSIBLE_DEPT, + theUpdate.getResponsibleDept()); + } + + if(theUpdate.getTitle() != null){ + queryParams.put(CO_NUXEO_SCHEMA_NAME + ":" + CollectionObjectJAXBSchema.TITLE, + theUpdate.getTitle()); + } + + NuxeoRESTClient nxClient = getClient(); + Representation res = nxClient.get(pathParams, queryParams); + SAXReader reader = new SAXReader(); + String status = null; + try { + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for(Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + if("docRef".equals(element.getName())){ + status = (String) element.getData(); + verbose("updateCollectionObject response: " + status); + } + } + } catch(Exception e) { + //FIXME: NOT_FOUND? + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Update failed ").type("text/plain").build(); + throw new WebApplicationException(response); + } + + return theUpdate; + } + + @DELETE + @Path("{csid}") + public void deleteCollectionObject(@PathParam("csid") String csid) { + + verbose("deleteCollectionObject with csid=" + csid); + + NuxeoRESTClient nxClient = getClient(); + List pathParams = new ArrayList(); + Map queryParams = new HashMap(); + + pathParams.add("default"); + pathParams.add(csid); + pathParams.add("deleteDocumentRestlet"); + Representation res = nxClient.get(pathParams, queryParams); + SAXReader reader = new SAXReader(); + String status = ""; + + try { + Document document = reader.read(res.getStream()); + Element root = document.getRootElement(); + for(Iterator i = root.elementIterator(); i.hasNext();){ + Element element = (Element) i.next(); + if("docRef".equals(element.getName())){ + status = (String) element.getData(); + verbose("deleteCollectionObjectt response: " + status); + } + } + }catch(Exception e){ + //FIXME: NOT_FOUND? + Response response = Response.status(Response.Status.NOT_FOUND).entity( + "Delete failed ").type("text/plain").build(); + throw new WebApplicationException(response); + } + + } + + private void verbose(String msg, CollectionObject co) { + try { + verbose(msg); + JAXBContext jc = JAXBContext.newInstance( + CollectionObject.class); + + Marshaller m = jc.createMarshaller(); + m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, + Boolean.TRUE); + m.marshal(co, System.out); + } catch(Exception e){ + e.printStackTrace(); + } + } + + private void verbose(String msg) { + System.out.println("CollectionObjectResource. " + msg); + } +} diff --git a/services/common/pom.xml b/services/common/pom.xml new file mode 100644 index 000000000..2fc241ddc --- /dev/null +++ b/services/common/pom.xml @@ -0,0 +1,236 @@ + + + + + 4.0.0 + org.collectionspace.services + org-collectionspace-services-common + jar + 0.1 + CollectionSpace Services Common + + + + java.net + http://download.java.net/maven/1 + legacy + + + maven repo + maven repo + http://repo1.maven.org/maven2/ + + + + jboss + jboss repo + http://repository.jboss.org/maven2 + + + mojo + mojo repo + http://svn.codehaus.org/mojo/trunk/mojo/jboss-maven-plugin + + + + maven-restlet + Public online Restlet repository + http://maven.restlet.org + + + + cspace.local.nuxeo + ${nuxeo.local.repo.dir} + + + cspace.local.nuxeo.client + ${nuxeo.local.repo.client.dir} + + + public + http://maven.nuxeo.org/public + + + + false + + + + public-snapshot + http://maven.nuxeo.org/public-snapshot + + false + + + + + + + + + public + http://maven.nuxeo.org/public + Nuxeo virtual release repository + + + + false + + + + public-snapshot + http://maven.nuxeo.org/public-snapshot + Nuxeo virtual snapshot repository + + false + + + + + + + + + 4.2.3.GA + 3.0 + UTF-8 + 1.5.1 + 0.9.7 + 5.2-SNAPSHOT + 1.5-SNAPSHOT + + + + + + org.jboss.resteasy + resteasy-jaxrs + 1.0.2.GA + + + tjws + webserver + + + + + org.jboss.resteasy + resteasy-jaxb-provider + 1.0.2.GA + + + org.jboss.resteasy + resteasy-multipart-provider + 1.0.2.GA + + + junit + junit + 4.1 + test + + + + + + + javax.security + jaas + 1.0.01 + provided + + + + dom4j + dom4j + 1.6.1 + provided + + + + + + + + org.nuxeo.ecm.core + nuxeo-core-api + ${nuxeo.version.1.5} + + + jboss-remoting + jboss + + + + + + + + org.restlet + org.restlet + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet.ext.httpclient + 1.0.7 + + + com.noelios.restlet + com.noelios.restlet + 1.0.7 + + + + jaxen + jaxen + 1.1.1 + + + + + org-collectionspace-services-common + + + org.apache.maven.plugins + maven-surefire-plugin + + + + surefire-it + integration-test + + test + + + false + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + + diff --git a/services/common/src/main/java/org/collectionspace/services/CollectionSpaceResource.java b/services/common/src/main/java/org/collectionspace/services/CollectionSpaceResource.java new file mode 100644 index 000000000..79ded42d7 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/CollectionSpaceResource.java @@ -0,0 +1,25 @@ +package org.collectionspace.services; + +import org.collectionspace.services.nuxeo.NuxeoRESTClient; + +public abstract class CollectionSpaceResource { + //replace WORKSPACE_UID for resource workspace + static String CS_COLLECTIONOBJECT_WORKSPACE_UID = "4416ba45-08ca-47b2-aafa-7f4483611d76"; + //rem demo.collectionspace.org UID for CO's is 5a37d40f-59c4-4d15-93ad-e0e6a0c33587 + //sanjay 6c7881fe-54c5-486e-b144-a025dee3a484 + //demo eae0d7b6-580a-45a3-a0f3-e25e980e03bb + static String CS_PERSON_WORKSPACE_UID = "eae0d7b6-580a-45a3-a0f3-e25e980e03bb"; + + //replace host if not running on localhost + //static String CS_NUXEO_HOST = "173.45.234.217"; + static String CS_NUXEO_HOST = "localhost"; + static String CS_NUXEO_URI = "http://" + CS_NUXEO_HOST + ":8080/nuxeo"; + + NuxeoRESTClient getClient() { + NuxeoRESTClient nxClient = new NuxeoRESTClient(CS_NUXEO_URI); + nxClient.setAuthType(NuxeoRESTClient.AUTH_TYPE_BASIC); + nxClient.setBasicAuthentication("Administrator", "Administrator"); + return nxClient; + } + +} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoCallback.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoCallback.java new file mode 100644 index 000000000..6954ae55a --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoCallback.java @@ -0,0 +1,50 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.collectionspace.services.nuxeo; + + +import javax.security.auth.callback.Callback; + +/** + * Copied from jbossx + * + * An implementation of Callback that simply obtains an Object to be used + * as the authentication credential. Interpretation of the Object is up to + * the LoginModules that validate the credential. + * + * @author Scott.Stark@jboss.org + */ +public class NuxeoCallback implements Callback { + + private final String prompt; + + private Object credential; + + public NuxeoCallback() { + this(""); + } + + public NuxeoCallback(String prompt) { + this.prompt = prompt; + } + + public String getPrompt() { + return prompt; + } + + public Object getCredential() { + return credential; + } + + public void setCredential(Object credential) { + this.credential = credential; + } + + public void clearCredential() { + credential = null; + } + +} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoCallbackHandler.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoCallbackHandler.java new file mode 100644 index 000000000..565b64a5e --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoCallbackHandler.java @@ -0,0 +1,85 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.collectionspace.services.nuxeo; + +/** + * + * @author sanjaydalal + */ +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; + +/** + * Copied from jbossx. + * + * @author Scott.Stark@jboss.org + */ +public class NuxeoCallbackHandler implements CallbackHandler { + + private final String username; + private char[] password; + private final Object credential; + + /** + * Initializes the UsernamePasswordHandler with the username and password to + * use. + * + * @param username the user name + * @param password the password for this user + */ + public NuxeoCallbackHandler(String username, char[] password) { + this.username = username; + this.password = password; + credential = password; + } + + public NuxeoCallbackHandler(String username, Object credential) { + this.username = username; + this.credential = credential; + if (credential instanceof char[]) { + password = (char[]) credential; + } else if (credential instanceof CharSequence) { + password = credential.toString().toCharArray(); + } + } + + /** + * Sets any NameCallback name property to the instance username, sets any + * PasswordCallback password property to the instance, and any password. + * + * @exception UnsupportedCallbackException, + * thrown if any callback of type other than NameCallback or + * PasswordCallback are seen. + */ + public void handle(Callback[] callbacks) + throws UnsupportedCallbackException { + for (Callback c : callbacks) { + if (c instanceof NameCallback) { + NameCallback nc = (NameCallback) c; + nc.setName(username); + } else if (c instanceof PasswordCallback) { + PasswordCallback pc = (PasswordCallback) c; + if (password == null) { + // We were given an opaque Object credential but a char[] is + // requested? + if (credential != null) { + String tmp = credential.toString(); + password = tmp.toCharArray(); + } + } + pc.setPassword(password); + } else if (c instanceof NuxeoCallback) { + NuxeoCallback oc = (NuxeoCallback) c; + oc.setCredential(credential); + } else { + throw new UnsupportedCallbackException(c, + "Unrecognized Callback"); + } + } + } +} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoLoginConfiguration.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoLoginConfiguration.java new file mode 100644 index 000000000..e008f4783 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoLoginConfiguration.java @@ -0,0 +1,53 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package org.collectionspace.services.nuxeo; + +/** + * + * @author sanjaydalal + */ +import java.util.HashMap; +import java.util.Map; + +import javax.security.auth.login.AppConfigurationEntry; +import javax.security.auth.login.Configuration; +import javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag; + +public class NuxeoLoginConfiguration extends Configuration { + + private final Configuration parent; + public static final String LOGIN_DOMAIN = "nuxeo-client-login"; + + public NuxeoLoginConfiguration(Configuration parent) { + this.parent = parent; + } + + @Override + public AppConfigurationEntry[] getAppConfigurationEntry(String name) { + + if (LOGIN_DOMAIN.equals(name)) { + AppConfigurationEntry[] entries = new AppConfigurationEntry[1]; + + Map options = new HashMap(); + + options.put("restore-login-identity", "True"); + options.put("multi-threaded", "True"); + + entries[0] = new AppConfigurationEntry("org.jboss.security.ClientLoginModule", LoginModuleControlFlag.REQUIRED, options); + + + return entries; + } else { + return parent.getAppConfigurationEntry(name); + } + } + + @Override + public void refresh() { + if (parent != null) { + parent.refresh(); + } + } +} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoLoginContextFactory.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoLoginContextFactory.java new file mode 100644 index 000000000..fd02d18e2 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoLoginContextFactory.java @@ -0,0 +1,48 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package org.collectionspace.services.nuxeo; + +/** + * + * @author sanjaydalal + */ + +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.login.Configuration; +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; + +public class NuxeoLoginContextFactory { + + + private static boolean initDone=false; + + private static void initLoginConfig() + { + if (initDone) + return; + + Configuration parentConfig = null; + try { + parentConfig = Configuration.getConfiguration(); + } catch (Exception e) { + // do nothing - this can happen if default configuration provider is not correctly configured + // for examnple FileConfig fails if no config file was defined + } + Configuration config = new NuxeoLoginConfiguration(parentConfig); + Configuration.setConfiguration(config); + + initDone=true; + + } + + + public static LoginContext getLoginContext(CallbackHandler handler) throws LoginException + { + initLoginConfig(); + return new LoginContext(NuxeoLoginConfiguration.LOGIN_DOMAIN, handler); + } +} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoRESTClient.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoRESTClient.java new file mode 100644 index 000000000..f8785852c --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/NuxeoRESTClient.java @@ -0,0 +1,313 @@ +/* + * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public License + * (LGPL) version 2.1 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Contributors: + * Nuxeo - initial API and implementation + * + * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ + */ +package org.collectionspace.services.nuxeo; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Map; + + +import org.restlet.Client; +import org.restlet.data.ChallengeResponse; +import org.restlet.data.ChallengeScheme; +import org.restlet.data.Cookie; +import org.restlet.data.Form; +import org.restlet.data.MediaType; +import org.restlet.data.Method; +import org.restlet.data.Parameter; +import org.restlet.data.Protocol; +import org.restlet.data.Request; +import org.restlet.resource.OutputRepresentation; +import org.restlet.resource.Representation; +import org.restlet.util.Series; + +public class NuxeoRESTClient { + + public static final int AUTH_TYPE_NONE = 0; + public static final int AUTH_TYPE_BASIC = 1; + public static final int AUTH_TYPE_SECRET = 2; + protected String baseURL = "http://127.0.0.1:8080/nuxeo"; + protected String restPrefix = "restAPI"; + protected String davPrefix = "dav"; + protected List cookies; + protected int authType = AUTH_TYPE_NONE; + protected String userName; + protected String password; + protected String secretToken; + protected Client restClient; + + public NuxeoRESTClient(String baseURL) { + this.baseURL = baseURL; + } + + public NuxeoRESTClient(String protocol, String serverIP, String serverPort) { + this(protocol, serverIP, serverPort, "nuxeo"); + } + + public NuxeoRESTClient(String protocol, String serverIP, String serverPort, + String servletPath) { + StringBuffer sb = new StringBuffer(); + sb.append(protocol); + sb.append("://"); + sb.append(serverIP); + if (serverPort != null && !serverIP.equals("80")) { + sb.append(':'); + sb.append(serverPort); + } + sb.append(servletPath); + sb.append('/'); + baseURL = sb.toString(); + } + + public void setBasicAuthentication(String userName, String password) { + authType = AUTH_TYPE_BASIC; + this.userName = userName; + this.password = password; + } + + public void setSharedSecretAuthentication(String userName, + String secretToken) { + authType = AUTH_TYPE_SECRET; + this.userName = userName; + this.secretToken = secretToken; + } + + public void setCookies(List cookies) { + this.cookies = cookies; + } + + public Representation post(List pathParams, + Map queryParams, InputStream istream) { + String path = ""; + StringBuffer pathBuffer = new StringBuffer(); + + if (pathParams != null) { + for (String p : pathParams) { + pathBuffer.append(p); + pathBuffer.append('/'); + } + path = pathBuffer.toString(); + } + + return post(path, queryParams, istream); + } + + public Representation post(String subPath, + Map queryParams, InputStream istream) { + StringBuffer urlBuffer = new StringBuffer(); + + if (subPath.startsWith("/")) { + subPath = subPath.substring(1); + } + if (subPath.endsWith("/")) { + subPath = subPath.substring(0, subPath.length() - 1); + } + + urlBuffer.append(baseURL); + urlBuffer.append('/'); + urlBuffer.append(restPrefix); + urlBuffer.append('/'); + urlBuffer.append(subPath); + + if (queryParams != null) { + urlBuffer.append('?'); + + String qpValue = null; + for (String qpName : queryParams.keySet()) { + urlBuffer.append(qpName); + urlBuffer.append('='); + qpValue = queryParams.get(qpName); + if (qpValue != null) { + urlBuffer.append(qpValue.replaceAll(" ", "%20")); + } + urlBuffer.append('&'); + } + } + + String completeURL = urlBuffer.toString(); + System.out.println("\nNuxeoRESTClient: calling " + completeURL); + Request request = new Request(Method.POST, completeURL); + + setupAuth(request); + setupCookies(request); + final InputStream in = istream; + request.setEntity(new OutputRepresentation( + MediaType.MULTIPART_FORM_DATA) { + + @Override + public void write(OutputStream outputStream) throws IOException { + byte[] buffer = new byte[1024 * 64]; + int read; + while ((read = in.read(buffer)) != -1) { + outputStream.write(buffer, 0, read); + } + + } + }); + + return getRestClient().handle(request).getEntity(); + } + + public Representation get(List pathParams, + Map queryParams) { + String path = ""; + StringBuffer pathBuffer = new StringBuffer(); + + if (pathParams != null) { + for (String p : pathParams) { + pathBuffer.append(p); + pathBuffer.append('/'); + } + path = pathBuffer.toString(); + } + + return get(path, queryParams); + } + + public Representation get(String subPath, + Map queryParams) { + StringBuffer urlBuffer = new StringBuffer(); + + if (subPath.startsWith("/")) { + subPath = subPath.substring(1); + } + if (subPath.endsWith("/")) { + subPath = subPath.substring(0, subPath.length() - 1); + } + + urlBuffer.append(baseURL); + urlBuffer.append('/'); + urlBuffer.append(restPrefix); + urlBuffer.append('/'); + urlBuffer.append(subPath); + + if (queryParams != null) { + urlBuffer.append('?'); + for (String qpName : queryParams.keySet()) { + urlBuffer.append(qpName); + urlBuffer.append('='); + urlBuffer.append(queryParams.get(qpName).replaceAll(" ", "%20")); + urlBuffer.append('&'); + } + } + + String completeURL = urlBuffer.toString(); + System.out.println("\nNuxeoRESTClient: calling " + completeURL); + Request request = new Request(Method.GET, completeURL); + setupAuth(request); + setupCookies(request); + + return getRestClient().handle(request).getEntity(); + } + + protected void setupAuth(Request request) { + + if (authType == AUTH_TYPE_BASIC) { + ChallengeScheme scheme = ChallengeScheme.HTTP_BASIC; + ChallengeResponse authentication = new ChallengeResponse(scheme, + userName, password); + request.setChallengeResponse(authentication); + + } else if (authType == AUTH_TYPE_SECRET) { + Series additionnalHeaders = new Form(); + + Map securityHeaders = PortalSSOAuthenticationProvider.getHeaders( + secretToken, userName); + + for (String hn : securityHeaders.keySet()) { + additionnalHeaders.add(hn, securityHeaders.get(hn)); + } + + request.getAttributes().put("org.restlet.http.headers", + additionnalHeaders); + } + } + + protected void setupCookies(Request request) { + if (cookies != null) { + request.getCookies().clear(); + for (Cookie cookie : cookies) { + request.getCookies().add(cookie); + } + } + + } + + protected Client getRestClient() { + if (restClient == null) { + if (baseURL.startsWith("https")) { + restClient = new Client(Protocol.HTTPS); + } else { + restClient = new Client(Protocol.HTTP); + } + } + + return restClient; + } + + public int getAuthType() { + return authType; + } + + public void setAuthType(int authType) { + this.authType = authType; + } + + public String getDavPrefix() { + return davPrefix; + } + + public void setDavPrefix(String davPrefix) { + this.davPrefix = davPrefix; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getRestPrefix() { + return restPrefix; + } + + public void setRestPrefix(String restPrefix) { + this.restPrefix = restPrefix; + } + + public String getSecretToken() { + return secretToken; + } + + public void setSecretToken(String secretToken) { + this.secretToken = secretToken; + } + + public String getUserName() { + return userName; + } + + public void setUserName(String userName) { + this.userName = userName; + } +} diff --git a/services/common/src/main/java/org/collectionspace/services/nuxeo/PortalSSOAuthenticationProvider.java b/services/common/src/main/java/org/collectionspace/services/nuxeo/PortalSSOAuthenticationProvider.java new file mode 100644 index 000000000..0bd2e5189 --- /dev/null +++ b/services/common/src/main/java/org/collectionspace/services/nuxeo/PortalSSOAuthenticationProvider.java @@ -0,0 +1,72 @@ +/* + * (C) Copyright 2006-2007 Nuxeo SAS (http://nuxeo.com/) and contributors. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the GNU Lesser General Public License + * (LGPL) version 2.1 which accompanies this distribution, and is available at + * http://www.gnu.org/licenses/lgpl.html + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * Contributors: + * Nuxeo - initial API and implementation + * + * $Id: JOOoConvertPluginImpl.java 18651 2007-05-13 20:28:53Z sfermigier $ + */ + +package org.collectionspace.services.nuxeo; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Date; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; + +import com.noelios.restlet.util.Base64; + +public class PortalSSOAuthenticationProvider { + + private static final String TOKEN_SEP = ":"; + + private static final String TS_HEADER = "NX_TS"; + + private static final String RANDOM_HEADER = "NX_RD"; + + private static final String TOKEN_HEADER = "NX_TOKEN"; + + private static final String USER_HEADER = "NX_USER"; + + public static Map getHeaders(String secretKey, + String userName) { + + Map headers = new HashMap(); + + Date timestamp = new Date(); + int randomData = new Random(timestamp.getTime()).nextInt(); + + String clearToken = timestamp.getTime() + TOKEN_SEP + randomData + + TOKEN_SEP + secretKey + TOKEN_SEP + userName; + + byte[] hashedToken; + + try { + hashedToken = MessageDigest.getInstance("MD5").digest( + clearToken.getBytes()); + } catch (NoSuchAlgorithmException e) { + return null; + } + + String base64HashedToken = Base64.encodeBytes(hashedToken); + + headers.put(TS_HEADER, String.valueOf(timestamp.getTime())); + headers.put(RANDOM_HEADER, String.valueOf(randomData)); + headers.put(TOKEN_HEADER, base64HashedToken); + headers.put(USER_HEADER, userName); + + return headers; + } + +}