4 Replies Latest reply on Apr 18, 2004 6:39 PM by Steve Lewis

    Servlet using a Jboss Session - Bean

    josefduschinger Newbie

      Hi,

      i am using jboss3.2.3 with tomcat. I wrote a servlet, in which I want to use a JBoss - Session Bean.

      I always get the Excption like:

      EJBException:; nested exception is: javax.ejb.EJBException: checkSecurityAssociation; CausedByException is: Authentication exception, principal=null

      The source code is:

      public String execute(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, org.apache.velocity.context.Context pvContext)
      {

      try
      {


      SecurityAssociationHandler handler = new SecurityAssociationHandler();
      Principal userPrincipal = new Principal()
      {
      public String getName()
      {
      return "georg";
      }
      };
      System.out.println(userPrincipal.getName());

      handler.setSecurityInfo(userPrincipal, "georg1");
      LoginContext loginContext =
      new LoginContext("EJBSecurityDomain", (CallbackHandler) handler);
      loginContext.login();

      Context jndiContext = getInitialContext();

      Object ref = jndiContext.lookup("GeorgSQLHomeRemote");
      GeorgSQLHomeRemote georgHome = (GeorgSQLHomeRemote)
      PortableRemoteObject.narrow(ref,GeorgSQLHomeRemote.class);

      GeorgSQLRemote georg = georgHome.create();

      pvContext.put ("Meldung", "Huhu");

      }
      catch (Throwable t)
      {
      t.printStackTrace();
      pvContext.put ("Meldung", t.getMessage());
      }


      return "userList.html";
      }

      static public Context getInitialContext() throws Exception
      {
      // jndi.properties contains InitialContext properties
      Hashtable env = new Hashtable();
      env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
      env.put(Context.OBJECT_FACTORIES, "org.jboss.naming:org.jnp.interfaces");
      env.put(Context.PROVIDER_URL, "192.168.249.23:1099");

      return new InitialContext(env);
      }

      My question, what have I to do, that the connection works?

      Josef