Skip Headers

Oracle® Application Server Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 2 (10.1.2)
Part No. B15505-01
  Go To Documentation Library
Home
Go To Product List
Solution Area
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Previous
Next
Next
 

Specifying Credentials in EJB Clients

When you access EJBs in a remote container, you must pass valid credentials to this container. See "Setting JNDI Properties" for more information.

Credentials in JNDI Properties

Indicate the username (principal) and password (credentials) to use when looking up remote EJBs in the jndi.properties file.

For example, if you want to access remote EJBs as POMGR/welcome, define the following properties. The factory.initial property indicates that you will use the Oracle JNDI implementation:

java.naming.security.principal=POMGR
java.naming.security.credentials=welcome
java.naming.factory.initial= 	com.evermind.server.ApplicationClientInitialContextFactory
java.naming.provider.url=opmn:ormi://opmnhost:oc4j_inst1/ejbsamples

In your application program, authenticate and access the remote EJBs, as shown below:

InitialContext ic = new InitialContext();
CustomerHome = 	(CustomerHome)ic.lookup("java:comp/env/purchaseOrderBean"); 

Credentials in the InitialContext

To access remote EJBs from a servlet or JavaBean, pass the credentials in the InitialContext object, as follows:

Hashtable env = new Hashtable(); 
env.put("java.naming.provider.url", 	"opmn:ormi://opmnhost:oc4j_inst1/ejbsamples"); 
env.put("java.naming.factory.initial", 
        "com.evermind.server.ApplicationClientInitialContextFactory"); 
env.put(Context.SECURITY_PRINCIPAL, "POMGR"); 
env.put(Context.SECURITY_CREDENTIALS, "welcome"); 
Context ic = new InitialContext (env); 
CustomerHome =  
   (CustomerHome) ic.lookup ("java:comp/env/purchaseOrderBean");