0 Replies Latest reply on Oct 24, 2005 2:27 PM by Greedo Sect

    Accessing JBoss 3.2.3 from external Tomcat 5.0

    Greedo Sect Newbie

      Hi all,

      I'm attempting to lookup an EJB using the JNDI service in JBoss 3.2.3 from a servlet running in a seperate Tomcat 5.0 container, however I'm getting an error when I create an InitialContext.

      I running Tomcat with a Security Manager and also tried adding several addicional permissions to the catalina.policy file.

      I'm receiving the following error:

      INFO: Server startup in 2437 ms
      javax.naming.NamingException: Failed to retrieve Naming interface [Root exception is java.security.AccessControlException: access denied (java.net.NetPermission setDefaultAuthenticator)]
      at org.jboss.naming.HttpNamingContextFactory.getInitialContext(HttpNamingContextFactory.java:69)
      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
      at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
      at javax.naming.InitialContext.init(InitialContext.java:219)
      at javax.naming.InitialContext.(InitialContext.java:195)
      at br.gov.bnb.grupoecon.web.GrupoEconController.getInitialContext(GrupoEconController.java:91)
      at br.gov.bnb.grupoecon.web.GrupoEconController.getGerenciaCadastro(GrupoEconController.java:102)
      at br.gov.bnb.grupoecon.web.GrupoEconController.doPost(GrupoEconController.java:150)
      at br.gov.bnb.grupoecon.web.GrupoEconController.doGet(GrupoEconController.java:135)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:324)
      at org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:239)
      at java.security.AccessController.doPrivileged(Native Method)
      at javax.security.auth.Subject.doAsPrivileged(Subject.java:500)
      at org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:268)
      at org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:157)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
      at org.apache.catalina.core.ApplicationFilterChain.access$000(ApplicationFilterChain.java:50)
      at org.apache.catalina.core.ApplicationFilterChain$1.run(ApplicationFilterChain.java:140)
      at java.security.AccessController.doPrivileged(Native Method)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:136)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
      at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
      at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
      at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
      at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
      at java.lang.Thread.run(Thread.java:534)
      Caused by: java.security.AccessControlException: access denied (java.net.NetPermission setDefaultAuthenticator)
      at java.security.AccessControlContext.checkPermission(AccessControlContext.java:269)
      at java.security.AccessController.checkPermission(AccessController.java:401)
      at java.lang.SecurityManager.checkPermission(SecurityManager.java:524)
      at java.net.Authenticator.setDefault(Authenticator.java:84)
      at org.jboss.invocation.http.interfaces.Util.init(Util.java:79)
      at org.jboss.naming.HttpNamingContextFactory.getNamingServer(HttpNamingContextFactory.java:106)

      My Code:

      
      private Context getInitialContext() {
       try {
       if (context == null) {
       Properties env = new Properties();
       env.setProperty(Context.INITIAL_CONTEXT_FACTORY,
       "org.jboss.naming.HttpNamingContextFactory");
       env.setProperty(Context.PROVIDER_URL,
       "http://localhost:8080/invoker/JNDIFactory");
       env.setProperty(Context.URL_PKG_PREFIXES,
       "org.jboss.naming:org.jnp.interfaces");
       context = new InitialContext(env);
       }
       } catch (NamingException e) {
       e.printStackTrace();
       }
       return context;
      }
      
      


      My catalina.policy file:

      ....
      grant {
      permission java.security.AllPermission;
      permission java.net.NetPermission setDefaultAuthenticator;
      permission java.util.PropertyPermission "catalina.base", "read";
      permission java.lang.RuntimePermission setContextClassLoader;
      permission java.net.SocketPermission 127.0.0.1:1738 accept,resolve;
      };

      Thanks in advance!

      Craig