geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jinmeil...@apache.org
Subject [39/50] [abbrv] incubator-geode git commit: Update init and close on SecurityManager interface
Date Fri, 08 Jul 2016 15:51:59 GMT
Update init and close on SecurityManager interface

* Add close() to SecurityManager interface
* Change init(Properties) to have default empty impl
* Create integration test for init and close


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

Branch: refs/heads/develop
Commit: 0fd2288ecda79f1670553f3198e0ae4aad5e36a6
Parents: 8a26ac0
Author: gmeilen <gracemeilen@gmail.com>
Authored: Wed Jul 6 14:56:26 2016 -0700
Committer: gmeilen <gracemeilen@gmail.com>
Committed: Wed Jul 6 14:57:32 2016 -0700

----------------------------------------------------------------------
 .../internal/cache/GemFireCacheImpl.java        |   4 +-
 .../internal/security/GeodeSecurityUtil.java    |  11 ++
 .../gemfire/security/SecurityManager.java       |   4 +-
 ...edSecurityCacheLifecycleIntegrationTest.java | 104 +++++++++++++++++++
 4 files changed, 121 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0fd2288e/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java
index 13e0602..567f377 100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java
@@ -147,6 +147,7 @@ import com.gemstone.gemfire.internal.logging.LoggingThreadGroup;
 import com.gemstone.gemfire.internal.logging.log4j.LocalizedMessage;
 import com.gemstone.gemfire.internal.offheap.MemoryAllocator;
 import com.gemstone.gemfire.internal.process.ClusterConfigurationNotAvailableException;
+import com.gemstone.gemfire.internal.security.GeodeSecurityUtil;
 import com.gemstone.gemfire.internal.sequencelog.SequenceLoggerImpl;
 import com.gemstone.gemfire.internal.tcp.ConnectionTable;
 import com.gemstone.gemfire.internal.util.concurrent.FutureResult;
@@ -1898,7 +1899,8 @@ public class GemFireCacheImpl implements InternalCache, ClientCache,
HasCachePer
       return;
     }
     final boolean isDebugEnabled = logger.isDebugEnabled();
-    
+    GeodeSecurityUtil.close(system.getConfig().getSecurityProps());
+
     synchronized (GemFireCacheImpl.class) {
       // bugfix for bug 36512 "GemFireCache.close is not thread safe"
       // ALL CODE FOR CLOSE SHOULD NOW BE UNDER STATIC SYNCHRONIZATION

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0fd2288e/geode-core/src/main/java/com/gemstone/gemfire/internal/security/GeodeSecurityUtil.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/internal/security/GeodeSecurityUtil.java
b/geode-core/src/main/java/com/gemstone/gemfire/internal/security/GeodeSecurityUtil.java
index 048b8ba..ff32f92 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/internal/security/GeodeSecurityUtil.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/internal/security/GeodeSecurityUtil.java
@@ -337,6 +337,17 @@ public class GeodeSecurityUtil {
 
   }
 
+  public static void close(Properties securityProps) {
+    if (securityProps != null) {
+      String customAuthenticator = securityProps.getProperty(SECURITY_MANAGER);
+      Object authenticatorObject = getObject(customAuthenticator);
+      if (authenticatorObject != null && authenticatorObject instanceof SecurityManager)
{
+        ((SecurityManager) authenticatorObject).close();
+      }
+    }
+    return;
+  }
+
   public static Object postProcess(String regionPath, Object key, Object result){
     if(postProcessor == null)
       return result;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0fd2288e/geode-core/src/main/java/com/gemstone/gemfire/security/SecurityManager.java
----------------------------------------------------------------------
diff --git a/geode-core/src/main/java/com/gemstone/gemfire/security/SecurityManager.java b/geode-core/src/main/java/com/gemstone/gemfire/security/SecurityManager.java
index b19e5a8..eff27ae 100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/security/SecurityManager.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/security/SecurityManager.java
@@ -22,11 +22,13 @@ import java.util.Properties;
 
 public interface SecurityManager {
 
-  void init(Properties securityProps);
+  default void init(Properties securityProps) {}
 
   Principal authenticate(Properties props) throws AuthenticationFailedException;
 
   default boolean authorize(Principal principal, GeodePermission permission) {
     return true;
   }
+
+  default void close() {}
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/0fd2288e/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedSecurityCacheLifecycleIntegrationTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedSecurityCacheLifecycleIntegrationTest.java
b/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedSecurityCacheLifecycleIntegrationTest.java
new file mode 100644
index 0000000..96a4a51
--- /dev/null
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/IntegratedSecurityCacheLifecycleIntegrationTest.java
@@ -0,0 +1,104 @@
+/*
+ * 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 com.gemstone.gemfire.security;
+
+import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
+import static org.assertj.core.api.Assertions.*;
+
+import java.security.Principal;
+import java.util.Properties;
+
+import com.gemstone.gemfire.cache.Cache;
+import com.gemstone.gemfire.cache.CacheFactory;
+import com.gemstone.gemfire.test.junit.categories.IntegrationTest;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+@Category(IntegrationTest.class)
+public class IntegratedSecurityCacheLifecycleIntegrationTest {
+
+  private static SpySecurityManager spySecurityManager;
+
+  private Properties securityProps;
+  private Cache cache;
+
+  @Before
+  public void before() {
+    securityProps = new Properties();
+    securityProps.setProperty(SECURITY_MANAGER, SpySecurityManager.class.getName()+".create");
+
+    spySecurityManager = new SpySecurityManager();
+
+    Properties props = new Properties();
+    props.putAll(securityProps);
+    props.setProperty(MCAST_PORT, "0");
+    props.setProperty(LOCATORS, "");
+
+    cache = new CacheFactory(props).create();
+  }
+
+  @After
+  public void after() {
+    if (cache != null && !cache.isClosed()) {
+      cache.close();
+    }
+  }
+
+  @Test
+  public void initAndCloseTest () {
+    assertThat(spySecurityManager.initInvoked).isEqualTo(1);
+    assertThat(spySecurityManager.securityPropsInvoked).isEqualTo(securityProps);
+    cache.close();
+    assertThat(spySecurityManager.closeInvoked).isEqualTo(1);
+  }
+
+  public static class SpySecurityManager implements SecurityManager {
+
+    private int initInvoked = 0;
+    private int closeInvoked = 0;
+    private Properties securityPropsInvoked;
+
+    public static SecurityManager create() {
+      return spySecurityManager;
+    }
+
+    @Override
+    public void init(final Properties securityProps) {
+      initInvoked++;
+      this.securityPropsInvoked = securityProps;
+    }
+
+    @Override
+    public Principal authenticate(final Properties props) throws AuthenticationFailedException
{
+      return null;
+    }
+
+    @Override
+    public boolean authorize(final Principal principal, final GeodePermission permission)
{
+      return false;
+    }
+
+    @Override
+    public void close() {
+      closeInvoked++;
+    }
+  }
+}


Mime
View raw message