我们可以在没有用户名和密码的情况下设置 JMS 通信吗?
Can we setup JMS communication without username and password?
我在 jBoss 环境中工作并实现了 JMS 以实现两个模块之间的异步通信。但是为此我需要通过 "add-user.sh" 脚本添加用户。然后将用户信息保存在application-users.properties和application-roles.properties中。然后我需要在 MessagePublisher class 中硬编码此用户名和密码,后者将通过以下代码块验证用户 -
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);
但是我只想绕过用户名和密码这一步。我知道在 ActiveMQ 中可以通过设置 <simpleAuthenticationPlugin anonymousAccessAllowed="true">
同样地我们可以在 JMS 中做同样的事情吗?
我发现在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>
我确定我们需要修改此部分,但没有找到任何参考。
我们如何允许匿名用户名向 JMS 队列或主题发送消息?
提前致谢...
经过一番研究,我找到了答案。
在消息子系统下的 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-enabled>false</security-enabled>
在远程处理子系统下,我们需要删除安全领域条目。所以删除行 -
<connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
并添加行 -
<connector name="remoting-connector" socket-binding="remoting"/>
有了这个我们可以做以下事情-
// 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();
谢谢
尼尔玛利亚
我在 jBoss 环境中工作并实现了 JMS 以实现两个模块之间的异步通信。但是为此我需要通过 "add-user.sh" 脚本添加用户。然后将用户信息保存在application-users.properties和application-roles.properties中。然后我需要在 MessagePublisher class 中硬编码此用户名和密码,后者将通过以下代码块验证用户 -
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);
但是我只想绕过用户名和密码这一步。我知道在 ActiveMQ 中可以通过设置 <simpleAuthenticationPlugin anonymousAccessAllowed="true">
同样地我们可以在 JMS 中做同样的事情吗?
我发现在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>
我确定我们需要修改此部分,但没有找到任何参考。
我们如何允许匿名用户名向 JMS 队列或主题发送消息?
提前致谢...
经过一番研究,我找到了答案。
在消息子系统下的 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-enabled>false</security-enabled>
在远程处理子系统下,我们需要删除安全领域条目。所以删除行 -
<connector name="remoting-connector" socket-binding="remoting" security-realm="ApplicationRealm"/>
并添加行 -
<connector name="remoting-connector" socket-binding="remoting"/>
有了这个我们可以做以下事情-
// 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();
谢谢 尼尔玛利亚