This project has retired. For details please refer to its
Attic page.
WssTube xref
1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing,13 * software distributed under the License is distributed on an14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY15 * KIND, either express or implied. See the License for the16 * specific language governing permissions and limitations17 * under the License.18 */19package org.apache.chemistry.opencmis.commons.impl.tube.server;
2021import java.text.SimpleDateFormat;
22import java.util.TimeZone;
2324import javax.xml.parsers.DocumentBuilderFactory;
2526import org.apache.chemistry.opencmis.commons.impl.tube.AbstractWssTube;
27import org.w3c.dom.Document;
28import org.w3c.dom.Element;
2930import com.sun.xml.ws.api.message.HeaderList;
31import com.sun.xml.ws.api.message.Headers;
32import com.sun.xml.ws.api.message.Message;
33import com.sun.xml.ws.api.message.Packet;
34import com.sun.xml.ws.api.pipe.NextAction;
35import com.sun.xml.ws.api.pipe.Tube;
36import com.sun.xml.ws.api.pipe.TubeCloner;
37import com.sun.xml.ws.api.pipe.helper.AbstractFilterTubeImpl;
3839publicclassWssTubeextendsAbstractWssTube {
4041publicWssTube(Tube next) {
42super(next);
43 }
4445protectedWssTube(AbstractFilterTubeImpl that, TubeCloner cloner) {
46super(that, cloner);
47 }
4849publicWssTube copy(TubeCloner cloner) {
50returnnewWssTube(this, cloner);
51 }
5253 @Override
54public NextAction processResponse(Packet packet) {
55 Message message = packet.getMessage();
56if (message == null) {
57returnsuper.processResponse(packet);
58 }
5960try {
61 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
62 sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
63long created = System.currentTimeMillis();
64long expires = created + 24 * 60 * 60 * 1000; // 24 hours6566 Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
6768 Element wsseSecurityElement = document.createElementNS(WSSE_NAMESPACE, "Security");
6970 Element wsuTimestampElement = document.createElementNS(WSU_NAMESPACE, "Timestamp");
71 wsseSecurityElement.appendChild(wsuTimestampElement);
7273 Element tsCreatedElement = document.createElementNS(WSU_NAMESPACE, "Created");
74 tsCreatedElement.setTextContent(sdf.format(created));
75 wsuTimestampElement.appendChild(tsCreatedElement);
7677 Element tsExpiresElement = document.createElementNS(WSU_NAMESPACE, "Expires");
78 tsExpiresElement.setTextContent(sdf.format(expires));
79 wsuTimestampElement.appendChild(tsExpiresElement);
8081 HeaderList headers = message.getHeaders();
82 headers.add(Headers.create(wsseSecurityElement));
83 } catch (Exception e) {
84 e.printStackTrace();
85 }
8687returnsuper.processResponse(packet);
88 }
89 }