Siebel Web UI Dynamic Developer Kit Guide > Using Native Web Service Technology Stacks >

Implementing Siebel Session Management and Authentication SOAP Headers


IBM WebSephere 5.1 and BEA WebLogic 8.1 provide native technology stacks for supporting Web Service clients. To implement Siebel session management and authentication SOAP headers using these stacks, you need to write custom code for setting and getting the SOAP headers. See the following topics for examples:

Siebel session management and authentication SOAP headers are used to pass user credentials and session information back and forth between the Siebel server and the custom UI. The two primary scenarios for using Siebel session management and authentication SOAP headers are:

  • The custom UI sends a valid username and password to the Siebel Server in the SOAP header request. The Siebel Server returns a SessionToken containing a Session Id in the SOAP header response.
  • The custom UI sends a SessionToken (received from a previous login) to the Siebel Server in the SOAP header request. The Siebel Server uses the SessionToken to reconnect to an open session and then returns a new SessionToken in the SOAP header response.

    NOTE:  Requests (except for login requests) should include a SessionToken returned in the previous response from the Siebel Server.

Table 5 summarizes the Siebel session management and authentication SOAP headers.

Table 5. Siebel Session Management and Authentication SOAP Headers
Name
Description
Sample Siebel SOAP Headers

SessionType

Type of session (none or stateless).

<soapenv:Header xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<ns1:SessionType xmlns:ns1="http://siebel.com/webservices">stateless</ns1:SessionType>
<ns2:UsernameToken xmlns:ns2="http://siebel.com/webservices">SADMIN</ns2:UsernameToken>
<ns3:PasswordText xmlns:ns3="http://siebel.com/webservices">MSSQL</ns3:PasswordText>
</soapenv:Header>

NOTE:  Values for SessionType are case insensitive.

UsernameToken

User's Login Id name.

PasswordText

Password used by the Login Id.

SessionToken

Siebel generated token (encrypted) that includes Session ID, username, and password.

<siebel-header:SessionToken xmlns:siebelheader="http://siebel.com/webservices">MN9SxI9Any9zGQTOFIuJEJfCXjfI0G- 9ZOOH4lJjbSd2P.G7vySzo07sFeJxUA0WhdnK</siebel-header:SessionToken>
</SOAP-ENV:Header>

For detailed information about Siebel session management and authentication SOAP headers, see Integration Platform Technologies: Siebel Enterprise Application Integration.

Examples of Setting and Getting SOAP Headers Using IBM WebSphere 5.1

To use Siebel session management and authentication SOAP headers in IBM WebSphere 5.1, you need to write custom code to set and get the SOAP headers. The following example demonstrates implementing Siebel SOAP headers using IBM WebSphere 5.1. The example has three components:

Client Context Handler Example

This example demonstrates including Java dependencies, declaring UsernameToken, PasswordText, and SessionType as strings, and setting and getting the SOAP headers.

package com.siebel.headers.handlers;

import javax.xml.namespace.QName;
import javax.xml.rpc.handler.*;
import javax.xml.rpc.handler.soap.SOAPMessageContext;
import javax.xml.soap.*;
import java.util.Iterator;

public final class ClientContextHandler implements Handler {

        QName qn[] = null;
        public static String uname="username";
        public static String pword="password";
        public static String sessionType = "Stateless";
        //public static String sessionTypeLogout = "None";
        public static String SESSID;
        public static String ACTID;

        private static final String NS_URI
                = "http://siebel.com/webservices";
        private static final String SESSIONTYPE_ELEMENT
                = "SessionType";
        private static final String USERNAME_ELEMENT
                = "UsernameToken";
        private static final String PASSWORD_ELEMENT
                = "PasswordText";
        private static final QName SESSIONTYPE_HEADER
                = new QName(NS_URI, SESSIONTYPE_ELEMENT);
        private static final QName USERNAME_HEADER
                = new QName(NS_URI, USERNAME_ELEMENT);
        private static final QName PASSWORD_HEADER
                = new QName(NS_URI, PASSWORD_ELEMENT);

// Construct SOAP Header Elements Here ***

