We've been doing this for a few months now and are actually on an effort to move
away from it because of the security problems presented from this approach.
That being said, the context that we've found to work the best is the
RMIInitialContextFactory.

Here is sample of some code we're using.

The application name is the name of the application you specify in the xml
configuration files.

The username and password are configured in principals.xml.


// Get the context
         env = new Hashtable();
         env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
               "com.evermind.server.rmi.RMIInitialContextFactory");
         env.put(javax.naming.Context.PROVIDER_URL, "ormi://" +
getCodeBase().getHost() + "/cems");
         env.put(javax.naming.Context.SECURITY_PRINCIPAL, "admin");
         env.put(javax.naming.Context.SECURITY_CREDENTIALS, "123");
         env.put("dedicated.connection","true");
         context = new InitialContext(env);

// Now look up the bean
               Object obj = context.lookup("ejb/YourBeanName");
               home = (YouBeanHome)PortableRemoteObject.narrow(obj,
YouBeanHome.class);
               YourBeanRemote remote = home.create();

You will also need a policy file on the client.  For testing purposes it's
easiest to just grant all permission to the applet until
you get it running

grant {
    permission java.security.AllPermission;
};

Then specify the location of the policy file in your java console
-Djava.security.policy=<path>/java.policy.

Hope this helps.

Todd

Paul Sprague wrote:

> Nothing seems to be going my way! :-(
>
> First of all I've noticed that there are different provider URLs being
> passed around. I need to get this straitened out.
> As I understand it the format should be:
>
> ormi://<hostname>/<application>
>
> now what about the port? ORMI defaults to port 23791, right?
> does that "ormi://" part make the port not necessary because the default
> port is used?
>
> I have been using
> ormi://129.21.160.38/salary
>
> I have tried
> ormi://129.21.160.38
> ormi://129.21.160.38:23791
> ormi://129.21.160.38/application
> ormi://129.21.160.38:23791/application
>
> I'm really not sure what the application part of the provider URL is, can
> anyone clarify this? I thought it was the applications JNDI name space you
> wanted to access but I'm really not sure.
>
> The only difference is that my code freezes in different places. What is the
> preferred way to do this? Are any of these totally wrong?
>
> On to the initial context factory. I've been flipping between 2 of them in
> totally ignorance. What is the difference between these factories?
> Which one is best to use for doing JNDI lookups from within an applet?
> com.evermind.server.rmi.RMIInitialContextFactory
> com.evermind.server.ApplicationClientInitialContextFactory
>
> So I've been trying every possible combination of these 2 properties and the
> only thing that changes is where the code stops working. I either stops on
> Context context = new InitialContext(ht);
> or on
> NamingEnumeration enum = context.list("");
>
> my hashtable looks like this:
> ht.put( "java.naming.applet"                , this );      //I have no idea
> what this does, anyone?
> ht.put( "java.naming.factory.initial"       ,
> s_initial_context_factory_name );
> ht.put( "java.naming.provider.url"          ,
> url_name            );
> ht.put( "java.naming.security.principal"    ,
>        );
> ht.put( "java.naming.security.credentials"  ,
>            );
>
> Thanks for any help.
> Paul


Reply via email to