View Javadoc

1   package org.astrogrid.security;
2   
3   import org.apache.axis.ConfigurationException;
4   import org.apache.axis.EngineConfiguration;
5   import org.apache.axis.client.Stub;
6   
7   /***
8    * A SecurityGuard specialized to client operations with Axis and
9    * WSS4J. Axis delegates should use this class.
10   *
11   * An object of this class is typically derived from a given, generic
12   * SecurityGuard via the constructor AxisClientSecurityGuard(SecurityGuard).
13   * This constructor copies the principals and credentials from the given guard.
14   * Subsequent changes to the given guard that add, remove or replace 
15   * credentials or principals do not affect the newly-constructed guard.
16   * However, any changes to actual objects representing the credentials
17   * or principals do affect the new guard.
18   *
19   * To enable digital signatures on an Axis stub, call the 
20   * {@link configureStub} method. This passes references to the credentials
21   * to the stub and sets it to sign each subsequent message to its service.
22   * In order for the signature to work, the grid subject of the guard must
23   * contain the following credentials: a java.security.PrivateKey and a 
24   * java.security.cert.CertPath.
25   *
26   * @author Guy Rixon
27   */
28  public class AxisClientSecurityGuard extends SecurityGuard {
29    
30    /***
31     * Creates a ClientSecurityGuard with no credentials.
32     */
33    public AxisClientSecurityGuard () {
34      super();
35    }
36  
37    /***
38     * Creates a ClientSecurityGuard with credentials.
39     * The credentials are copied from a given SecurityGuard.
40     *
41     * @param sg The source of the credentials.
42     */
43     public AxisClientSecurityGuard (SecurityGuard sg) {
44       super(sg);
45    }
46  
47    /***
48     * Sets a guard on an Axis Stub.
49     * This passes to the signature handler in the stub the
50     * settings and credential needed to sign outgoing messages.
51     *
52     * @param stub The stub on which messages are to be signed.
53     */
54    public void configureStub(Stub stub) throws Exception {
55      stub._setProperty("org.astrogrid.security.authenticate", Boolean.TRUE);
56      stub._setProperty("org.astrogrid.security.guard", this);
57    }
58  
59    /***
60     * Makes a configuration for an AxisEngine that applies digital signature to
61     * outgoing messages. This configuration should be used when creating stubs.
62     * in the client.
63     *
64     * @return The configuration.
65     */
66    public static EngineConfiguration getEngineConfiguration() 
67        throws ConfigurationException {
68      return new SecuredClientConfig();
69    }
70  
71  }