1 package org.astrogrid.security;
2
3 import javax.security.auth.Subject;
4 import javax.security.auth.login.Configuration;
5 import javax.security.auth.login.LoginContext;
6 import javax.xml.rpc.JAXRPCException;
7 import javax.xml.soap.SOAPMessage;
8 import org.apache.axis.AxisFault;
9 import org.apache.axis.MessageContext;
10 import org.apache.axis.handlers.BasicHandler;
11 import org.astrogrid.security.jaas.SimpleLoginConfiguration;
12
13 /***
14 * Axis handler for WSSE headers on the server side.
15 *
16 * The Axis developers have declined to implement the
17 * JAX-RPC standard for handlers; their handler format is
18 * different. This class wraps a proper, JAX-RPC handler
19 * in an Axis wrapper.
20 *
21 * Since the underlying handler handles only request messages,
22 * this one ignores response messages.
23 *
24 * @author Guy Rixon.
25 *
26 * @see {@link ServiceCredentialHandler}
27 */
28 public class ServiceCredentialAxisHandler extends BasicHandler {
29
30 /***
31 * A JAX-RPC-compliant handler that does the real work.
32 */
33 private ServiceCredentialHandler realHandler;
34
35
36 /***
37 * Constructs a handler that composes a JAX-RPC handler.
38 */
39 public ServiceCredentialAxisHandler () {
40 super();
41 this.realHandler = new ServiceCredentialHandler();
42 }
43
44
45 /***
46 * Handles a message, delegating it to the JAX-RPC handler.
47 * Only request messages are handled; resonse messages are
48 * ignored.
49 *
50 * @param mc the message context
51 * @throws AxisFault if the JAX-RPC handler throws an exception
52 */
53 public void invoke (MessageContext mc) throws AxisFault {
54 System.out.println("Entering ServiceCredentialAxisHandler.invoke()");
55 try {
56
57
58 if (mc.getPastPivot()) {
59 }
60
61
62 else {
63 this.realHandler.handleRequest(mc);
64 }
65 }
66 catch (Exception e) {
67 System.out.println("ServiceCredentialAxisHandler.invoke() caught an exception");
68 throw this.makeFault("Failed to parse credentials in a request message",
69 e);
70 }
71 }
72
73
74 /***
75 * Makes an AxisFault that retains the ful ldetail of the cause.
76 * Axis itself retains only the first of a chain of exceptions
77 * given as the cause. This method compacts all the messages in
78 * the chain into the message of the exception at its head.
79 *
80 * @param contextMessage the primary text of the AxisFault
81 * @e0 the exception at the head of the chain of causes
82 * @return the created fault
83 */
84 private AxisFault makeFault (String contextMessage, Exception e0) {
85 System.out.println(e0.toString());
86 StringBuffer causeMessage = new StringBuffer(e0.getMessage());
87 Throwable eLast = e0;
88 Throwable eNext = e0.getCause();
89 while (eNext != null) {
90 causeMessage.append("\nCaused by:\n");
91 causeMessage.append(eNext.getMessage());
92 eLast = eNext;
93 eNext = eLast.getCause();
94 }
95 Throwable e1 = new Throwable(causeMessage.toString());
96 return new AxisFault(contextMessage, e1);
97 }
98
99 }