geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [30/50] [abbrv] incubator-geode git commit: GEODE-17: add the desc for shiro.ini configuration.
Date Fri, 29 Apr 2016 19:23:40 GMT
GEODE-17: add the desc for shiro.ini configuration.

* added tests around DistributionConfig
* make sure getSecurityProperties will return the correct settings


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/adb7208f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/adb7208f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/adb7208f

Branch: refs/heads/develop
Commit: adb7208fa27098c29ac086dbec76676ed7b85427
Parents: da0bbfe
Author: Jinmei Liao <jiliao@pivotal.io>
Authored: Fri Apr 22 15:48:09 2016 -0700
Committer: Jinmei Liao <jiliao@pivotal.io>
Committed: Fri Apr 22 15:48:09 2016 -0700

----------------------------------------------------------------------
 .../internal/AbstractDistributionConfig.java    | 42 +++++++++++---------
 .../internal/DistributionConfigImpl.java        | 25 +++++++-----
 .../internal/SystemManagementService.java       |  2 +-
 .../internal/DistributionConfigJUnitTest.java   | 36 +++++++++++++++--
 .../cli/commands/CliCommandTestBase.java        |  4 ++
 5 files changed, 76 insertions(+), 33 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/adb7208f/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/AbstractDistributionConfig.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/AbstractDistributionConfig.java
b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/AbstractDistributionConfig.java
index c742005..e8dafb8 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/AbstractDistributionConfig.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/AbstractDistributionConfig.java
@@ -16,6 +16,17 @@
  */
 package com.gemstone.gemfire.distributed.internal;
 
+import java.lang.reflect.Method;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
 import com.gemstone.gemfire.InternalGemFireException;
 import com.gemstone.gemfire.InvalidValueException;
 import com.gemstone.gemfire.UnmodifiableException;
@@ -27,11 +38,6 @@ import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 import com.gemstone.gemfire.internal.logging.LogWriterImpl;
 import com.gemstone.gemfire.memcached.GemFireMemcachedServer;
 
-import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.*;
-
 /**
  * Provides an implementation of <code>DistributionConfig</code> that
  * knows how to read the configuration file.
@@ -513,6 +519,14 @@ public abstract class AbstractDistributionConfig
       return;
     }
 
+    if (attName.startsWith(SECURITY_PREFIX_NAME)) {
+      this.setSecurity(attName,attValue.toString());
+    }
+
+    if (attName.startsWith(SSL_SYSTEM_PROPS_NAME) || attName.startsWith(SYS_PROP_NAME)) {
+      this.setSSLProperty(attName, attValue.toString());
+    }
+
     // special case: log-level and security-log-level attributes are String type, but the
setter accepts int
     if(attName.equalsIgnoreCase(LOG_LEVEL_NAME) || attName.equalsIgnoreCase(SECURITY_LOG_LEVEL_NAME)){
       attValue = LogWriterImpl.levelNameToCode((String)attValue);
@@ -520,17 +534,6 @@ public abstract class AbstractDistributionConfig
 
     Method setter = setters.get(attName);
     if (setter == null) {
-      // if we cann't find the defined setter, look for two more special cases
-      if (attName.startsWith(SECURITY_PREFIX_NAME)) {
-        this.setSecurity(attName,(String)attValue);
-        getAttSourceMap().put(attName, source);
-        return;
-      }
-      if (attName.startsWith(SSL_SYSTEM_PROPS_NAME) || attName.startsWith(SYS_PROP_NAME))
{
-        this.setSSLProperty(attName, (String) attValue);
-        getAttSourceMap().put(attName, source);
-        return;
-      }
       throw new InternalGemFireException(LocalizedStrings.AbstractDistributionConfig_UNHANDLED_ATTRIBUTE_NAME_0.toLocalizedString(attName));
     }
 
@@ -1107,12 +1110,15 @@ public abstract class AbstractDistributionConfig
     
     m.put(HTTP_SERVICE_SSL_TRUSTSTORE_PASSWORD_NAME,"Password to unlock the keystore file
(store password) specified by  javax.net.ssl.trustStore.");
     
-    
     m.put(START_DEV_REST_API_NAME, "If true then the developer(API) REST service will be
started when the cache is created. Defaults to false.");
     m.put(OFF_HEAP_MEMORY_SIZE_NAME, LocalizedStrings.AbstractDistributionConfig_OFF_HEAP_MEMORY_SIZE_0.toLocalizedString(DEFAULT_OFF_HEAP_MEMORY_SIZE));
-    dcAttDescriptions = Collections.unmodifiableMap(m);
     m.put(LOCK_MEMORY_NAME, LocalizedStrings.AbstractDistributionConfig_LOCK_MEMORY.toLocalizedString(DEFAULT_LOCK_MEMORY));
     m.put(DISTRIBUTED_TRANSACTIONS_NAME, "Flag to indicate whether all transactions including
JTA should be distributed transactions.  Default is false, meaning colocated transactions.");
+
+    m.put(SHIRO_INIT_NAME, "The name of the shiro configuration file in the classpath, e.g.
shiro.ini");
+
+    dcAttDescriptions = Collections.unmodifiableMap(m);
+
   }
   /**
    * Used by unit tests.

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/adb7208f/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionConfigImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionConfigImpl.java
b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionConfigImpl.java
index bac66c6..8b6b632 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionConfigImpl.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/DistributionConfigImpl.java
@@ -17,6 +17,21 @@
 
 package com.gemstone.gemfire.distributed.internal;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.Serializable;
+import java.net.InetAddress;
+import java.net.URL;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
 import com.gemstone.gemfire.GemFireConfigException;
 import com.gemstone.gemfire.GemFireIOException;
 import com.gemstone.gemfire.distributed.DistributedSystem;
@@ -26,14 +41,6 @@ import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 import com.gemstone.gemfire.internal.process.ProcessLauncherContext;
 import com.gemstone.gemfire.memcached.GemFireMemcachedServer;
 
-import java.io.File;
-import java.io.IOException;
-import java.io.Serializable;
-import java.net.InetAddress;
-import java.net.URL;
-import java.net.UnknownHostException;
-import java.util.*;
-
 /**
  * Provides an implementation of <code>DistributionConfig</code> that
  * knows how to read the configuration file.
@@ -1998,7 +2005,6 @@ public class DistributionConfigImpl
   }
 
   public void setSecurity(String attName, String attValue) {
-    checkAttribute(attName, attValue);
     security.setProperty(attName, attValue);
   }
 
@@ -2039,7 +2045,6 @@ public class DistributionConfigImpl
   }
 
   public void setSSLProperty(String attName, String attValue) {
-    checkAttribute(attName, attValue);
     if (attName.startsWith(SYS_PROP_NAME)) {
       attName = attName.substring(SYS_PROP_NAME.length());
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/adb7208f/geode-core/src/main/java/com/gemstone/gemfire/management/internal/SystemManagementService.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/SystemManagementService.java
b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/SystemManagementService.java
index 45ec358..7fec9b7 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/management/internal/SystemManagementService.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/management/internal/SystemManagementService.java
@@ -168,7 +168,7 @@ public final class SystemManagementService extends BaseManagementService
{
       SecurityUtils.setSecurityManager(securityManager);
     }
     else if (!StringUtils.isBlank(customAuthenticator)) {
-      Realm realm = new CustomAuthRealm(config.toProperties());
+      Realm realm = new CustomAuthRealm(config.getSecurityProps());
       SecurityManager securityManager = new DefaultSecurityManager(realm);
       SecurityUtils.setSecurityManager(securityManager);
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/adb7208f/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionConfigJUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionConfigJUnitTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionConfigJUnitTest.java
index 7a54040..3e7008d 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionConfigJUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/distributed/internal/DistributionConfigJUnitTest.java
@@ -23,6 +23,7 @@ import static org.mockito.Mockito.*;
 import java.io.File;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -31,6 +32,7 @@ import java.util.Properties;
 import com.gemstone.gemfire.InternalGemFireException;
 import com.gemstone.gemfire.UnmodifiableException;
 import com.gemstone.gemfire.internal.ConfigSource;
+import com.gemstone.gemfire.management.internal.security.JSONAuthorization;
 import com.gemstone.gemfire.test.junit.categories.UnitTest;
 
 import org.junit.Before;
@@ -38,11 +40,8 @@ import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.experimental.categories.Category;
 
-/**
- * Created by jiliao on 2/2/16.
- */
-@Category(UnitTest.class)
 
