Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 136CA200BD4 for ; Fri, 16 Dec 2016 23:09:36 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 1217A160B24; Fri, 16 Dec 2016 22:09:36 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 0F945160B10 for ; Fri, 16 Dec 2016 23:09:34 +0100 (CET) Received: (qmail 35929 invoked by uid 500); 16 Dec 2016 22:09:34 -0000 Mailing-List: contact commits-help@geode.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.apache.org Delivered-To: mailing list commits@geode.apache.org Received: (qmail 35918 invoked by uid 99); 16 Dec 2016 22:09:34 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 16 Dec 2016 22:09:34 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2A2E7DF9A3; Fri, 16 Dec 2016 22:09:34 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: klund@apache.org To: commits@geode.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: geode git commit: GEODE-2207 GEODE-1662: fix and rename SecurityManager callback test Date: Fri, 16 Dec 2016 22:09:34 +0000 (UTC) archived-at: Fri, 16 Dec 2016 22:09:36 -0000 Repository: geode Updated Branches: refs/heads/feature/GEODE-2207 [created] 0585bf9f9 GEODE-2207 GEODE-1662: fix and rename SecurityManager callback test Project: http://git-wip-us.apache.org/repos/asf/geode/repo Commit: http://git-wip-us.apache.org/repos/asf/geode/commit/0585bf9f Tree: http://git-wip-us.apache.org/repos/asf/geode/tree/0585bf9f Diff: http://git-wip-us.apache.org/repos/asf/geode/diff/0585bf9f Branch: refs/heads/feature/GEODE-2207 Commit: 0585bf9f994f0f451cfa13fb0a6fb4bd992f8399 Parents: e3ec736 Author: Kirk Lund Authored: Thu Dec 15 17:02:58 2016 -0800 Committer: Kirk Lund Committed: Fri Dec 16 14:09:02 2016 -0800 ---------------------------------------------------------------------- ...edSecurityCacheLifecycleDistributedTest.java | 131 ------------------ ...SecurityManagerCallbacksDistributedTest.java | 132 +++++++++++++++++++ .../geode/security/SpySecurityManager.java | 6 +- 3 files changed, 135 insertions(+), 134 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/geode/blob/0585bf9f/geode-core/src/test/java/org/apache/geode/security/IntegratedSecurityCacheLifecycleDistributedTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/security/IntegratedSecurityCacheLifecycleDistributedTest.java b/geode-core/src/test/java/org/apache/geode/security/IntegratedSecurityCacheLifecycleDistributedTest.java deleted file mode 100644 index 00a9276..0000000 --- a/geode-core/src/test/java/org/apache/geode/security/IntegratedSecurityCacheLifecycleDistributedTest.java +++ /dev/null @@ -1,131 +0,0 @@ -/* - * 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.security; - -import static org.apache.geode.distributed.ConfigurationProperties.*; -import static org.assertj.core.api.Assertions.*; - -import java.io.IOException; -import java.util.Properties; - -import org.apache.geode.cache.server.CacheServer; -import org.apache.geode.internal.AvailablePortHelper; -import org.apache.geode.internal.security.IntegratedSecurityService; -import org.apache.geode.internal.security.SecurityService; -import org.apache.geode.management.ManagementService; -import org.apache.geode.test.dunit.DistributedTestUtils; -import org.apache.geode.test.dunit.Host; -import org.apache.geode.test.dunit.NetworkUtils; -import org.apache.geode.test.dunit.VM; -import org.apache.geode.test.dunit.cache.internal.JUnit4CacheTestCase; -import org.apache.geode.test.junit.categories.DistributedTest; -import org.apache.geode.test.junit.categories.FlakyTest; -import org.apache.geode.test.junit.categories.SecurityTest; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -@Ignore("This is broken but fixed on feature/GEODE-1673") -@Category({DistributedTest.class, SecurityTest.class}) -public class IntegratedSecurityCacheLifecycleDistributedTest extends JUnit4CacheTestCase { - - private String locators; - private VM locator; - private SecurityService securityService; - - @Override - public final void postSetUp() throws Exception { - Host host = Host.getHost(0); - locator = host.getVM(0); - - securityService = IntegratedSecurityService.getSecurityService(); - - int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2); - int locatorPort = ports[0]; - int managerPort = ports[1]; - - locators = NetworkUtils.getServerHostName(host) + "[" + locatorPort + "]"; - - locator.invoke(() -> { - DistributedTestUtils.deleteLocatorStateFile(locatorPort); - - final Properties properties = new Properties(); - properties.setProperty(TestSecurityManager.SECURITY_JSON, - "org/apache/geode/management/internal/security/clientServer.json"); - properties.setProperty(LOCATORS, locators); - properties.setProperty(MCAST_PORT, "0"); - properties.setProperty(SECURITY_MANAGER, SpySecurityManager.class.getName()); - properties.setProperty(START_LOCATOR, locators); - properties.setProperty(JMX_MANAGER, "true"); - properties.setProperty(JMX_MANAGER_START, "true"); - properties.setProperty(JMX_MANAGER_PORT, String.valueOf(managerPort)); - properties.setProperty(USE_CLUSTER_CONFIGURATION, "false"); - getSystem(properties); - getCache(); - }); - } - - @Category(FlakyTest.class) // GEODE-1662 - @Test - public void initAndCloseTest() throws Exception { - connect(); - - { - ManagementService ms = ManagementService.getExistingManagementService(getCache()); - assertThat(ms).isNotNull(); - assertThat(ms.isManager()).isFalse(); - - verifyInitCloseInvoked(); - } - - locator.invoke(() -> { - ManagementService ms = ManagementService.getExistingManagementService(getCache()); - assertThat(ms).isNotNull(); - assertThat(ms.isManager()).isTrue(); - - verifyInitCloseInvoked(); - }); - } - - private void connect() throws IOException { - final Properties properties = new Properties(); - properties.setProperty(TestSecurityManager.SECURITY_JSON, - "org/apache/geode/management/internal/security/clientServer.json"); - properties.setProperty(LOCATORS, locators); - properties.setProperty(MCAST_PORT, "0"); - properties.setProperty(SECURITY_MANAGER, SpySecurityManager.class.getName()); - properties.setProperty(USE_CLUSTER_CONFIGURATION, "false"); - - getSystem(properties); - - CacheServer server1 = getCache().addCacheServer(); - server1.setPort(0); - server1.start(); - - getCache(); - } - - @Override - public void postTearDownCacheTestCase() throws Exception { - closeAllCache(); - } - - private void verifyInitCloseInvoked() { - SpySecurityManager ssm = (SpySecurityManager) this.securityService.getSecurityManager(); - assertThat(ssm.initInvoked).isEqualTo(1); - getCache().close(); - assertThat(ssm.closeInvoked).isEqualTo(1); - } -} http://git-wip-us.apache.org/repos/asf/geode/blob/0585bf9f/geode-core/src/test/java/org/apache/geode/security/SecurityManagerCallbacksDistributedTest.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/security/SecurityManagerCallbacksDistributedTest.java b/geode-core/src/test/java/org/apache/geode/security/SecurityManagerCallbacksDistributedTest.java new file mode 100644 index 0000000..09c30f5 --- /dev/null +++ b/geode-core/src/test/java/org/apache/geode/security/SecurityManagerCallbacksDistributedTest.java @@ -0,0 +1,132 @@ +/* + * 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.security; + +import static org.apache.geode.distributed.ConfigurationProperties.*; +import static org.apache.geode.internal.AvailablePortHelper.getRandomAvailableTCPPorts; +import static org.apache.geode.internal.security.IntegratedSecurityService.getSecurityService; +import static org.apache.geode.management.ManagementService.getExistingManagementService; +import static org.apache.geode.test.dunit.DistributedTestUtils.deleteLocatorStateFile; +import static org.apache.geode.test.dunit.Host.getHost; +import static org.apache.geode.test.dunit.NetworkUtils.getServerHostName; +import static org.assertj.core.api.Assertions.*; + +import java.io.IOException; +import java.util.Properties; + +import org.apache.geode.cache.server.CacheServer; +import org.apache.geode.cache30.CacheTestCase; +import org.apache.geode.management.ManagementService; +import org.apache.geode.test.dunit.Host; +import org.apache.geode.test.dunit.VM; +import org.apache.geode.test.junit.categories.DistributedTest; +import org.apache.geode.test.junit.categories.SecurityTest; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +@Category({DistributedTest.class, SecurityTest.class}) +public class SecurityManagerCallbacksDistributedTest extends CacheTestCase { + + private String locators; + private VM locatorVM; + + @Before + public void before() throws Exception { + Host host = getHost(0); + this.locatorVM = host.getVM(0); + + int[] ports = getRandomAvailableTCPPorts(2); + int locatorPort = ports[0]; + int managerPort = ports[1]; + + this.locators = getServerHostName(host) + "[" + locatorPort + "]"; + + this.locatorVM.invoke(() -> { + deleteLocatorStateFile(locatorPort); + + Properties properties = new Properties(); + properties.setProperty(LOCATORS, locators); + properties.setProperty(MCAST_PORT, "0"); + properties.setProperty(START_LOCATOR, locators); + properties.setProperty(JMX_MANAGER, "true"); + properties.setProperty(JMX_MANAGER_PORT, String.valueOf(managerPort)); + properties.setProperty(JMX_MANAGER_START, "true"); + properties.setProperty(USE_CLUSTER_CONFIGURATION, "false"); + properties.setProperty(SECURITY_MANAGER, SpySecurityManager.class.getName()); + properties.setProperty("security-username", "secure"); + properties.setProperty("security-password", "secure"); + + getSystem(properties); + getCache(); + }); + } + + @After + public void after() throws Exception { + closeAllCache(); + } + + @Test + public void callbacksShouldBeInvoked() throws Exception { + connectServer(); + + verifyCallbacksRegardlessOfManager(false); + + this.locatorVM.invoke(() -> { + verifyCallbacksRegardlessOfManager(true); + }); + } + + private void connectServer() throws IOException { + Properties properties = new Properties(); + properties.setProperty(LOCATORS, locators); + properties.setProperty(MCAST_PORT, "0"); + properties.setProperty(USE_CLUSTER_CONFIGURATION, "false"); + properties.setProperty(SECURITY_MANAGER, SpySecurityManager.class.getName()); + properties.setProperty("security-username", "secure"); + properties.setProperty("security-password", "secure"); + + getSystem(properties); + + CacheServer server1 = getCache().addCacheServer(); + server1.setPort(0); + server1.start(); + + getCache(); + } + + private void verifyCallbacksRegardlessOfManager(final boolean isManager) { + ManagementService ms = getExistingManagementService(getCache()); + assertThat(ms).isNotNull(); + assertThat(ms.isManager()).isEqualTo(isManager); + + verifyInitAndCloseInvoked(); + } + + private void verifyInitAndCloseInvoked() { + SpySecurityManager ssm = (SpySecurityManager) getSecurityService().getSecurityManager(); + + assertThat(ssm.initInvoked).isEqualTo(1); + assertThat(ssm.closeInvoked).isEqualTo(0); + + getCache().close(); + + assertThat(ssm.initInvoked).isEqualTo(1); + assertThat(ssm.closeInvoked).isEqualTo(1); + } +} http://git-wip-us.apache.org/repos/asf/geode/blob/0585bf9f/geode-core/src/test/java/org/apache/geode/security/SpySecurityManager.java ---------------------------------------------------------------------- diff --git a/geode-core/src/test/java/org/apache/geode/security/SpySecurityManager.java b/geode-core/src/test/java/org/apache/geode/security/SpySecurityManager.java index 8704e93..1109489 100644 --- a/geode-core/src/test/java/org/apache/geode/security/SpySecurityManager.java +++ b/geode-core/src/test/java/org/apache/geode/security/SpySecurityManager.java @@ -18,7 +18,7 @@ import java.util.Properties; import org.apache.geode.security.SecurityManager; -public class SpySecurityManager implements SecurityManager { +public class SpySecurityManager extends SimpleTestSecurityManager { public int initInvoked = 0; public int closeInvoked = 0; @@ -29,8 +29,8 @@ public class SpySecurityManager implements SecurityManager { } @Override - public Object authenticate(final Properties props) throws AuthenticationFailedException { - return null; + public boolean authorize(final Object principal, final ResourcePermission permission) { + return true; } @Override