        public static QName[] HEADERS = new QName[]
{ SESSIONTYPE_HEADER,USERNAME_HEADER,PASSWORD_HEADER };

        public MySessionBean sessionId;
        public void init(HandlerInfo info) {
                qn = info.getHeaders();
                java.util.Map m = info.getHandlerConfig();
                uname = (String) m.get("username");
                pword = (String) m.get("password");
        }

        public boolean handleRequest(MessageContext msgContext) {
                        SOAPMessageContext smc = (SOAPMessageContext)msgContext;
                        SOAPMessage msg = smc.getMessage();
                        SOAPPart sp = msg.getSOAPPart();
                        try {
                                SOAPEnvelope se = sp.getEnvelope();
                                SOAPHeader header = se.getHeader();

                                // add SessionType

                                Name name1 = se.createName(qn[0].getLocalPart(),
                                        "s1", qn[0].getNamespaceURI());
                                SOAPHeaderElement headerElement1 = header.addHeaderElement(name1);
                                sessionId = (MySessionBean)msgContext.getProperty("SessionID");
                                if(sessionId.getValue()!=null)
                                {
                                        headerElement1.addTextNode(sessionType);
                                }
                                //if SessionId is null ie Login does not happen
                                        else
                                        {
        headerElement1.addTextNode("None");
                                        }

                                // add UsernameToken
                                Name name2 = se.createName(qn[1].getLocalPart(),
                                        "s2", qn[1].getNamespaceURI());
                                SOAPHeaderElement headerElement2 = header.addHeaderElement(name2);
                                headerElement2.addTextNode(uname);
                                // add PasswordText
                                Name name3 = se.createName(qn[2].getLocalPart(),
                                        "s3", qn[2].getNamespaceURI());
                                SOAPHeaderElement headerElement3 = header.addHeaderElement(name3);
                                headerElement3.addTextNode(pword);
                        } catch (SOAPException e) {
                                        e.printStackTrace();
                        }
                        return true;
                }

                public boolean handleResponse(MessageContext msgContext)
                {
                        SOAPMessageContext smc = (SOAPMessageContext)msgContext;
                        SOAPMessage msg = smc.getMessage();
                        SOAPPart sp = msg.getSOAPPart();
                        try {

                                SOAPEnvelope se = sp.getEnvelope();|
                                SOAPHeader header = se.getHeader();

                                Iterator it = header.getChildElements();
                                int level=0;
                                while(it.hasNext())
                                {
                                        SOAPHeaderElement he = (SOAPHeaderElement) it.next();
                                        Name name1 = he.getElementName();
                                        Iterator it2 = he.getChildElements();
                                        level++;
                                        if (it2.hasNext())
                                        {
                                                if (level<=1)
                                                {
                                                        Text t = (Text) it2.next();
                                                        sessionId = (MySessionBean)msgContext.getProperty("SessionID");
                                                        sessionId.SetValue(t.getValue());
                                                }
                                                else
                                                {
                                                        Text t = (Text) it2.next();
                                                }

                                        }
                                }
                        } catch (SOAPException e) {
                                e.printStackTrace();

                        }

                        return true;

                }

                public QName[] getHeaders() {
                        return qn;
                }

                public void destroy() {}

                public boolean handleFault(MessageContext mc) { SOAPMessageContext messageContext = (SOAPMessageContext) mc;
                        return true; }
}

MySessionBean Example

This example demonstrates storing the Session Id in the MySessionBean object.

package com.siebel.headers.handlers;

public class MySessionBean {

String value = "default";

    public String getValue()

    {

        return value;

    }

    public void SetValue(String strSessionID)
{
        value = strSessionID;

    }
}

JSP Page Example

The following JSP example demonstrates how the HandlerInfo object passes username, password, and session id into the handler.

<HTML>
<HEAD>
<%@ page language="java"
    contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
    session="true"
%>

