2 Replies Latest reply on Apr 9, 2004 1:46 AM by raja05

    Throws AccessControlException if used HTTP Tunneling

    paragsagdeo

      Please see the code below...
      I am getting host and port in applet itself and passing it to ServerManager

      //---------- code inside applet ---------------//
      String host = getCodeBase().getHost();
      String port = getCodeBase().getPort() == -1 ? "" : ":" + getCodeBase().getPort();

      //--------- code of ServerManager -------------//
      String url = (host + port);
      Properties props = new Properties();
      props.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.HttpNamingContextFactory" );
      props.put(Context.PROVIDER_URL,"http://" + url + "/invoker/JNDIFactory" );
      props.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
      try {
      InitialContext ctx = new InitialContext(props);
      Object sessionRemoteRef = ctx.lookup("testejb.session.MySessionBean"); //Line no 74
      }catch(Exception e){
      e.printStackTrace();
      }

      My problem is when i access the applet from browser using address http://parag:8080/mine/TestApplet.html,
      everything works fine but when i try to access it using http://localhost:8080/mine/TestApplet.html
      it throws the following error (TestApplet.html is a simple html file with applet tag)

      --------------------------------------------
      javax.naming.ServiceUnavailableException: Unexpected failure [Root exception is java.security.AccessControlException: access denied (java.net.SocketPermission paragxp:8080 connect,resolve)]
      at org.jboss.naming.interceptors.ExceptionInterceptor.invoke(ExceptionInterceptor.java:56)
      at org.jboss.proxy.SecurityInterceptor.invoke(SecurityInterceptor.java:45)
      at org.jboss.proxy.ClientMethodInterceptor.invoke(ClientMethodInterceptor.java:55)
      at org.jboss.proxy.ClientContainer.invoke(ClientContainer.java:85)
      at $Proxy0.lookup(Unknown Source)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:528)
      at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:507)
      at javax.naming.InitialContext.lookup(Unknown Source)
      at testclient.ServerManager.lookup(ServerManager.java:74)
      at testclient.ServerManager.(ServerManager.java:55)
      at testclient.ServerManagerFactory.getServerManager(ServerManagerFactory.java:28)
      at testclient.gui.TestApplet.initialise(TestApplet.java:260)
      at testclient.gui.TestApplet.init(TestApplet.java:180)
      at sun.applet.AppletPanel.run(Unknown Source)
      at java.lang.Thread.run(Unknown Source)
      Caused by: java.security.AccessControlException: access denied (java.net.SocketPermission paragxp:8080 connect,resolve)
      at java.security.AccessControlContext.checkPermission(Unknown Source)
      at java.security.AccessController.checkPermission(Unknown Source)
      at java.lang.SecurityManager.checkPermission(Unknown Source)
      at java.lang.SecurityManager.checkConnect(Unknown Source)
      at sun.plugin.net.protocol.http.HttpURLConnection.checkPermission(Unknown Source)
      at sun.plugin.net.protocol.http.HttpURLConnection.connect(Unknown Source)
      at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
      at org.jboss.invocation.http.interfaces.Util.invoke(Util.java:101)
      at org.jboss.invocation.http.interfaces.HttpInvokerProxy.invoke(HttpInvokerProxy.java:102)
      at org.jboss.invocation.InvokerInterceptor.invoke(InvokerInterceptor.java:96)
      at org.jboss.naming.interceptors.ExceptionInterceptor.invoke(ExceptionInterceptor.java:42)
      ---------------------------------------------

      I think it should resolve localhost to parag as parag is the name of my own machine
      but it is not doing so.

      Can someone please tell me why it throws AccessControlException when accessing from localhost ?

      Thanks and Regards,

      Parag Sagdeo