Debian Codegraph @

samples/security/ClientSigningHandler.java

raw
1 /*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package samples.security;
18
19 import org.apache.axis.AxisFault;
20 import org.apache.axis.Handler;
21 import org.apache.axis.Message;
22 import org.apache.axis.MessageContext;
23 import org.apache.axis.components.logger.LogFactory;
24 import org.apache.axis.handlers.BasicHandler;
25 import org.apache.axis.message.SOAPEnvelope;
26 import org.apache.commons.logging.Log;
27
28
29 public class ClientSigningHandler extends BasicHandler {
30 static Log log =
31 LogFactory.getLog(ClientSigningHandler.class.getName());
32
33 static {
34 org.apache.xml.security.Init.init();
35 }
36
37 public void invoke(MessageContext msgContext) throws AxisFault {
38 /** Sign the SOAPEnvelope
39 */
40 try {
41 Handler serviceHandler = msgContext.getService();
42 String filename = (String) getOption("keystore");
43 if ((filename == null) || (filename.equals("")))
44 throw new AxisFault("Server.NoKeyStoreFile",
45 "No KeyStore file configured for the ClientSigningHandler!",
46 null, null);
47 Message requestMessage = msgContext.getRequestMessage();
48 SOAPEnvelope unsignedEnvelope = requestMessage.getSOAPEnvelope();
49 // need to correctly compute baseuri
50 SignedSOAPEnvelope signedEnvelope = new SignedSOAPEnvelope(msgContext, unsignedEnvelope, "http://xml-security", filename);
51 requestMessage = new Message(signedEnvelope);
52 msgContext.setCurrentMessage(requestMessage);
53 // and then pass on to next handler
54 //requestMessage.getSOAPPart().writeTo(System.out);
55 } catch (Exception e) {
56 throw AxisFault.makeFault(e);
57 }
58 }
59
60 public void onFault(MessageContext msgContext) {
61 try {
62 // probably needs to fault.
63 } catch (Exception e) {
64 log.error(e);
65 }
66 }
67 }