Glassfish JMS(平面文件)身份验证

发布于 2024-08-24 06:36:40 字数 1543 浏览 4 评论 0原文

平面文件 JMS 身份验证很容易在 Glassfish 上设置(请参阅 http://docs.sun.com/app/docs/doc/821-0027/aeofg?a=view)。

问题出在客户端部分。我正在编写一个独立的 Java 客户端来通过 JNDI 访问我的 JMS 资源(ConnectionFactoryDestination)。

如何从该客户端将用户名和密码传递给 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

过度放纵 2024-08-31 06:36:41

好的,我找到了一个解决方法,即不使用 JNDI,而是使用特定于供应商的 JMS API,如 http://weblogs.java.net/blog/kalali/archive/2010/03/ 02/open-mq-open-source-message-queuing-beginners-and-professionals-0

最终代码是:

com.sun.messaging.ConnectionFactory connectionFactory = new com.sun.messaging.ConnectionFactory();
QueueConnection queueConnection = connectionFactory.createQueueConnection("user01", "password01");

这次会导致错误

Error: [C4060]: Login failed:  user=user01, broker=localhost:7676(53445)

,这很棒;)

所以,解决方法是有效的。然而,如果有人知道如何使用 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:

com.sun.messaging.ConnectionFactory connectionFactory = new com.sun.messaging.ConnectionFactory();
QueueConnection queueConnection = connectionFactory.createQueueConnection("user01", "password01");

Which this time leads to the error

Error: [C4060]: Login failed:  user=user01, broker=localhost:7676(53445)

Which is great ;)

So, workaround is working. However if someone does know how to achive this also with JNDI it would be even better.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文