<%@ page import="com.siebel.www.*" %>
<%@ page import="com.siebel.headers.handlers.*" %>
<%@ page import="javax.xml.rpc.handler.*" %>
<%@ page import="javax.xml.namespace.QName" %>
<%@ page import="java.util.*" %>
<%@ page import="java.net.URL" %>

<%

    String uname = request.getParameter("username");
    String pword = request.getParameter("password");
    String sessid;

%>

<HEAD>

<TITLE>Siebel Custom Headers</TITLE>
</HEAD>
<BODY>

<FORM METHOD="Get" >
    <TABLE BORDER="0" CELLPADDING="4" CELLSPACING="0" BGCOLOR="#eeeeee">
        <TR BGCOLOR="#ccccff">
            <TD COLSPAN="2" WIDTH="100%">
                <B><FONT FACE="Arial">Sign In</FONT></B>
            </TD>
        </TR>
        <TR>
            <TD ALIGN="right">
                <FONT FACE="Arial" SIZE="-1 ">User ID:</FONT>
            </TD>
            <TD>
                <INPUT NAME="username" SIZE="12" MAXLENGTH="32">
            </TD>
        </TR>
        <TR>
            <TD ALIGN="right">
                <FONT FACE="Arial" SIZE="-1">Password:</FONT>
            </TD>
            <TD>
                <INPUT NAME="password" SIZE="12" TYPE="password" MAXLENGTH="32">
            </TD>
        </TR>
        <TR>
            <TD>
                <INPUT NAME="action" SIZE="12" TYPE="hidden" value="login">
            </TD>
        </TR>
        <TR>
            <TD>
                &nbsp;
            </TD>
            <TD>
                <FONT FACE="Arial" SIZE="-1"><INPUT TYPE="submit" VALUE="Sign in" NAME="Invoke"></FONT>
            </TD>
        </TR>
        <TR>
            <TD>
                <INPUT NAME="action" SIZE="12" TYPE="hidden" value="logout">
            </TD>
        </TR>
        <TR>
            <TD>
                &nbsp;
            </TD>
            <TD>
                <FONT FACE="Arial" SIZE="-1"><INPUT TYPE="submit" VALUE="Logout" NAME="InvokeLogout"></FONT>
            </TD>
        </TR>
    </TABLE>
</FORM>

<%
    if (request.getParameter("Invoke")!= null)
    {
        uname = request.getParameter("username");
        pword = request.getParameter("password");
        sessid = InvokeWS(uname, pword);

        out.println("Your session ID is: " + sessid);
    }

%>

<%

    if (request.getParameter("InvokeLogout")!= null)
    {

        uname = request.getParameter("username");
        pword = request.getParameter("password");
        sessid = InvokeLogout(uname, pword);

        out.println("Your session ID is: " + sessid);
    }

%>

<%!

MySessionBean ctxValue;
        Port service;
        SessionAccessWSLocator locator;
        List handlerList ;
        HandlerRegistry hInfo;
        Map hConfig ;
public String InvokeWS(String username, String password)
{
    try{

        locator = new SessionAccessWSLocator();

        Iterator i = locator.getPorts();
        QName temp =(QName) i.next();

        //QName portQName = new QName("http://tempuri.org/", "WSHeaderSoap");
        //List handlerList = new ArrayList();
        handlerList = new ArrayList();
        HandlerRegistry hInfo = locator.getHandlerRegistry();
        hInfo = locator.getHandlerRegistry();

        hConfig = new HashMap();
        hConfig.put ("username", username);
        hConfig.put ("password", password);

        handlerList.add(new HandlerInfo(ClientContextHandler.class, hConfig, ClientContextHandler.HEADERS));
        hInfo.setHandlerChain(temp, handlerList);

        //WSHeaderSoapProxy wsheaderproxy = new WSHeaderSoapProxy();
        //WSHeaderSoap getConversationtemp = locator.getWSHeaderSoap();
        service = locator.getPort();

        ctxValue = new MySessionBean();
        ctxValue.SetValue("no session");
        //((WSHeaderSoapStub)getConversationtemp)._setProperty("SessionID",ctxValue);
        ((PortStub)service)._setProperty("SessionID", ctxValue);

        //getConversationtemp.doInvokeHeaders();
        service.sessionAccessPing(null);

        ctxValue = (MySessionBean)((PortStub)service)._getProperty("SessionID");
        //System.out.println("Session Bean is " + ctxValue.getValue());
        return (ctxValue.getValue());

    }
    catch(Exception e)
    {
        e.printStackTrace ();
        System.out.println (e.getMessage ());
        return (e.toString());
    }
}