+@Category(UnitTest.class)
 public class DistributionConfigJUnitTest {
   static Map<String, ConfigAttribute> attributes;
   static Map<String, Method> setters;
@@ -108,6 +107,21 @@ public class DistributionConfigJUnitTest {
   }
 
   @Test
+  public void testAttributeDesc(){
+    String[] attNames = AbstractDistributionConfig._getAttNames();
+    for(String attName:attNames){
+      assertTrue("Does not contain description for attribute "+ attName, AbstractDistributionConfig.dcAttDescriptions.containsKey(attName));
+    }
+    List<String> attList = Arrays.asList(attNames);
+    for(Object attName:AbstractDistributionConfig.dcAttDescriptions.keySet()){
+      if(!attList.contains(attName)){
+        System.out.println("Has unused description for "+attName.toString());
+      }
+      //assertTrue("Has unused description for "+attName.toString(), attList.contains(attName));
+    }
+  }
+
+  @Test
   public void sameCount() {
     assertEquals(attributes.size(), setters.size());
     assertEquals(setters.size(), getters.size());
@@ -302,6 +316,20 @@ public class DistributionConfigJUnitTest {
     assertTrue(config.isAttributeModifiable("jmx-manager-http-port"));
   }
 
+
+  @Test
+  public void testSecurityProps(){
+    Properties props = new Properties();
+    props.put(DistributionConfig.SECURITY_CLIENT_AUTHENTICATOR_NAME, JSONAuthorization.class.getName()
+ ".create");
+    props.put(DistributionConfig.SECURITY_CLIENT_ACCESSOR_NAME, JSONAuthorization.class.getName()
+ ".create");
+    props.put(DistributionConfig.SECURITY_LOG_LEVEL_NAME, "config");
+    // add another non-security property to verify it won't get put in the security properties
+    props.put(DistributionConfig.ACK_WAIT_THRESHOLD_NAME, 2);
+
+    DistributionConfig config = new DistributionConfigImpl(props);
+    assertEquals(config.getSecurityProps().size(), 3);
+  }
+
   public final static Map<Class<?>, Class<?>> classMap = new HashMap<Class<?>,
Class<?>>();
 
   static {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/adb7208f/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
index 9ddfbbb..f2dc80f 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/management/internal/cli/commands/CliCommandTestBase.java
@@ -157,6 +157,10 @@ public abstract class CliCommandTestBase extends JUnit4CacheTestCase
{
 
       return results;
     });
+
+    this.jmxHost = (String) result[0];
+    this.jmxPort = (Integer) result[1];
+    this.httpPort = (Integer) result[2];
   }
 
   /**


Mime
View raw message