You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by je...@apache.org on 2017/11/03 01:56:10 UTC

[geode] branch develop updated: GEODE-3941: Pulse issues when SecurityManager is enabled (#1007)

This is an automated email from the ASF dual-hosted git repository.

jensdeppe pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new a8e1fab  GEODE-3941: Pulse issues when SecurityManager is enabled (#1007)
a8e1fab is described below

commit a8e1fab63848b064fdecb2c63fa2fa26e8f06cb4
Author: Jens Deppe <jd...@pivotal.io>
AuthorDate: Thu Nov 2 18:56:08 2017 -0700

    GEODE-3941: Pulse issues when SecurityManager is enabled (#1007)
    
    - Pulse UI is not updated correctly - missing servers for ex.
    - NPE regarding JMXUpdater in pulse.log
---
 .../tools/pulse/PulseSecurityIntegrationTest.java  | 57 ++++++++++++++++++++++
 .../internal/beans/LocatorMBeanBridge.java         |  4 +-
 .../tools/pulse/internal/data/JMXDataUpdater.java  | 30 ++++++++----
 .../src/main/webapp/WEB-INF/spring-security.xml    |  1 +
 4 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseSecurityIntegrationTest.java b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseSecurityIntegrationTest.java
new file mode 100644
index 0000000..7e331d7
--- /dev/null
+++ b/geode-assembly/src/test/java/org/apache/geode/tools/pulse/PulseSecurityIntegrationTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.tools.pulse;
+
+import static java.util.concurrent.TimeUnit.MINUTES;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.examples.SimpleSecurityManager;
+import org.apache.geode.management.ManagementService;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.apache.geode.test.junit.rules.EmbeddedPulseRule;
+import org.apache.geode.test.junit.rules.LocatorStarterRule;
+import org.apache.geode.tools.pulse.internal.data.Cluster;
+
+@Category(IntegrationTest.class)
+public class PulseSecurityIntegrationTest {
+
+  @Rule
+  public LocatorStarterRule locator =
+      new LocatorStarterRule().withSecurityManager(SimpleSecurityManager.class).withAutoStart();
+
+  @Rule
+  public EmbeddedPulseRule pulse = new EmbeddedPulseRule();
+
+  @Test
+  public void getAttributesWithSecurityManager() throws Exception {
+    pulse.useJmxPort(locator.getJmxPort());
+
+    ManagementService service =
+        ManagementService.getExistingManagementService(locator.getLocator().getCache());
+
+    await().atMost(2, MINUTES).until(() -> assertThat(service.getMemberMXBean()).isNotNull());
+
+    Cluster cluster = pulse.getRepository().getCluster("cluster", "cluster");
+    Cluster.Member[] members = cluster.getMembers();
+    assertThat(members.length).isEqualTo(1);
+    assertThat(members[0].getName()).isEqualTo("locator");
+  }
+}
diff --git a/geode-core/src/main/java/org/apache/geode/management/internal/beans/LocatorMBeanBridge.java b/geode-core/src/main/java/org/apache/geode/management/internal/beans/LocatorMBeanBridge.java
index 1597f9f..bb86ac0 100644
--- a/geode-core/src/main/java/org/apache/geode/management/internal/beans/LocatorMBeanBridge.java
+++ b/geode-core/src/main/java/org/apache/geode/management/internal/beans/LocatorMBeanBridge.java
@@ -16,6 +16,7 @@ package org.apache.geode.management.internal.beans;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.InetAddress;
 import java.util.List;
 
 import org.apache.logging.log4j.Logger;
@@ -44,7 +45,8 @@ public class LocatorMBeanBridge {
   }
 
   public String getBindAddress() {
-    return loc.getBindAddress().getCanonicalHostName();
+    InetAddress bindAddress = loc.getBindAddress();
+    return bindAddress != null ? bindAddress.getCanonicalHostName() : null;
   }
 
   public String getHostnameForClients() {
diff --git a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/JMXDataUpdater.java b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/JMXDataUpdater.java
index 2da74f1..f9b6825 100644
--- a/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/JMXDataUpdater.java
+++ b/geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/JMXDataUpdater.java
@@ -17,16 +17,10 @@
 
 package org.apache.geode.tools.pulse.internal.data;
 
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.ObjectNode;
-import org.apache.commons.lang.StringUtils;
-import org.apache.geode.tools.pulse.internal.data.JmxManagerFinder.JmxManagerInfo;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
 import java.io.IOException;
 import java.io.PrintWriter;
 import java.io.StringWriter;
+import java.lang.reflect.Array;
 import java.math.BigDecimal;
 import java.net.Inet4Address;
 import java.net.Inet6Address;
@@ -43,11 +37,14 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.ResourceBundle;
 import java.util.Set;
+import java.util.stream.Collectors;
+
 import javax.management.Attribute;
 import javax.management.AttributeList;
 import javax.management.AttributeNotFoundException;
 import javax.management.InstanceNotFoundException;
 import javax.management.IntrospectionException;
+import javax.management.MBeanAttributeInfo;
 import javax.management.MBeanException;
 import javax.management.MBeanServerConnection;
 import javax.management.MalformedObjectNameException;
@@ -62,6 +59,14 @@ import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 import javax.rmi.ssl.SslRMIClientSocketFactory;
 
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.apache.commons.lang.StringUtils;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import org.apache.geode.tools.pulse.internal.data.JmxManagerFinder.JmxManagerInfo;
+
 /**
  * Class JMXDataUpdater Class used for creating JMX connection and getting all the required MBeans
  * 
@@ -1256,15 +1261,20 @@ public class JMXDataUpdater implements IClusterUpdater, NotificationListener {
    * function used to iterate through all member attributes and return the updated member
    */
   private Cluster.Member initializeMember(ObjectName mbeanName, Cluster.Member member)
-      throws InstanceNotFoundException, ReflectionException, IOException {
+      throws InstanceNotFoundException, ReflectionException, IOException, IntrospectionException {
+
+    MBeanAttributeInfo[] mbeanAttributes = this.mbs.getMBeanInfo(mbeanName).getAttributes();
+    Set<String> mbeanAttributeNames =
+        Arrays.stream(mbeanAttributes).map(MBeanAttributeInfo::getName).collect(Collectors.toSet());
 
     AttributeList attributeList =
-        this.mbs.getAttributes(mbeanName, PulseConstants.MEMBER_MBEAN_ATTRIBUTES);
+        this.mbs.getAttributes(mbeanName, mbeanAttributeNames.toArray(new String[0]));
 
     for (int i = 0; i < attributeList.size(); i++) {
 
       Attribute attribute = (Attribute) attributeList.get(i);
       String name = attribute.getName();
+
       switch (name) {
         case PulseConstants.MBEAN_ATTRIBUTE_GEMFIREVERSION:
           if (member.getGemfireVersion() == null) {
@@ -1424,7 +1434,7 @@ public class JMXDataUpdater implements IClusterUpdater, NotificationListener {
         memberList.add(clusterMember);
         cluster.getPhysicalToMember().put(clusterMember.getHost(), memberList);
       }
-    } catch (InstanceNotFoundException | ReflectionException infe) {
+    } catch (InstanceNotFoundException | ReflectionException | IntrospectionException infe) {
       logger.warn(infe);
     }
   }
diff --git a/geode-pulse/src/main/webapp/WEB-INF/spring-security.xml b/geode-pulse/src/main/webapp/WEB-INF/spring-security.xml
index b8055f1..8cc035d 100644
--- a/geode-pulse/src/main/webapp/WEB-INF/spring-security.xml
+++ b/geode-pulse/src/main/webapp/WEB-INF/spring-security.xml
@@ -29,6 +29,7 @@
 		<!-- Can be invoked w/o auth -->
 		<intercept-url pattern="/login.html" access="permitAll"  />
 		<intercept-url pattern="/authenticateUser" access="permitAll" />
+		<intercept-url pattern="/pulseVersion" access="permitAll" />
 		<!-- Can be invoked w/o auth -->
 
 		<!-- Restricted urls -->

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].