Java Clients
Connecting with Server Attributes Read from an LDAP ServerNote: 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 The following five attributes are required:
ExampleThe 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. |