3 Replies Latest reply: Jun 30, 2010 7:41 PM by dvohra21 RSS

    jndi lookup of remote EJB, using weblogic.xml

    782282
      From within a servlet, I'd like to call an EJB 2.0 session bean on a remote server. Both
      appservers are weblogic 10.32.

      I can see how I can configure the InitialContext to set the URL and credentials, e.g.,:

      p = new Properties();
      p.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
      p.put(Context.PROVIDER_URL, "t3://myhost.somewhere.com:8002");
      p.put(Context.SECURITY_PRINCIPAL, "system");
      p.put(Context.SECURITY_CREDENTIALS, "weblogic");
      Context context = new InitialContext(p);
      Object obj = context.lookup("java:comp/env/ejb/HelloWorldBean");

      However, it seems to me to be better to instead configure the lookup in the
      deployment descriptor (i.e., not pass the properties to the InitialContext). I have
      managed to get the following working in the weblogic.xml for the servlet:

      <weblogic-web-app>
      ...
      <ejb-reference-description>
      <ejb-ref-name>ejb/TaskManagerBean</ejb-ref-name>
      <jndi-name>t3://myhost.somewhere.com:8002/HelloWorldBean</jndi-name>
      </ejb-reference-description>
      </weblogic-web-app>

      But I don't know how to provide the security principals/credentials in this case. I've
      been searching the web/documentation all day. :(

      Any help/pointers would be greatly appreciated!
        • 1. Re: jndi lookup of remote EJB, using weblogic.xml
          Jay SenSharma MiddlewareMagic
          Hi,

          Lookup in the JNDI tree...by default doesnt requires any Authentication. It means without using the Username & Password Informations u should be able to lookup your EJBs even if it is Located in a Remote Server. You need to pass the Credentials inside the Hashtable ....Only if your have secure the JNDI lookup of your EJBs....Which generally we dont do.

          NOTE: Securing JNDI tree for Lookup is not related to EJBs....EJB Layer Security is different from JNDI level security....So using Deployment descriptor Tags <ejb-reference-description> You cannot make your EJB secure , You can just refer to it....For Lookup and access a JNDI tree u need to have Security implemented at JNDI layer...so naturally the JNDI Access/Authentication will be limited to JNDI lookup layer only.....

          <font color=red>
          Even there is NO mapping (Tag) available inside deployment descriptor as part of Tag <ejb-reference-description> ..which can be used.
          *<ejb-reference-description>* can be used to refer to an EJB which is deployed on the Same Server...*u CANNOT even use it to access (reference) and EJB which is deployed on a Remote Server.*
          </font>... Still if you want to authenticate a User ...before he looks up to the remote EJB ..then u need to provide authentication at the Web Layer.
          .
          .
          Thanks
          Jay SenSharma
          http://weblogic-wonders.com/weblogic (WebLogic Wonders Are Here)
          • 2. Re: jndi lookup of remote EJB, using weblogic.xml
            782282
            Thanks Jay ... that's the information I was missing.
            • 3. Re: jndi lookup of remote EJB, using weblogic.xml
              dvohra21
              Use the mapped name for session bean. The format of the global JNDI name is mappedName#qualified_name_of_businessInterface.
              <remote_interface> beanRemote = (<remote_interface>) context.lookup("mappedName#qualified_name_of_businessInterface");