Glassfish JMS(平面文件)身份验证
平面文件 JMS 身份验证很容易在 Glassfish 上设置(请参阅 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");
2)在连接工厂中使用JMS用户名和密码参数
connectionFactory.createConnection();
但是,这些方法都不起作用。
当我运行该程序时,我只是得到:
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)
所以它一直尝试通过“来宾”用户进行身份验证。
对于此测试,我使用 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) */
希望有人知道答案。
预先非常感谢
问候,
迪内什
Flat-file JMS authentication is easy to set up on Glassfish (see http://docs.sun.com/app/docs/doc/821-0027/aeofg?a=view).
The problem is the client part. I am writing a standalone Java client to access my JMS ressources (ConnectionFactory
and Destination
) via JNDI.
How to pass a username and a password to JMS from that client ?
I already tried several things such as:
1) Adding those credentials in the InitialContext
context.addToEnvironment(InitialContext.SECURITY_PRINCIPAL, "username");
context.addToEnvironment(InitialContext.SECURITY_CREDENTIALS, "password");
2) Using JMS username and password parameters in the connection factory
connectionFactory.createConnection();
However, none of those methods is working.
When I run the program, I just get:
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)
So it keeps trying to authenticate with the "guest" user.
For this test, I used connection.NORMAL.deny.user=*
as permission rule (accesscontrol.properties
).
The interesting part is that this exception is thrown even before the connection factore is obtained:
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) */
Hope someone knows the answer.
Many thanks in advance
Regards,
Dinesh
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,我找到了一个解决方法,即不使用 JNDI,而是使用特定于供应商的 JMS API,如 http://weblogs.java.net/blog/kalali/archive/2010/03/ 02/open-mq-open-source-message-queuing-beginners-and-professionals-0
最终代码是:
这次会导致错误
,这很棒;)
所以,解决方法是有效的。然而,如果有人知道如何使用 JNDI 来实现这一点,那就更好了。
OK I found a workaround, which is to not use JNDI, but to use vendor-specific JMS API instead, as described on http://weblogs.java.net/blog/kalali/archive/2010/03/02/open-mq-open-source-message-queuing-beginners-and-professionals-0
The final code is:
Which this time leads to the error
Which is great ;)
So, workaround is working. However if someone does know how to achive this also with JNDI it would be even better.