绕过 JConsole 对用户名/密码的要求 - 将 Jaas 自定义登录模块与 JMX 结合使用来处理授权和身份验证
我正在使用JConsole来访问正在运行的MBAan。
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
管理属性文件如下所示:
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;
};
然后,用户将通过命令行通过 JConsole 登录来访问此正在运行的进程。
jconsole -debug //or just jconsole
用户选择“远程连接”,使用远程进程“本地主机:1234”
loginmodule 根据当前登录到 Windows 的用户处理用户验证和主体设置,这用于查询单独的授权逻辑以确定访问级别。
我想发生的事情:
- 用户在 cmd 中输入 jconsole
- 将打开 jconsole 窗口。
- 用户输入进程地址,例如“本地主机:1234”
- 用户不输入用户名或密码(因为这不是必需的,因为授权由自定义 jaas 登录模块处理)。
- 模块确定用户是否具有读写、只读或无访问权限。
- 进程的 Jconsole 窗口打开,或者登录失败。
问题:
要在jconsole窗口中访问jmx进程,我必须输入一个虚拟的用户名和密码,例如U:a,P:a,否则我会收到以下错误:
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 中创建了一个条件,其中用户名和 passowrd 字段必须在字段中打开。
如果此值设置为 false,则从不调用登录模块。
是否可以为特定实例扩展 Jconsole 功能,应用配置设置,或者启用 jaas 登录模块,而无需设置:
-Dcom.sun.management.jmxremote.authenticate=true
为了防止有必要在下面突出显示的以下字段中输入用户名和密码:
我正在寻找一种类似于此处演示的解决方案。但用户无需输入用户名或密码字段。
编辑:另外,为了澄清,这需要在不修改客户端JCONSOLE的情况下完成,因此纯粹使用服务器端更改和设置。