%>

<%!

public String InvokeLogout(String username, String password)

{

    try{

        //SessionAccessWSLocator locator = new SessionAccessWSLocator();
        Iterator i = locator.getPorts();
        QName temp =(QName) i.next();
        //QName portQName = new QName("http://tempuri.org/", "WSHeaderSoap");
        //List handlerList = new ArrayList();
        handlerList = new ArrayList();
        //HandlerRegistry hInfo = locator.getHandlerRegistry();
        hInfo = locator.getHandlerRegistry();

        //Map hConfig = new HashMap();
        //hConfig.put ("username", username);
        //hConfig.put ("password", password);

        handlerList.add(new HandlerInfo(ClientContextHandler.class, hConfig, ClientContextHandler.HEADERS));
        hInfo.setHandlerChain(temp, handlerList);

        //WSHeaderSoapProxy wsheaderproxy = new WSHeaderSoapProxy();
        //WSHeaderSoap getConversationtemp = locator.getWSHeaderSoap();|
        service = locator.getPort();

        //MySessionBean ctxValue = new MySessionBean();
        ctxValue.SetValue(null);
        //((WSHeaderSoapStub)getConversationtemp)._setProperty("SessionID",ctxValue);
        //((PortStub)service)._setProperty("SessionID", ctxValue);
        ((PortStub)service)._setProperty("SessionID", ctxValue);

        //getConversationtemp.doInvokeHeaders();
        service.sessionAccessPing(null);

        ctxValue = (MySessionBean)((PortStub)service)._getProperty("SessionID");
        //System.out.println("Session Bean is " + ctxValue.getValue());
        return (ctxValue.getValue());

    }
    catch(Exception e)
    {
        e.printStackTrace ();
        System.out.println (e.getMessage ());
        return (e.toString());
    }
}

%>

</BODY>
</HTML>

Example of Setting and Getting SOAP Headers Using BEA WebLogic 8.1

The following example to demonstrates how to set and get Siebel session management and authentication SOAP headers using BEA Web Logic 8.1.

public class SessionAccessControlTest implements com.bea.jws.WebService
{
     static final long serialVersionUID = 1L;

     /** @common:control */
     public WSDLFolder.SessionAccessControl sessionAccessControl;
/**
          * @common:operation
          */
          public MySessionBean Login(String Username,String Password)
          {
               MySessionBean sessiontok=new MySessionBean();

               HeaderDocument hd = null;
               try
               {
                         hd = HeaderDocument.Factory.parse(
                         "<SOAP-ENV:Header xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
                         "<ns1:SessionType xmlns:ns1=\"http://siebel.com/webservices\">Stateless</ns1:SessionType>" +
                         "<ns2:UsernameToken xmlns:ns2=\"http://siebel.com/webservices\">"+Username+"</ns2:UsernameToken>" +
                         "<ns3:PasswordText xmlns:ns3=\"http://siebel.com/webservices\">"+Password+"</ns3:PasswordText>" +
                         "</SOAP-ENV:Header>");
               Element h1 = (Element) hd.newDomNode().getFirstChild();
               sessionAccessControl.setOutputHeaders(new Element[] { h1});

               }
               catch (XmlException xe)
               {

                    System.out.println(xe.toString());
               }
               sessionAccessControl.SessionAccessPing("");
               Element e[]=sessionAccessControl.getInputHeaders();
               sessiontok.SetValue(e[0].getFirstChild().getFirstChild().getNodeValue());
               System.out.println("sESSION id "+ sessiontok.getValue());

               return sessiontok;
     }

}     

Siebel Web UI Dynamic Developer Kit Guide