Package org.silverpeas.sso.kerberos.spnego

# Class SpnegoSOAPConnection

java.lang.Object
jakarta.xml.soap.SOAPConnection
org.silverpeas.sso.kerberos.spnego.SpnegoSOAPConnection

All Implemented Interfaces:
  `AutoCloseable`

public class SpnegoSOAPConnection extends jakarta.xml.soap.SOAPConnection
This class can be used to make SOAP calls to a protected SOAP Web Service.

The idea for this class is to replace code that looks like this...

      final SOAPConnectionFactory soapConnectionFactory =
          SOAPConnectionFactory.newInstance();
      conn = soapConnectionFactory.createConnection();

with code that looks like this...

      conn = new SpnegoSOAPConnection("spnego-client", "dfelix", "myp@s5");

Example:

     SOAPMessage response = null;

     final SpnegoSOAPConnection conn =
         new SpnegoSOAPConnection(this.module, this.kuser, this.kpass);

     try {
         final MessageFactory msgFactory = MessageFactory.newInstance();
         final SOAPMessage message = msgFactory.createMessage();

         final SOAPBody body = message.getSOAPBody();

         final SOAPBodyElement bodyElement = body.addBodyElement(
                 new QName(this.namespace, this.methodName, this.nsprefix));

         for (int i=0; i<args.length; i++) {
             final SOAPElement element = bodyElement.addChildElement(
                     new QName("arg" + i));

             element.addTextNode(args[i]);
         }

         response = conn.call(message, this.serviceLocation);

     } finally {
         conn.close();
     }

To see a full working example, take a look at the ExampleSpnegoSOAPClient.java example.

Also, take a look at the how to connect to a protected SOAP Web Service example.

Author:
  Darwin V. Felix
See Also:
  - `SpnegoHttpURLConnection`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `SpnegoSOAPConnection(String loginModuleName)`
  Creates an instance where the LoginContext relies on a keytab file being specified by "java.security.auth.login.config" or where LoginContext relies on tgtsessionkey.
  `SpnegoSOAPConnection(String loginModuleName, String username, String password)`
  Creates an instance where the LoginContext does not require a keytab file.
  `SpnegoSOAPConnection(GSSCredential creds)`
  Create an instance where the GSSCredential is specified by the parameter and where the GSSCredential is automatically disposed after use.
  `SpnegoSOAPConnection(GSSCredential creds, boolean dispose)`
  Create an instance where the GSSCredential is specified by the parameter and whether the GSSCredential should be disposed after use.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final jakarta.xml.soap.SOAPMessage`
  `call(jakarta.xml.soap.SOAPMessage request, Object endpoint)`
  `final void`
  `close()`

  ### Methods inherited from class jakarta.xml.soap.SOAPConnection

  `get, getConnectTimeout, getReadTimeout, setConnectTimeout, setReadTimeout`

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### SpnegoSOAPConnection

    public SpnegoSOAPConnection(String loginModuleName) throws LoginException
    Creates an instance where the LoginContext relies on a keytab file being specified by "java.security.auth.login.config" or where LoginContext relies on tgtsessionkey.
    Parameters:
      `loginModuleName` - the name of the login module
    Throws:
      `LoginException` - if the login fails

  - ### SpnegoSOAPConnection

    public SpnegoSOAPConnection(GSSCredential creds)
    Create an instance where the GSSCredential is specified by the parameter and where the GSSCredential is automatically disposed after use.
    Parameters:
      `creds` - credentials to use

  - ### SpnegoSOAPConnection

    public SpnegoSOAPConnection(GSSCredential creds, boolean dispose)
    Create an instance where the GSSCredential is specified by the parameter and whether the GSSCredential should be disposed after use.
    Parameters:
      `creds` - credentials to use
      `dispose` - true if GSSCredential should be diposed after use

  - ### SpnegoSOAPConnection

    public SpnegoSOAPConnection(String loginModuleName, String username, String password) throws LoginException
    Creates an instance where the LoginContext does not require a keytab file. However, the "java.security.auth.login.config" property must still be set prior to instantiating this object.
    Parameters:
      `loginModuleName` - the name of the login module
      `username` - the login id of the user
      `password` - the login password of the user
    Throws:
      `LoginException` - if the login fails

- ## Method Details

  - ### call

    public final jakarta.xml.soap.SOAPMessage call(jakarta.xml.soap.SOAPMessage request, Object endpoint) throws jakarta.xml.soap.SOAPException
    Specified by:
      `call` in class `jakarta.xml.soap.SOAPConnection`
    Throws:
      `jakarta.xml.soap.SOAPException`

  - ### close

    public final void close()
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in class `jakarta.xml.soap.SOAPConnection`