简体   繁体   English

我们可以在没有用户名和密码的情况下设置 JMS 通信吗?

[英]Can we setup JMS communication without username and password?

I am working in a jBoss environment and implemented JMS for enabling asynchronous communication between two modules.我在 jBoss 环境中工作并实现了 JMS 以实现两个模块之间的异步通信。 But for this I need to add the user by "add-user.sh" script.但是为此我需要通过“add-user.sh”脚本添加用户。 Then the user information gets saved in application-users.properties and application-roles.properties.然后用户信息保存在 application-users.properties 和 application-roles.properties 中。 Then I need to hardcode this username and password in the MessagePublisher class who will authenticate the user by the following block of code -然后我需要在 MessagePublisher 类中对此用户名和密码进行硬编码,该类将通过以下代码块对用户进行身份验证 -

final static String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
Context context=null;
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
env.put(Context.SECURITY_PRINCIPAL, System.getProperty("username", "abcd"));
env.put(Context.SECURITY_CREDENTIALS, System.getProperty("password", "xyz")); 
context = new InitialContext(env);

But I just want to bypass this step of username and password.但我只想绕过用户名和密码这一步。 I know in ActiveMQ it is possible by setting <simpleAuthenticationPlugin anonymousAccessAllowed="true"> Similarly can we do the same thing in JMS?我知道在 ActiveMQ 中可以通过设置<simpleAuthenticationPlugin anonymousAccessAllowed="true">同样,我们可以在 JMS 中做同样的事情吗?

I found that in the standalone.xml there is an entry -我发现在 standalone.xml 中有一个条目 -

<security-settings>
  <security-setting match="#">
    <permission type="send" roles="guest"/>
    <permission type="consume" roles="guest"/>
    <permission type="createNonDurableQueue" roles="guest"/>
    <permission type="deleteNonDurableQueue" roles="guest"/>
  </security-setting>
</security-settings>

I am sure we need to modify this section, but didn't found any reference.我确定我们需要修改此部分,但没有找到任何参考。

How can we allow an anonymous username to send messages to a JMS queue or topic?我们如何允许匿名用户向 JMS 队列或主题发送消息?

Thanks in advance...提前致谢...

after some research I found out the answer.经过一番研究,我找到了答案。

In the standalone.xml file under the messaging subsystem - Remove the following lines –在消息子系统下的 standalone.xml 文件中 - 删除以下几行 -

<security-settings>
<security-setting match="#">
<permission type="send" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
</security-setting>

Instead add the following line in that same place –而是在同一位置添加以下行 –

<security-enabled>false</security-enabled>

Under the remoting subsystem we need to remove the security-realm entry.在远程处理子系统下,我们需要删除 security-realm 条目。 So remove the line -所以删除线 -

<connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>

And add the line -并添加行 -

<connector name="remoting-connector" socket-binding="remoting"/>

With this we can do the following -有了这个,我们可以做到以下几点 -

// Set up the context for the JNDI lookup
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, System.getProperty(Context.PROVIDER_URL, PROVIDER_URL));
// username and password are not required
//env.put(Context.SECURITY_PRINCIPAL, "username");
//env.put(Context.SECURITY_CREDENTIALS, "password");
context = new InitialContext(env);

// Create the JMS connection, session, producer, and consumer
// no need to pass the username and password when create connection
//connection = connectionFactory.createConnection("usernme", "password");
connection = connectionFactory.createConnection();

Thanks Nirmalya谢谢尼尔玛利亚

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM