Author: fmui
Date: Mon May 31 11:09:25 2010
New Revision: 949715

URL: http://svn.apache.org/viewvc?rev=949715&view=rev
Log:
Web Services server: added WS-Security header to response to make .Net clients 
happy

Added:
    
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/
    
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTube.java
    
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTubeAssembler.java
    
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTubelineAssemblerFactory.java
    
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/resources/
    
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/resources/META-INF/
    
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/resources/META-INF/services/
    
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/resources/META-INF/services/com.sun.xml.ws.api.pipe.TubelineAssemblerFactory

Added: 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTube.java
URL: 
http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTube.java?rev=949715&view=auto
==============================================================================
--- 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTube.java
 (added)
+++ 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTube.java
 Mon May 31 11:09:25 2010
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.server.impl.webservices.wss;
+
+import java.text.SimpleDateFormat;
+import java.util.TimeZone;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import com.sun.xml.ws.api.message.HeaderList;
+import com.sun.xml.ws.api.message.Headers;
+import com.sun.xml.ws.api.message.Message;
+import com.sun.xml.ws.api.message.Packet;
+import com.sun.xml.ws.api.pipe.NextAction;
+import com.sun.xml.ws.api.pipe.Tube;
+import com.sun.xml.ws.api.pipe.TubeCloner;
+import com.sun.xml.ws.api.pipe.helper.AbstractFilterTubeImpl;
+
+public class WssTube extends AbstractFilterTubeImpl {
+
+    private static final String WSSE_NAMESPACE = 
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";;
+    private static final String WSU_NAMESPACE = 
"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";;
+
+    protected WssTube(Tube next) {
+        super(next);
+    }
+
+    protected WssTube(AbstractFilterTubeImpl that, TubeCloner cloner) {
+        super(that, cloner);
+    }
+
+    public WssTube copy(TubeCloner cloner) {
+        return new WssTube(this, cloner);
+    }
+
+    @Override
+    public NextAction processResponse(Packet packet) {
+        Message message = packet.getMessage();
+        if (message == null) {
+            return super.processResponse(packet);
+        }
+
+        try {
+            SimpleDateFormat sdf = new 
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
+            sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
+            long created = System.currentTimeMillis();
+            long expires = created + 24 * 60 * 60 * 1000; // 24 hours
+
+            Document document = 
DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+
+            Element wsseSecurityElement = 
document.createElementNS(WSSE_NAMESPACE, "Security");
+
+            Element wsuTimestampElement = 
document.createElementNS(WSU_NAMESPACE, "Timestamp");
+            wsseSecurityElement.appendChild(wsuTimestampElement);
+
+            Element tsCreatedElement = document.createElementNS(WSU_NAMESPACE, 
"Created");
+            tsCreatedElement.setTextContent(sdf.format(created));
+            wsuTimestampElement.appendChild(tsCreatedElement);
+
+            Element tsExpiresElement = document.createElementNS(WSU_NAMESPACE, 
"Expires");
+            tsExpiresElement.setTextContent(sdf.format(expires));
+            wsuTimestampElement.appendChild(tsExpiresElement);
+
+            HeaderList headers = message.getHeaders();
+            headers.add(Headers.create(wsseSecurityElement));
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+        return super.processResponse(packet);
+    }
+}

Added: 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTubeAssembler.java
URL: 
http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTubeAssembler.java?rev=949715&view=auto
==============================================================================
--- 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTubeAssembler.java
 (added)
+++ 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTubeAssembler.java
 Mon May 31 11:09:25 2010
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.server.impl.webservices.wss;
+
+import com.sun.xml.ws.api.pipe.ClientTubeAssemblerContext;
+import com.sun.xml.ws.api.pipe.ServerTubeAssemblerContext;
+import com.sun.xml.ws.api.pipe.Tube;
+import com.sun.xml.ws.api.pipe.TubelineAssembler;
+
+public class WssTubeAssembler implements TubelineAssembler {
+
+    public Tube createClient(ClientTubeAssemblerContext context) {
+        Tube head = context.createTransportTube();
+        head = context.createSecurityTube(head);
+        head = context.createWsaTube(head);
+        head = context.createClientMUTube(head);
+
+        return context.createHandlerTube(head);
+    }
+
+    public Tube createServer(ServerTubeAssemblerContext context) {
+        Tube head = context.getTerminalTube();
+        head = new WssTube(head);
+        head = context.createHandlerTube(head);
+        head = context.createMonitoringTube(head);
+        head = context.createServerMUTube(head);
+        head = context.createWsaTube(head);
+        head = context.createSecurityTube(head);
+
+        return head;
+    }
+}

Added: 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTubelineAssemblerFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTubelineAssemblerFactory.java?rev=949715&view=auto
==============================================================================
--- 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTubelineAssemblerFactory.java
 (added)
+++ 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/java/org/apache/chemistry/opencmis/server/impl/webservices/wss/WssTubelineAssemblerFactory.java
 Mon May 31 11:09:25 2010
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.chemistry.opencmis.server.impl.webservices.wss;
+
+import com.sun.xml.ws.api.BindingID;
+import com.sun.xml.ws.api.pipe.TubelineAssembler;
+import com.sun.xml.ws.api.pipe.TubelineAssemblerFactory;
+
+public class WssTubelineAssemblerFactory extends TubelineAssemblerFactory {
+
+    @Override
+    public TubelineAssembler doCreate(BindingID bindingID) {
+        return new WssTubeAssembler();
+    }
+}

Added: 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/resources/META-INF/services/com.sun.xml.ws.api.pipe.TubelineAssemblerFactory
URL: 
http://svn.apache.org/viewvc/incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/resources/META-INF/services/com.sun.xml.ws.api.pipe.TubelineAssemblerFactory?rev=949715&view=auto
==============================================================================
--- 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/resources/META-INF/services/com.sun.xml.ws.api.pipe.TubelineAssemblerFactory
 (added)
+++ 
incubator/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-bindings/src/main/resources/META-INF/services/com.sun.xml.ws.api.pipe.TubelineAssemblerFactory
 Mon May 31 11:09:25 2010
@@ -0,0 +1 @@
+org.apache.chemistry.opencmis.server.impl.webservices.wss.WssTubelineAssemblerFactory
\ No newline at end of file


Reply via email to