我在jBoss环境中工作并实现了JMS,以实现两个模块之间的异步通信。但为此,我需要通过“add-user.sh”脚本添加用户。然后,用户信息将保存在application-users.properties和application-roles.properties中。然后,我需要在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);
但我只是想绕过这一步用户名和密码。我知道在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队列或主题?
提前致谢...
答案 0 :(得分:1)
在消息传递子系统下的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>
在远程处理子系统下,我们需要删除security-realm条目。所以删除该行 -
<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();
由于 Nirmalya