SAS 9.1.3 Integration Technologies » Developer's Guide


Developing Java Clients
Installation and JRE Requirements
Security
Using the IOM Server
Using the Java Connection Factory
Connecting with Directly Supplied Server Attributes
Connecting with Server Attributes Read from a SAS Metadata Server
Connecting with Server Attributes Read from an LDAP Server
Connecting with Server Attributes Read from the Information Service
Language Service Example
Logging Java Connection Factory Activities
Using Failover
Using Load Balancing
Using Connection Pooling
Pooling with Directly Supplied Server Attributes
Pooling with Server Attributes Read from a Metadata Server
Pooling with Server Attributes Read from the Information Service
Returning Connections to the Java Connection Factory
Using Java CORBA Stubs for IOM Objects
Getting a JDBC Connection Object
Using the Java Workspace Factory
Using SAS Foundation Services
IOM and CORBA Class Documentation
Java Clients

Connecting with Server Attributes Read from an LDAP Server

Note: You can read the metadata by either connecting to the metadata server directly, or by using the Information Service. For details about using the Information Service, see Connecting with Server Attributes Read from the Information Service.

The Java Connection Factory enables you to obtain server connection information from a managed, secure LDAP directory using indirect logical names. The main advantage of this method is that you can maintain and update the IOM server and connection information without changing your client programs. This method also provides additional security features if you are using connection pooling.

To use this method, you must provide the client program with instructions for connecting to the LDAP directory, the logical name of the information you want to search for, and the context within the directory for performing the search. To provide this information, you can create an instance of java.util.Hashtable containing the appropriate attributes. For a complete list of the attributes you can provide, refer to the documentation for the class javax.naming.Context. Note that the property names are string constants on the javax.naming.Context interface instead of literal strings.

The following five attributes are required:

javax.naming.Context.INITIAL_CONTEXT_FACTORY
specifies the name of the main class implementing LDAP. If you are using the LDAP implementation from JavaSoft, this value should be com.sun.jndi.ldap.LdapCtxFactory.
javax.naming.Context.PROVIDER_URL
specifies the URL for the LDAP directory server. This value takes the form ldap://host:port.
javax.naming.Context.SECURITY_AUTHENTICATION
specifies the type of authentication to use when connecting to the LDAP directory server. This value is either none, simple, or strong.
javax.naming.Context.SECURITY_PRINCIPAL
specifies the name, such as the distinguished name of a person object in the directory, under which the connection to the LDAP directory server should be made. This property is not required if the value for javax.naming.Context.SECURITY_AUTHENTICATION is none.
javax.naming.Context.SECURITY_CREDENTIALS
specifies the credentials, such as a password, corresponding to the principal given as the value of javax.naming.Context.SECURITY_PRINCIPAL. This property is not required if the value for javax.naming.Context.SECURITY_AUTHENTICATION is none.

Example

The following example code shows how to initialize and use the Java Connection Factory using information from an LDAP directory. For information about how to use the workspace object reference, see Language Service Example.

The last two statements in the example show how to dispose of a workspace object reference. For details about this procedure, see Returning Connections to the Connection Factory.

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import com.sas.iom.SAS.IWorkspace;
import com.sas.iom.SAS.IWorkspaceHelper;
import com.sas.services.connection.ConnectionFactoryAdminInterface;
import com.sas.services.connection.ConnectionFactoryConfiguration;
import com.sas.services.connection.ConnectionFactoryInterface;
import com.sas.services.connection.ConnectionFactoryManager;
import com.sas.services.connection.ConnectionInterface;
import com.sas.services.connection.jndi.JNDIConnectionFactoryConfiguration;

Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL,"ldap://ldsrv.alphaliteairways.com:389");
env.put(Context.SECURITY_AUTHENTICATION,"simple");
env.put(Context.SECURITY_PRINCIPAL,"cn=adm1,o=Alphalite Airways,c=US");
env.put(Context.SECURITY_CREDENTIALS,"adm1pass");
InitialDirContext ctx = new InitialDirContext(env);

< insert LDAP directory usage code here >

private static final String baseDN = "o=Alphalite Airways,c=US";
private static final String logicalName = "abclog";
private static final String repositoryDomain = "LDAP";

// make a connection factory configuration with the server
ConnectionFactoryConfiguration cxfConfig = null;
cxfConfig = new JNDIConnectionFactoryConfiguration(ctx,baseDN,
               logicalName,repositoryDomain);

// get a connection factory manager
ConnectionFactoryManager cxfManager = new ConnectionFactoryManager();

// get a connection factory that matches the configuration
ConnectionFactoryInterface cxf = cxfManager.getFactory(cxfConfig);

// get a connection
String userName = "cn=use1,o=Alphalite Airways,c=US";
String password = "use1pass";
ConnectionInterface cx = 
   cxf.getConnection(userName,password,repositoryDomain);
org.omg.CORBA.Object obj = cx.getObject();
IWorkspace iWorkspace = IWorkspaceHelper.narrow(obj);

< insert workspace usage code here >

// close the workspace connection
cx.close();

// shut down the connection factory
cxf.shutdown();

// close the LDAP context
javax.naming.directory.DirContext.close();

In an effort to make the previous example more readable, we have removed most of the code structuring elements. The example will not compile as it is shown.