可以在Glassfish上轻松设置平面文件JMS身份验证(请参阅http://docs.sun.com/app/docs/doc/821-0027/aeofg?a=view).
问题是客户端部分.我正在编写一个独立的Java客户端来通过JNDI 访问我的JMS资源(ConnectionFactory和Destination).
如何从该客户端将用户名和密码传递给JMS?
我已经尝试过几个例子:
1)在InitialContext中添加这些凭据
context.addToEnvironment(InitialContext.SECURITY_PRINCIPAL, "username");
context.addToEnvironment(InitialContext.SECURITY_CREDENTIALS, "password");
Run Code Online (Sandbox Code Playgroud)
2)在连接工厂中使用JMS用户名和密码参数
connectionFactory.createConnection();
Run Code Online (Sandbox Code Playgroud)
但是,这些方法都不起作用.
当我运行程序时,我得到:
com.sun.messaging.jms.JMSSecurityException: [C4084]: Échec de
l'authentification de l'utilisateur : user=guest, broker=localhost:7676(34576)
at com.sun.messaging.jmq.jmsclient.ProtocolHandler.authenticate
(ProtocolHandler.java:1084)
Run Code Online (Sandbox Code Playgroud)
所以它一直试图与"访客"用户进行身份验证.
对于此测试,我使用connection.NORMAL.deny.user=*了权限规则(accesscontrol.properties).
有趣的是,即使在获得连接因子之前,也会抛出此异常:
InitialContext context = new InitialContext();
ConnectionFactory connectionFactory =
(ConnectionFactory)context.lookup("jms/middleware/factory");
/* The exception is thrown here, so authentication MUST have happened
before already (i.e. NOT in the createConnection(username, password) method) */
Run Code Online (Sandbox Code Playgroud)
希望有人知道答案.
提前谢谢了
问候,
迪内希