2016-03-07 64 views
1

我正在jBoss環境中工作,並實現了JMS以支持兩個模塊之間的異步通信。但爲此,我需要通過「add-user.sh」腳本添加用戶。然後將用戶信息保存在application-users.properties和application-roles.properties中。然後,我需要硬編碼在MessagePublisher類此用戶名和密碼,誰將會通過下面的代碼塊驗證用戶 -我們可以在沒有用戶名和密碼的情況下設置JMS通信嗎?

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

經過一番研究,我找到了答案。

在傳輸子系統下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(); 

感謝 Nirmalya

相關問題