geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jche...@apache.org
Subject [geode] branch support/1.12 updated: GEODE-9515: Skip setting MBeanServer when JMXConnectorServer will set it (#6770)
Date Fri, 03 Sep 2021 20:04:06 GMT
This is an automated email from the ASF dual-hosted git repository.

jchen21 pushed a commit to branch support/1.12
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/support/1.12 by this push:
     new 23a2c27  GEODE-9515: Skip setting MBeanServer when JMXConnectorServer will set it
(#6770)
23a2c27 is described below

commit 23a2c2748d750a4e3404fd761f32c0f0c6f9404f
Author: Jianxia Chen <11181423+jchen21@users.noreply.github.com>
AuthorDate: Mon Aug 23 14:06:09 2021 -0700

    GEODE-9515: Skip setting MBeanServer when JMXConnectorServer will set it (#6770)
    
    (cherry picked from commit 280bd841427f244f507633826def2f845a9b10ef)
---
 .../internal/ManagementAgentIntegrationTest.java   | 123 +++++++++++++++++++++
 .../geode/management/internal/ManagementAgent.java |  27 +++--
 2 files changed, 142 insertions(+), 8 deletions(-)

diff --git a/geode-core/src/integrationTest/java/org/apache/geode/management/internal/ManagementAgentIntegrationTest.java
b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/ManagementAgentIntegrationTest.java
new file mode 100644
index 0000000..15815a5
--- /dev/null
+++ b/geode-core/src/integrationTest/java/org/apache/geode/management/internal/ManagementAgentIntegrationTest.java
@@ -0,0 +1,123 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information
regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version
2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain
a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under
the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
express
+ * or implied. See the License for the specific language governing permissions and limitations
under
+ * the License.
+ */
+package org.apache.geode.management.internal;
+
+import static org.assertj.core.api.Assertions.assertThatCode;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.management.ManagementFactory;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.management.MBeanServer;
+import javax.management.remote.JMXConnectorServer;
+import javax.management.remote.JMXServiceURL;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.internal.cache.InternalCache;
+import org.apache.geode.internal.security.SecurityService;
+
+public class ManagementAgentIntegrationTest {
+
+  // private ManagementAgent managementAgent = spy(ManagementAgent.class);
+  @Rule
+  public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+  @Test
+  public void testSetMBeanServer() throws IOException {
+    DistributionConfig distributionConfig = mock(DistributionConfig.class);
+    InternalCache internalCache = mock(InternalCache.class);
+    JmxRmiSerialFilter serialFilter = mock(JmxRmiSerialFilter.class);
+    SecurityService securityService = mock(SecurityService.class);
+    when(internalCache.getSecurityService()).thenReturn(securityService);
+    when(securityService.isIntegratedSecurity()).thenReturn(false);
+    File tempFile = temporaryFolder.newFile("testFile");
+    when(distributionConfig.getJmxManagerAccessFile()).thenReturn(tempFile.getCanonicalPath());
+    ManagementAgent managementAgent =
+        new ManagementAgent(distributionConfig, internalCache, serialFilter);
+    MBeanServer mBeanServer = mock(MBeanServer.class);
+    JMXConnectorServer jmxConnectorServerWithMBeanServer = new JMXConnectorServer(mBeanServer)
{
+      @Override
+      public void start() throws IOException {
+
+      }
+
+      @Override
+      public void stop() throws IOException {
+
+      }
+
+      @Override
+      public boolean isActive() {
+        return false;
+      }
+
+      @Override
+      public JMXServiceURL getAddress() {
+        return null;
+      }
+
+      @Override
+      public Map<String, ?> getAttributes() {
+        return null;
+      }
+    };
+    managementAgent.setJmxConnectorServer(jmxConnectorServerWithMBeanServer);
+    assertThatCode(() -> managementAgent
+        .setMBeanServerForwarder(ManagementFactory.getPlatformMBeanServer(), new HashMap<>()))
+            .doesNotThrowAnyException();
+    managementAgent.setMBeanServerForwarder(ManagementFactory.getPlatformMBeanServer(),
+        new HashMap<>());
+
+    JMXConnectorServer jmxConnectorServerNullMBeanServer = new JMXConnectorServer() {
+      @Override
+      public void start() throws IOException {
+
+      }
+
+      @Override
+      public void stop() throws IOException {
+
+      }
+
+      @Override
+      public boolean isActive() {
+        return false;
+      }
+
+      @Override
+      public JMXServiceURL getAddress() {
+        return null;
+      }
+
+      @Override
+      public Map<String, ?> getAttributes() {
+        return null;
+      }
+    };
+
+    managementAgent.setJmxConnectorServer(jmxConnectorServerNullMBeanServer);
+    assertThatCode(() -> managementAgent
+        .setMBeanServerForwarder(ManagementFactory.getPlatformMBeanServer(), new HashMap<>()))
+            .doesNotThrowAnyException();
+  }
+}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java
b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java
index dbd96d6..9c36e49 100755
--- a/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/ManagementAgent.java
@@ -51,6 +51,7 @@ import org.apache.commons.lang3.StringUtils;
 import org.apache.logging.log4j.Logger;
 
 import org.apache.geode.GemFireConfigException;
+import org.apache.geode.annotations.VisibleForTesting;
 import org.apache.geode.cache.internal.HttpService;
 import org.apache.geode.distributed.internal.DistributionConfig;
 import org.apache.geode.internal.GemFireVersion;
@@ -417,6 +418,19 @@ public class ManagementAgent {
           }
         };
 
+    setMBeanServerForwarder(mbs, env);
+    registerAccessControlMBean();
+    registerFileUploaderMBean();
+
+    jmxConnectorServer.start();
+    if (logger.isDebugEnabled()) {
+      logger.debug("Finished starting jmx manager agent.");
+    }
+  }
+
+  @VisibleForTesting
+  void setMBeanServerForwarder(MBeanServer mbs, HashMap<String, Object> env)
+      throws IOException {
     if (securityService.isIntegratedSecurity()) {
       shiroAuthenticator = new JMXShiroAuthenticator(this.securityService);
       env.put(JMXConnectorServer.AUTHENTICATOR, shiroAuthenticator);
@@ -437,20 +451,12 @@ public class ManagementAgent {
       if (accessFile != null && accessFile.length() > 0) {
         // Rewire the mbs hierarchy to set accessController
         ReadOpFileAccessController controller = new ReadOpFileAccessController(accessFile);
-        controller.setMBeanServer(mbs);
         jmxConnectorServer.setMBeanServerForwarder(controller);
       } else {
         // if no access control, do not allow mbean creation to prevent Mlet attack
         jmxConnectorServer.setMBeanServerForwarder(new BlockMBeanCreationController());
       }
     }
-    registerAccessControlMBean();
-    registerFileUploaderMBean();
-
-    jmxConnectorServer.start();
-    if (logger.isDebugEnabled()) {
-      logger.debug("Finished starting jmx manager agent.");
-    }
   }
 
   private void registerAccessControlMBean() {
@@ -496,6 +502,11 @@ public class ManagementAgent {
     return jmxConnectorServer;
   }
 
+  @VisibleForTesting
+  void setJmxConnectorServer(JMXConnectorServer jmxConnectorServer) {
+    this.jmxConnectorServer = jmxConnectorServer;
+  }
+
   public synchronized RemoteStreamExporter getRemoteStreamExporter() {
     if (remoteStreamExporter == null) {
       remoteStreamExporter =

Mime
View raw message