Skip Headers
Oracle® Workspaces Web Services Application Developer's Guide
10g Release 1 (10.1.2.2)

Part Number B28207-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Master Index
Master Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

3 Authentication Service

The Authentication service provides an authentication mechanism for users to access Oracle Workspaces Web services.

The user supplies his or her login credentials. The Authentication service Web service validates them by connecting to Oracle Internet Directory. An authentication cookie representing the user session is returned. Pass this cookie to all other Oracle Workspaces Web services in order to invoke them. As a result, the user will not be required to supply his credentials again until the cookies expires or the user explicitly logs out.

See the code samples in chapters about specific services such as Chapter 5, "Home Service" for examples of how to use the authentication cookie to invoke Oracle Workspaces Web services.

Example: Retrieve Authentication Cookie

The following code sample retrieves an authentication cookie:

Example 3-1 AuthenticationSample.java

package oracle.sample.workspaces.ws;
 
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import oracle.workspaces.ws.AuthenticationService;
import oracle.workspaces.ws.AuthenticationServiceServiceLocator;
import oracle.workspaces.ws.AuthenticationServiceSoapBindingStub;
import oracle.workspaces.ws.S2SAuthenticationServiceSoapBindingStub;
import oracle.workspaces.ws.exceptions.CwWSException;
import org.apache.axis.transport.http.HTTPConstants;
 
public class AuthenticationSample 
{
  public static AuthenticationService
    configureAuthenticationService(
    String username,
    String password) throws ServiceException, RemoteException, CwWSException
    {
      System.out.println("Logging on to Oracle Workspaces Web services " +
        "using AuthenticationService");
 
    // Initialize the service locator for the Authentication service.
    // The service locator contains the Web service endpoint URL
    // in the form of
    // http://<midtier instance name>:<port>/
    //   ocw/services/AuthenticationService
      
    AuthenticationServiceServiceLocator assl =
      new AuthenticationServiceServiceLocator();
      
    // Retrieve a reference to the Web service's remote interface
    // from the service locator
      
    AuthenticationService as = assl.getAuthenticationService();
    
    // Indicate the client's willingness to participate in the session.
    // Unless it is set to true, the server assumes that client is not
    // participating in the session.
    //
    // As HTTP is stateless, each Web service invocation will be
    // different and the user's state will not be
    // maintained across different Web service invocations.    
    
    ((AuthenticationServiceSoapBindingStub)as).
      setMaintainSession(true);
      
    // Invoke the login method to authenticate the user.
    // User nickname and password are sent as plain text.
              
    as.login(username, password);
    
    return as;
 
      
    }
 
  public static String getAuthenticationCookie
    (AuthenticationService as)
    throws CwWSException, ServiceException, RemoteException
  {
    // Once the authentication is successful, an HTTP session is
    // established between the Web services server and the user.
    //
    // A J2EE session is established between the Web services server
    // and the Oracle Workspaces back-end. A cookie identifying the
    // user's HTTP session is placed into the servlet application context.
    //
    // This cookie is to be retrieved and supplied on each 
    // subsequent Web services invocation.
    
    String cookie = (String)((AuthenticationServiceSoapBindingStub)as).
      _getCall().getMessageContext().
      getProperty(HTTPConstants.HEADER_COOKIE);
      
    return cookie;
    
  }
  
  public static void main(String[] args)
  {
    try {
    
      // Get authentication cookie
      
      AuthenticationService myAuthenticationService =
        AuthenticationSample.configureAuthenticationService(
          "orcladmin",
          "welcome1");
          
      String authCookie = AuthenticationSample.getAuthenticationCookie
        (myAuthenticationService);
        
      System.out.println("Retrieved authentication cookie : " + authCookie);
      
      // Invoke the logout method to destroy the user credentials
      // stored in the HTTP session.
      //
      // On logout invocation, the HTTP session is invalidated and
      // the cookie is destroyed.
      // 
      // The user's state is lost and hence the user will not be able
      // to invoke any other Web services methods
      // until he or she logs in again.
      
      myAuthenticationService.logout();      
      
      
    } catch (CwWSException cwwse) 
    {
      System.out.println("CwWSException caught: " + cwwse.getMessage());
    } catch (Exception e) 
    {
      System.out.println("Exception caught: " + e.toString());
    }
    
  }
}