2 Replies Latest reply on Apr 8, 2004 2:04 PM by cbuckley

    JMS Security

    cbuckley

      Hello,

      I think this should be a simple one:
      Details: Jboss 3.2.3, Windows XP
      I have the following client which complies and runs ( I got it from the JBoss docs), however when I try to use a queue (queue/A) I get a JMSSecurityException more specifically:

      07:55:28,966 DEBUG [ChannelSocket] Accepted socket Socket[addr=/10.1.1.125,port=4235,localport=8009]
      07:55:28,997 DEBUG [ChannelSocket] receive()
      07:55:28,997 DEBUG [ChannelSocket] read() [B@c96c01 8192 0 4 = 4
      07:55:28,997 DEBUG [MsgAjp] Received 188 18
      07:55:28,997 DEBUG [ChannelSocket] read() [B@c96c01 8192 4 188 = 188
      07:55:28,997 DEBUG [ChannelSocket] Call next 0 org.apache.jk.common.HandlerRequest@113e8f3
      07:55:28,997 DEBUG [HandlerRequest] Handling 2
      07:55:28,997 DEBUG [HandlerRequest] R( /invoker/JNDIFactory)
      07:55:28,997 DEBUG [HandlerRequest] Calling next container org.apache.jk.server.JkCoyoteHandler
      07:55:28,997 DEBUG [JkCoyoteHandler] Invoke R( /invoker/JNDIFactory) org.apache.coyote.Response@1d1ba28 /invoker/JNDIFactory
      07:55:29,028 INFO [JaasSecurityManagerService] Created securityMgr=org.jboss.security.plugins.JaasSecurityManager@15cfa96
      07:55:29,028 INFO [JaasSecurityManagerService] setCachePolicy, c=org.jboss.util.TimedCachePolicy@147c2de
      07:55:29,028 INFO [JaasSecurityManagerService] Added http-invoker, org.jboss.security.plugins.SecurityDomainContext@4a8194 to map
      07:55:29,028 DEBUG [JkCoyoteHandler] ACK
      07:55:29,122 DEBUG [JkCoyoteHandler] COMMIT
      07:55:29,122 DEBUG [JkCoyoteHandler] COMMIT sending headers org.apache.coyote.Response@1d1ba28 === MimeHeaders ===

      07:55:29,153 DEBUG [ChannelSocket] send() 112 4
      07:55:29,153 DEBUG [JkCoyoteHandler] doWrite 0 1386 0
      07:55:29,153 DEBUG [ChannelSocket] send() 1394 3
      07:55:29,169 DEBUG [JkCoyoteHandler] CLIENT_FLUSH
      07:55:29,169 DEBUG [JkCoyoteHandler] CLIENT_FLUSH
      07:55:29,169 DEBUG [JkCoyoteHandler] CLIENT_FLUSH
      07:55:29,169 DEBUG [JkCoyoteHandler] CLOSE
      07:55:29,169 DEBUG [ChannelSocket] send() 6 5
      07:55:29,169 DEBUG [REQ_TIME] Time pre=0/ service=172 -1 /invoker/JNDIFactory
      07:55:29,169 DEBUG [HandlerRequest] Invoke returned 0
      07:55:29,169 DEBUG [ChannelSocket] receive()
      07:55:29,747 WARN [OILServerILService] Client request resulted in a server exception:
      javax.jms.JMSSecurityException: User: null is NOT authenticated
      at org.jboss.mq.security.SecurityManager.authenticate(SecurityManager.java:232)
      at org.jboss.mq.security.ServerSecurityInterceptor.authenticate(ServerSecurityInterceptor.java:51)
      at org.jboss.mq.server.TracingInterceptor.authenticate(TracingInterceptor.java:781)
      at org.jboss.mq.server.JMSServerInvoker.authenticate(JMSServerInvoker.java:287)
      at org.jboss.mq.il.oil.OILServerILService$Client.run(OILServerILService.java:329)
      at java.lang.Thread.run(Thread.java:534)
      07:55:49,700 INFO [ChannelSocket] connection timeout reached

      Looking at the jbossmq-destinations-service.xml:

      Queue A appears to have no security manager.

      Here is my Client:

      package intuinet.messenger;

      import java.util.Properties;

      import javax.jms.JMSException;
      import javax.jms.Message;
      import javax.jms.MessageListener;
      import javax.jms.Queue;
      import javax.jms.QueueConnection;
      import javax.jms.QueueConnectionFactory;
      import javax.jms.QueueReceiver;
      import javax.jms.QueueSender;
      import javax.jms.QueueSession;
      import javax.jms.TextMessage;
      import javax.naming.Context;
      import javax.naming.InitialContext;
      import javax.naming.NamingException;

      import EDU.oswego.cs.dl.util.concurrent.CountDown;


      /** A complete JMS client example program that sends a
      TextMessage to a Queue and asynchronously receives the
      message from the same Queue.
      @author Scott.Stark@jboss.org
      @version $Revision:$
      */

      public class SendRecvClient
      {
      static CountDown done = new CountDown(1);
      QueueConnection conn;
      QueueSession session;
      Queue que;
      public static class ExListener implements MessageListener
      {
      public void onMessage(Message msg)
      {
      done.release();
      TextMessage tm = (TextMessage) msg;
      try
      {
      System.out.println("onMessage, recv text="
      + tm.getText());
      }
      catch(Throwable t)
      {
      t.printStackTrace();
      }
      }
      }

      public static InitialContext getInitialContext() throws NamingException {
      Properties env = new Properties();
      env.put(Context.SECURITY_PRINCIPAL, "guest");
      env.put(Context.SECURITY_CREDENTIALS, "guest");
      env.put(Context.INITIAL_CONTEXT_FACTORY,"org.jboss.naming.HttpNamingContextFactory");
      env.put(Context.PROVIDER_URL, "http://server/invoker/JNDIFactory");
      return new InitialContext(env);
      }



      public void setupPTP()
      throws JMSException, NamingException
      {
      InitialContext iniCtx = getInitialContext();
      Object tmp = iniCtx.lookup("ConnectionFactory");
      QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
      conn = qcf.createQueueConnection();
      que = (Queue) iniCtx.lookup("queue/A");
      session = conn.createQueueSession(false,QueueSession.AUTO_ACKNOWLEDGE);
      conn.start();
      }
      public void sendRecvAsync(String text)
      throws JMSException, NamingException
      {
      System.out.println("Begin sendRecvAsync");
      // Setup the PTP connection, session
      setupPTP();
      // Set the async listener
      QueueReceiver recv = session.createReceiver(que);
      recv.setMessageListener(new ExListener());
      // Send a text msg
      QueueSender send = session.createSender(que);
      TextMessage tm = session.createTextMessage(text);
      send.send(tm);
      System.out.println("sendRecvAsync, sent text="
      + tm.getText());
      send.close();
      System.out.println("End sendRecvAsync");

      }
      public void stop() throws JMSException {
      conn.stop();
      session.close();
      conn.close();
      }
      public static void main(String args[]) throws Exception {


      SendRecvClient client = new SendRecvClient();
      client.sendRecvAsync("A text msg");
      client.done.acquire();
      client.stop();
      System.exit(0);
      }
      }