2015-05-19 21 views
23

我使用JConsole的訪問正在運行一個MBean。繞過用戶名/密碼JConsole的需求 - 使用JAAS自定義登錄模塊時使用JMX處理授權和認證

的MBean的使用自定義JAAS登錄模塊,並使用下面的命令運行:

java -classpath UserLGUGroupHandlingApplication.jar;MBeanSecure.jar 
-com.sun.management.jmxremote.login.config=management.properties 
-Djava.security.auth.login.config=./sample_jaas.config 
com.test.running.RunningImplementation 

隨着management.properties文件看起來像這樣:

com.sun.management.jmxremote.access.file=jmxremote.access 
com.sun.management.jmxremote=true 
com.sun.management.jmxremote.authenticate=true 
com.sun.management.jmxremote.port=1234 
com.sun.management.jmxremote.login.config=Sample 
com.sun.management.jmxremote.ssl=false 
com.sun.management.jmxremote.ssl.need.client.auth=false 

和sample_jaas.config:

Sample { 
    test.module.AETTLoginModule required debug=true; 
}; 

然後用戶將通過登錄通過訪問此正在運行的進程h命令行中的JConsole。

jconsole -debug //or just jconsole 

用戶選擇「遠程連接」,具有RemoteProcess「本地主機:1234」

登錄模塊處理基於當前登錄到Windows用戶,這是用於將用戶驗證和主體的設定查詢單獨的授權邏輯以確定訪問級別。

我想什麼發生:

  1. 用戶enteres JConsole的進入CMD
  2. JConsole窗口中打開。
  3. 用戶輸入過程的地址例如「本地主機:1234」
  4. 用戶輸入用戶名或密碼(因爲這不是必需的授權由自定義JAAS登錄模塊處理)。
  5. 模塊確定用戶是否具有讀寫,只讀或無訪問。打開
  6. 過程JConsole的窗口,或登錄失敗。

的問題:

要訪問JMX過程在JConsole窗口我必須輸入一個虛擬用戶名和密碼,例如U:一,P:一,否則我得到以下錯誤:

java.lang.SecurityException: Authentication failed! Credentials required 
    at com.sun.jmx.remote.security.JMXPluggableAuthenticator.authenticationFailure(JMXPluggableAuthenticator.java:193) 
    at com.sun.jmx.remote.security.JMXPluggableAuthenticator.authenticate(JMXPluggableAuthenticator.java:145) 
    at sun.management.jmxremote.ConnectorBootstrap$AccessFileCheckerAuthenticator.authenticate(ConnectorBootstrap.java:201) 
    at javax.management.remote.rmi.RMIServerImpl.doNewClient(RMIServerImpl.java:213) 
    at javax.management.remote.rmi.RMIServerImpl.newClient(RMIServerImpl.java:180) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:303) 
    at sun.rmi.transport.Transport$1.run(Transport.java:159) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at sun.rmi.transport.Transport.serviceCall(Transport.java:155) 
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918) 
    at java.lang.Thread.run(Thread.java:662) 
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255) 
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233) 
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:142) 
    at javax.management.remote.rmi.RMIServerImpl_Stub.newClient(Unknown Source) 
    at javax.management.remote.rmi.RMIConnector.getConnection(RMIConnector.java:2327) 
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:277) 
    at javax.management.remote.rmi.RMIConnector.connect(RMIConnector.java:225) 
    at sun.tools.jconsole.ProxyClient.tryConnect(ProxyClient.java:334) 
    at sun.tools.jconsole.ProxyClient.connect(ProxyClient.java:296) 
    at sun.tools.jconsole.VMPanel$2.run(VMPanel.java:280) 

問題

對於JAAS登錄模塊運行,我需要以下設置:

-Dcom.sun.management.jmxremote.authenticate=true 

但,這也會在JConsole中創建一個條件,其中用戶名和密碼字段必須在該字段中打開。

如果設置爲false,登錄模塊不會被調用。

是否有可能無需設置任何延長JConsole的功能的特定情況下,應用配置設置,或啓用JAAS登錄模塊:

-Dcom.sun.management.jmxremote.authenticate=true 

爲了防止進入的必要性在以下領域的用戶名和密碼,下面重點介紹:

enter image description here

我在尋找一個類似的解決方案證明here。但不需要用戶輸入用戶名或密碼字段。

編輯:此外,爲了澄清,這將需要完成而無需修改客戶端JCONSOLE,所以通過純粹使用服務器端的更改和設置。

回答

4

經過這個link。特別參見案例3,它可以幫助你。

*****更多的更新後,對問題進行了更多的說明*****************
基本上你試圖實現的是繞過(JAAS提供的)安全對於一個特定的客戶端連接,這是JCONSOLE在你的情況....我建議要麼: - 1)有兩個端口JMX服務器:安全和非安全...使用非安全端口JCONSOLE,或
2)如果您正在編寫自己的自定義JAAS模塊,請嘗試在login()方法中跳過特定客戶端的連接 - 我不確定這是否可行,因爲您如何知道請求客戶端的上下文...

+1

謝謝你,但是,我的問題是專門關於修改用戶的JConsole的需要關於要求的輸入。案例研究重點關注JaasLoginModule和客戶端代碼。 – Loco234

+0

請不要鏈接只有鏈接可能會中斷的答案。 – NathanOliver

+0

Re:編輯。 我很好奇是否有更直接的方法來解決這個問題,因爲使用Jaas登錄模塊是相當常見的需求。使用Jconsole中的字段限制用戶和密碼憑證輸入似乎很奇怪。 我的直接想法是在設置com.sun.management.jmxremote.authenticate = false時指向jaas配置文件。 上下文生成由在loginmodule中調用的單獨腳本處理,有效地繞過了需要檢查用戶憑據的需求,因爲它們將基於當前登錄的用戶。 – Loco234

0

試試這個:

https://blogs.oracle.com/alanb/entry/one_password_to_rule_them假設下面是不是你想要的(由@ ag112基於答案)

-J-Djmx.remote.x.password.file = /路徑/到/文件/ jmx.password然後放你的用戶名/憑證在那裏有空間。

+0

謝謝,但它不是設置密碼文件。相反,需要在jconsole視圖中輸入用戶名和密碼的詳細信息,其中由jaas模塊處理驗證。所以即使字段已滿,輸入也會被丟棄,因爲jaas登錄模塊會處理用戶數據。 – Loco234

+0

從鏈接中,不能指定你自己的登錄模塊嗎? -Dcom.sun.management.jmxremote.login.config = SunConfig -Djava.security.auth.login.config = ldap.config – Optional

+0

是的,我可以指定自己的登錄模塊,但只能用com.sun.management.jmxremote.authenticate = true設置。問題是,Jconsole需要用戶輸入intop用戶名和密碼字段,即使loginmodule沒有查看這些字段。 – Loco234

0

我必須添加另一種答案,從音符像我發現下面:

瀏覽到你想遠程連接(無需用戶名/密碼)的服務器實例。瀏覽服務器實例'server.xml'。尋找標籤,你可能會發現像下面

如果這是在服務器實例配置的,可以不帶任何接入監控:

使用連接字符串下面訪問JConsole的遠程處理。

服務:JMX:RMI://10.10.10.11:8082/JNDI/RMI://10.10.10.11:8081 /服務器

相關問題