You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by hi...@apache.org on 2016/09/13 22:56:13 UTC
[11/15] incubator-geode git commit: GEODE-37 Renamed security related
stuff
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d7a6960/geode-core/src/test/java/com/gemstone/gemfire/security/NoShowValue1PostProcessorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/NoShowValue1PostProcessorDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/NoShowValue1PostProcessorDUnitTest.java
deleted file mode 100644
index 5d071a8..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/NoShowValue1PostProcessorDUnitTest.java
+++ /dev/null
@@ -1,86 +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 com.gemstone.gemfire.security;
-
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.client.ClientCache;
-import com.gemstone.gemfire.cache.client.Pool;
-import com.gemstone.gemfire.cache.client.PoolManager;
-import com.gemstone.gemfire.cache.query.SelectResults;
-import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-import com.gemstone.gemfire.test.junit.categories.SecurityTest;
-
-@Category({ DistributedTest.class, SecurityTest.class })
-public class NoShowValue1PostProcessorDUnitTest extends AbstractSecureServerDUnitTest {
-
- public NoShowValue1PostProcessorDUnitTest(){
- this.postProcessor = NoShowValue1PostProcessor.class;
- }
-
- @Test
- public void testPostProcess(){
- List<String> keys = new ArrayList<>();
- keys.add("key1");
- keys.add("key2");
-
- client1.invoke(()->{
- ClientCache cache = createClientCache("super-user", "1234567", serverPort);
- Region region = cache.getRegion(REGION_NAME);
-
- // post process for get
- assertEquals("value3", region.get("key3"));
-
- assertNull(region.get("key1"));
-
- // post processs for getAll
- Map values = region.getAll(keys);
- assertEquals(2, values.size());
- assertEquals("value2", values.get("key2"));
- assertNull(values.get("key1"));
-
- // post process for query
- String query = "select * from /AuthRegion";
- SelectResults result = region.query(query);
- System.out.println("query result: "+result);
- assertEquals(5, result.size());
- assertTrue(result.contains("value0"));
- assertFalse(result.contains("value1"));
- assertTrue(result.contains("value2"));
- assertTrue(result.contains("value3"));
- assertTrue(result.contains("value4"));
-
- Pool pool = PoolManager.find(region);
- result = (SelectResults)pool.getQueryService().newQuery(query).execute();
- System.out.println("query result: "+result);
- assertTrue(result.contains("value0"));
- assertFalse(result.contains("value1"));
- assertTrue(result.contains("value2"));
- assertTrue(result.contains("value3"));
- assertTrue(result.contains("value4"));
- });
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d7a6960/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java
deleted file mode 100644
index 67dfadc..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/NotAuthorizedExceptionTest.java
+++ /dev/null
@@ -1,200 +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 com.gemstone.gemfire.security;
-
-import static com.googlecode.catchexception.CatchException.*;
-import static org.assertj.core.api.Assertions.*;
-import static org.mockito.Mockito.*;
-
-import java.io.NotSerializableException;
-import java.io.Serializable;
-import java.security.Principal;
-import javax.naming.NamingException;
-
-import org.apache.commons.lang.SerializationUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.rules.TestName;
-
-import com.gemstone.gemfire.test.junit.categories.SecurityTest;
-import com.gemstone.gemfire.test.junit.categories.UnitTest;
-
-/**
- * Unit tests for {@link NotAuthorizedException}.
- */
-@Category({ UnitTest.class, SecurityTest.class })
-public class NotAuthorizedExceptionTest {
-
- private String message;
- private String causeMessage;
- private Object nonSerializableResolvedObj;
- private NamingException nonSerializableNamingException;
- private SerializableObject serializableResolvedObj;
- private NamingException serializableNamingException;
- private String principalName;
- private Principal nonSerializablePrincipal;
- private SerializablePrincipal serializablePrincipal;
-
- @Rule
- public TestName testName = new TestName();
-
- @Before
- public void setUp() throws Exception {
- this.message = testName.getMethodName() + " message";
- this.causeMessage = testName.getMethodName() + " cause message";
-
- this.nonSerializableResolvedObj = new Object();
- this.nonSerializableNamingException = new NamingException(this.causeMessage);
- this.nonSerializableNamingException.setResolvedObj(this.nonSerializableResolvedObj);
-
- this.serializableResolvedObj = new SerializableObject(this.testName.getMethodName());
- this.serializableNamingException = new NamingException(this.causeMessage);
- this.serializableNamingException.setResolvedObj(this.serializableResolvedObj);
-
- this.principalName = "jsmith";
- this.nonSerializablePrincipal = mock(Principal.class);
- this.serializablePrincipal = new SerializablePrincipal(this.principalName);
-
- assertPreconditions();
- }
-
- private void assertPreconditions() {
- catchException(this).clone(this.nonSerializableNamingException);
- assertThat((Throwable)caughtException()).isNotNull();
- assertThat((Throwable)caughtException().getCause()).isInstanceOf(NotSerializableException.class);
-
- catchException(this).clone(this.serializableNamingException);
- assertThat((Throwable)caughtException()).isNull();
-
- assertThat(this.nonSerializableResolvedObj).isNotInstanceOf(Serializable.class);
-
- catchException(this).clone(this.serializableResolvedObj);
- assertThat((Throwable)caughtException()).isNull();
-
- assertThat(this.nonSerializablePrincipal).isNotInstanceOf(Serializable.class);
-
- catchException(this).clone(this.serializablePrincipal);
- assertThat((Throwable)caughtException()).isNull();
- }
-
- @Test
- public void isSerializable() throws Exception {
- assertThat(NotAuthorizedException.class).isInstanceOf(Serializable.class);
- }
-
- @Test
- public void serializes() throws Exception {
- NotAuthorizedException instance = new NotAuthorizedException(this.message);
-
- NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
-
- assertThat(cloned).hasMessage(this.message);
- }
-
- @Test
- public void serializesWithThrowable() throws Exception {
- Throwable cause = new Exception(this.causeMessage);
- NotAuthorizedException instance = new NotAuthorizedException(this.message, cause);
-
- NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
-
- assertThat(cloned).hasMessage(this.message);
- assertThat(cloned).hasCause(cause);
- }
-
- @Test
- public void serializesWithNonSerializablePrincipal() throws Exception {
- NotAuthorizedException instance = new NotAuthorizedException(this.message, this.nonSerializablePrincipal);
- assertThat(instance.getPrincipal()).isNotNull();
-
- NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
-
- assertThat(cloned).hasMessage(this.message);
- assertThat(cloned.getPrincipal()).isNull();
- }
-
- @Test
- public void serializesWithSerializablePrincipal() throws Exception {
- NotAuthorizedException instance = new NotAuthorizedException(this.message, this.serializablePrincipal);
-
- NotAuthorizedException cloned = (NotAuthorizedException) SerializationUtils.clone(instance);
-
- assertThat(cloned).hasMessage(this.message);
- assertThat(cloned.getPrincipal()).isNotNull().isEqualTo(this.serializablePrincipal);
- }
-
- public Object clone(final Serializable object) {
- return SerializationUtils.clone(object);
- }
-
- public static class SerializableObject implements Serializable {
-
- private String name;
-
- SerializableObject(String name) {
- this.name = name;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- SerializableObject that = (SerializableObject) o;
-
- return name != null ? name.equals(that.name) : that.name == null;
-
- }
-
- @Override
- public int hashCode() {
- return name != null ? name.hashCode() : 0;
- }
- }
-
- public static class SerializablePrincipal implements Principal, Serializable {
-
- private String name;
-
- SerializablePrincipal(String name) {
- this.name = name;
- }
-
- @Override
- public String getName() {
- return this.name;
- }
-
- @Override
- public boolean equals(Object o) {
- if (this == o) return true;
- if (o == null || getClass() != o.getClass()) return false;
-
- SerializablePrincipal that = (SerializablePrincipal) o;
-
- return name != null ? name.equals(that.name) : that.name == null;
-
- }
-
- @Override
- public int hashCode() {
- return name != null ? name.hashCode() : 0;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d7a6960/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java
deleted file mode 100644
index cb1836e..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java
+++ /dev/null
@@ -1,541 +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 com.gemstone.gemfire.security;
-
-import com.gemstone.gemfire.distributed.ConfigurationProperties;
-import com.gemstone.gemfire.distributed.DistributedSystem;
-import com.gemstone.gemfire.distributed.Locator;
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.distributed.internal.membership.MembershipManager;
-import com.gemstone.gemfire.distributed.internal.membership.gms.MembershipManagerHelper;
-import com.gemstone.gemfire.security.generator.CredentialGenerator;
-import com.gemstone.gemfire.security.generator.DummyCredentialGenerator;
-import com.gemstone.gemfire.security.generator.LdapUserCredentialGenerator;
-import com.gemstone.gemfire.security.generator.UserPasswordWithExtraPropsAuthInit;
-import com.gemstone.gemfire.security.templates.LdapUserAuthenticator;
-import com.gemstone.gemfire.security.templates.UserPasswordAuthInit;
-import com.gemstone.gemfire.test.dunit.Host;
-import com.gemstone.gemfire.test.dunit.VM;
-import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
-import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-import com.gemstone.gemfire.test.junit.categories.FlakyTest;
-import com.gemstone.gemfire.test.junit.categories.SecurityTest;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import javax.net.ssl.SSLHandshakeException;
-import java.util.Properties;
-
-import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
-import static com.gemstone.gemfire.internal.AvailablePort.SOCKET;
-import static com.gemstone.gemfire.internal.AvailablePort.getRandomAvailablePort;
-import static com.gemstone.gemfire.security.SecurityTestUtils.startLocator;
-import static com.gemstone.gemfire.security.SecurityTestUtils.stopLocator;
-import static com.gemstone.gemfire.test.dunit.Assert.*;
-import static com.gemstone.gemfire.test.dunit.IgnoredException.addIgnoredException;
-import static com.gemstone.gemfire.test.dunit.NetworkUtils.getIPLiteral;
-import static com.gemstone.gemfire.test.dunit.Wait.pause;
-
-/**
- * Tests peer to peer authentication in Gemfire
- *
- * @since GemFire 5.5
- */
-@Category({ DistributedTest.class, SecurityTest.class })
-public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
-
- private static VM locatorVM = null;
-
- private static final String[] ignoredExceptions = {
- AuthenticationRequiredException.class.getName(),
- AuthenticationFailedException.class.getName(),
- GemFireSecurityException.class.getName(),
- SSLHandshakeException.class.getName(),
- ClassNotFoundException.class.getName(),
- "Authentication failed for",
- "Failed to obtain credentials"
- };
-
- @Override
- public final void postSetUp() throws Exception {
- disconnectAllFromDS();
- locatorVM = Host.getHost(0).getVM(0);
- for (String exceptionString : ignoredExceptions) {
- addIgnoredException(exceptionString);
- }
- }
-
- /**
- * Check that mcast-port setting for discovery or with locator are
- * incompatible with security
- */
- @Test
- public void testIllegalPropertyCombos() throws Exception {
- int port = getRandomAvailablePort(SOCKET);
-
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "26753");
- props.setProperty(ConfigurationProperties.LOCATORS, getIPLiteral() + "[" + port + "]");
- props.setProperty(ConfigurationProperties.SECURITY_PEER_AUTH_INIT, UserPasswordAuthInit.class.getName() + ".create");
- props.setProperty(ConfigurationProperties.ENABLE_CLUSTER_CONFIGURATION, "false");
-
- try {
- Locator.startLocatorAndDS(port, null, null, props);
- fail("Expected an IllegalArgumentException while starting locator");
-
- } catch (IllegalArgumentException ex) {
- // success
- }
-
- // Also try setting the authenticator
- props = new Properties();
- props.setProperty(MCAST_PORT, "26753");
- props.setProperty(LOCATORS, getIPLiteral() + "[" + port + "]");
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, LdapUserAuthenticator.class.getName() + ".create");
- props.setProperty(ENABLE_CLUSTER_CONFIGURATION, "false");
-
- try {
- Locator.startLocatorAndDS(port, null, null, props);
- fail("Expected an IllegalArgumentException while starting locator");
-
- } catch (IllegalArgumentException expected) {
- // success
- }
-
- props = new Properties();
- props.setProperty(MCAST_PORT, "26753");
- props.setProperty(SECURITY_PEER_AUTH_INIT, UserPasswordAuthInit.class.getName() + ".create");
-
- try {
- getSystem(props);
- fail("Expected an IllegalArgumentException while connection to DS");
-
- } catch (IllegalArgumentException expected) {
- // success
- }
-
- // Also try setting the authenticator
- props = new Properties();
- props.setProperty(MCAST_PORT, "26753");
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, LdapUserAuthenticator.class.getName() + ".create");
-
- try {
- getSystem(props);
- fail("Expected an IllegalArgumentException while connection to DS");
-
- } catch (IllegalArgumentException expected) {
- // success
- }
- }
-
- /**
- * AuthInitialize is incorrect
- */
- @Test
- public void testP2PAuthenticationWithInvalidAuthInitialize() throws Exception {
- int locatorPort = getRandomAvailablePort(SOCKET);
-
- CredentialGenerator gen = new DummyCredentialGenerator();
- assertNotNull(gen.getAuthenticator());
- assertNull(gen.getJavaProperties());
-
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
- props.setProperty(SECURITY_PEER_AUTH_INIT, "Incorrect_AuthInitialize");
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
-
- startTheLocator(props, gen.getJavaProperties(), locatorPort);
-
- try {
- new SecurityTestUtils("tmp").createSystem(props, null);
- fail("AuthenticationFailedException was expected as the AuthInitialize object passed is incorrect");
-
- } catch (AuthenticationFailedException expected) {
- // success
-
- } finally {
- locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
- }
- }
-
- /**
- * Authenticator is incorrect
- */
- @Category(FlakyTest.class) // GEODE-1089: random port
- @Test
- public void testP2PAuthenticationWithInvalidAuthenticator() throws Exception {
- int locatorPort = getRandomAvailablePort(SOCKET);
-
- CredentialGenerator gen = new DummyCredentialGenerator();
- assertNotNull(gen.getAuthInit());
- assertNull(gen.getJavaProperties());
-
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
- props.setProperty(SECURITY_PEER_AUTH_INIT, gen.getAuthInit());
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, "xyz");
-
- startTheLocator(props, null, locatorPort);
-
- try {
- new SecurityTestUtils("tmp").createSystem(props, null);
- fail("AuthenticationFailedException was expected as the Authenticator object passed is incorrect");
-
- } catch (AuthenticationFailedException expected) {
- // success
-
- } finally {
- locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
- }
- }
-
- @Category(FlakyTest.class) // GEODE-1091: random port
- @Test
- public void testP2PAuthenticationWithNoCredentials() throws Exception {
- int locatorPort = getRandomAvailablePort(SOCKET);
-
- CredentialGenerator gen = new DummyCredentialGenerator();
- assertNotNull(gen.getAuthenticator());
- assertNotNull(gen.getAuthInit());
- assertNull(gen.getJavaProperties());
- assertNull(gen.getSystemProperties());
-
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
- props.setProperty(SECURITY_PEER_AUTH_INIT, gen.getAuthInit());
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
-
- startTheLocator(props, null, locatorPort);
-
- try {
- new SecurityTestUtils("tmp").createSystem(props, null);
- fail("AuthenticationFailedException was expected as no credentials are set");
-
- } catch (AuthenticationFailedException expected) {
- // success
-
- } finally {
- locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
- }
- }
-
- @Test
- public void testP2PAuthenticationWithValidCredentials() throws Exception {
- int locatorPort = getRandomAvailablePort(SOCKET);
-
- CredentialGenerator gen = new DummyCredentialGenerator();
- assertNotNull(gen.getAuthenticator());
- assertNotNull(gen.getAuthInit());
- assertNull(gen.getJavaProperties());
- assertNull(gen.getSystemProperties());
- assertNotNull(gen.getValidCredentials(1));
-
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
- props.setProperty(SECURITY_PEER_AUTH_INIT, gen.getAuthInit());
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
- props.putAll(gen.getValidCredentials(1));
-
- startTheLocator(props, gen.getJavaProperties(), locatorPort);
-
- try {
- createDS(props, gen.getJavaProperties());
- verifyMembers(2);
- disconnectFromDS();
-
- } finally {
- locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
- }
- }
-
- @Test
- public void testP2PAuthenticationWithBothValidAndInValidCredentials() throws Exception {
- addIgnoredException("Authentication failed");
-
- int locatorPort = getRandomAvailablePort(SOCKET);
-
- CredentialGenerator gen = new DummyCredentialGenerator();
- assertNotNull(gen.getAuthenticator());
- assertNotNull(gen.getAuthInit());
- assertNotNull(gen.getInvalidCredentials(1));
- assertNull(gen.getJavaProperties());
- assertNull(gen.getSystemProperties());
- assertNotNull(gen.getValidCredentials(1));
- assertNotNull(gen.getValidCredentials(3));
-
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
- props.setProperty(SECURITY_PEER_AUTH_INIT, gen.getAuthInit());
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
- props.putAll(gen.getValidCredentials(1));
-
- startTheLocator(props, null, locatorPort);
-
- try {
- // invalid credentials for the peer
- props.putAll(gen.getInvalidCredentials(1));
-
- try {
- new SecurityTestUtils("tmp").createSystem(props, null);
- fail("AuthenticationFailedException was expected as wrong credentials were passed");
-
- } catch (AuthenticationFailedException expected) {
- // success
- }
-
- props.putAll(gen.getValidCredentials(3));
-
- createDS(props, null);
- verifyMembers(2);
- disconnectFromDS();
-
- } finally {
- locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
- }
- }
-
- /**
- * The strategy is to test view change reject by having two different
- * authenticators on different VMs.
- *
- * Here locator will accept the credentials from peer2 but the first peer will
- * reject them due to different authenticator. Hence the number of members
- * reported by the first peer should be only two while others will report as
- * three.
- */
- @Ignore("disabled for some reason?")
- @Test
- public void testP2PViewChangeReject() throws Exception {
- final Host host = Host.getHost(0);
- final VM peer2 = host.getVM(1);
- final VM peer3 = host.getVM(2);
-
- CredentialGenerator gen = new LdapUserCredentialGenerator();
- gen.init();
- Properties extraProps = gen.getSystemProperties();
- String authenticator = gen.getAuthenticator();
- String authInit = gen.getAuthInit();
-
- if (extraProps == null) {
- extraProps = new Properties();
- }
-
- CredentialGenerator gen2 = new DummyCredentialGenerator();
- gen2.init();
- Properties extraProps2 = gen2.getSystemProperties();
- String authenticator2 = gen2.getAuthenticator();
-
- if (extraProps2 == null) {
- extraProps2 = new Properties();
- }
-
- // Start the locator with the LDAP authenticator
- Properties props = new Properties();
- int port = getRandomAvailablePort(SOCKET);
- final String locators = getIPLiteral() +"["+port+"]";
-
- props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, authenticator);
- Properties credentials = gen.getValidCredentials(1);
- Properties javaProps = gen.getJavaProperties();
- props.putAll(credentials);
- props.putAll(extraProps);
-
- startTheLocator(props, javaProps, port);
-
- try {
-
- // Start the first peer with different authenticator
- props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
- props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, authenticator2);
-
- credentials = gen.getValidCredentials(3);
- Properties javaProps2 = gen2.getJavaProperties();
- props.putAll(credentials);
- props.putAll(extraProps2);
-
- createDS(props, javaProps2);
-
- // Start the second peer with the same authenticator as locator
- props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
- props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, authenticator);
-
- credentials = gen.getValidCredentials(7);
- javaProps = gen.getJavaProperties();
- props.putAll(credentials);
- props.putAll(extraProps);
-
- createDS(peer2, props, javaProps);
-
- createDS(peer3, props, javaProps);
-
- // wait for view propagation
- pause(2000);
-
- // Verify the number of members on all peers and locator
- locatorVM.invoke(() -> verifyMembers(4));
- verifyMembers(2);
- peer2.invoke(() -> verifyMembers(4));
- peer3.invoke(() -> verifyMembers(4));
-
- // Disconnect the first peer and check again
- disconnectFromDS();
- pause(2000);
-
- locatorVM.invoke(() -> verifyMembers(3));
- peer2.invoke(() -> verifyMembers(3));
- peer3.invoke(() -> verifyMembers(3));
-
- // Disconnect the second peer and check again
- peer2.invoke(() -> disconnectFromDS());
- pause(2000);
-
- locatorVM.invoke(() -> verifyMembers(2));
- peer3.invoke(() -> verifyMembers(2));
-
- // Same for last peer
- peer3.invoke(() -> disconnectFromDS());
- pause(2000);
-
- locatorVM.invoke(() -> verifyMembers(1));
-
- } finally {
- locatorVM.invoke(() -> stopLocator(port, ignoredExceptions));
- }
- }
-
- /**
- * The strategy is to test credential size greater than UDP datagram size.
- *
- * Here locator will accept the credentials from peer2 and the large credential
- * from the first peer. Number of members in the DS
- * should be four
- */
- @Test
- public void testP2PLargeCredentialSucceeds() throws Exception {
- int locatorPort = getRandomAvailablePort(SOCKET);
-
- final Host host = Host.getHost(0);
- final VM peer2 = host.getVM(1);
- final VM peer3 = host.getVM(2);
-
- CredentialGenerator gen = new DummyCredentialGenerator();
- gen.init();
-
- assertNotNull(gen.getAuthenticator());
- assertNull(gen.getJavaProperties());
- assertNull(gen.getSystemProperties());
- assertNotNull(gen.getValidCredentials(1));
-
- String authInit = UserPasswordWithExtraPropsAuthInit.class.getName() + ".create";
- Properties credentials = gen.getValidCredentials(1);
-
- Properties props = new Properties();
- props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
- props.putAll(credentials);
-
- startTheLocator(props, null, locatorPort);
-
- try {
- // Start the first peer with huge credentials
- props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
- props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
-
- String hugeStr = "20KString";
- for (int i = 0; i <= 20000; i++) {
- hugeStr += "A";
- }
-
- credentials = gen.getValidCredentials(3);
- credentials.setProperty("security-keep-extra-props", "-");
- credentials.setProperty("security-hugeentryone", hugeStr);
- credentials.setProperty("security-hugeentrytwo", hugeStr);
- credentials.setProperty("security-hugeentrythree", hugeStr);
-
- props.putAll(credentials);
-
- createDS(props, null);
- // fail("AuthenticationFailedException was expected as credentials were passed beyond 50k"); --?
-
- // Start the second peer with the same authenticator as locator
- props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, getIPLiteral() + "[" + locatorPort + "]");
- props.setProperty(SECURITY_PEER_AUTH_INIT, authInit);
- props.setProperty(SECURITY_PEER_AUTHENTICATOR, gen.getAuthenticator());
-
- credentials = gen.getValidCredentials(7);
- props.putAll(credentials);
-
- createDS(peer2, props, null);
- createDS(peer3, props, null);
-
- // wait for view propagation
- pause(2000);
-
- // Verify the number of members on all peers and locator
- locatorVM.invoke(() -> verifyMembers(4));
- peer2.invoke(() -> verifyMembers(4));
- peer3.invoke(() -> verifyMembers(4));
-
- // Disconnect the peers
- disconnectFromDS();
- peer2.invoke(() -> disconnectFromDS());
- peer3.invoke(() -> disconnectFromDS());
-
- } finally {
- locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
- }
- }
-
- private void createDS(final VM peer2, final Properties props, final Properties javaProps) {
- peer2.invoke(() -> createDS(props, javaProps));
- }
-
- private void startTheLocator(final Properties props, final Properties javaProps, final int port) {
- locatorVM.invoke(() -> startLocator(getUniqueName(), port, props, javaProps, ignoredExceptions));
- }
-
- private static void createDS(final Properties props, final Properties javaProps) {
- SecurityTestUtils tmpUtil = new SecurityTestUtils("tmp");
- tmpUtil.createSystem(props, javaProps);
- }
-
- private static void verifyMembers(final int numExpectedMembers) {
- DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
- MembershipManager mgr = MembershipManagerHelper.getMembershipManager(ds);
- assertEquals(numExpectedMembers, mgr.getView().size());
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d7a6960/geode-core/src/test/java/com/gemstone/gemfire/security/PDXGfshPostProcessorOnRemoteServerTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/PDXGfshPostProcessorOnRemoteServerTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/PDXGfshPostProcessorOnRemoteServerTest.java
deleted file mode 100644
index 81b3add..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/PDXGfshPostProcessorOnRemoteServerTest.java
+++ /dev/null
@@ -1,159 +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 com.gemstone.gemfire.security;
-
-import static com.gemstone.gemfire.distributed.ConfigurationProperties.*;
-import static org.junit.Assert.*;
-
-import java.io.File;
-import java.util.Properties;
-import java.util.concurrent.TimeUnit;
-
-import com.jayway.awaitility.Awaitility;
-import org.apache.geode.security.templates.SampleSecurityManager;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.cache.Cache;
-import com.gemstone.gemfire.cache.CacheFactory;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.RegionShortcut;
-import com.gemstone.gemfire.cache.server.CacheServer;
-import com.gemstone.gemfire.distributed.Locator;
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.internal.AvailablePortHelper;
-import com.gemstone.gemfire.internal.security.SecurityService;
-import com.gemstone.gemfire.management.ManagementService;
-import com.gemstone.gemfire.management.cli.Result.Status;
-import com.gemstone.gemfire.management.internal.cli.CliUtil;
-import com.gemstone.gemfire.management.internal.cli.HeadlessGfsh;
-import com.gemstone.gemfire.management.internal.cli.i18n.CliStrings;
-import com.gemstone.gemfire.management.internal.cli.result.CommandResult;
-import com.gemstone.gemfire.management.internal.cli.util.CommandStringBuilder;
-import com.gemstone.gemfire.pdx.SimpleClass;
-import com.gemstone.gemfire.security.templates.UserPasswordAuthInit;
-import com.gemstone.gemfire.test.dunit.Host;
-import com.gemstone.gemfire.test.dunit.VM;
-import com.gemstone.gemfire.test.dunit.internal.JUnit4DistributedTestCase;
-import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-import com.gemstone.gemfire.test.junit.categories.SecurityTest;
-
-@Category({ DistributedTest.class, SecurityTest.class })
-public class PDXGfshPostProcessorOnRemoteServerTest extends JUnit4DistributedTestCase {
- protected static final String REGION_NAME = "AuthRegion";
- protected VM locator = null;
- protected VM server = null;
-
- @Before
- public void before() throws Exception {
- final Host host = Host.getHost(0);
- this.locator = host.getVM(0);
- this.server = host.getVM(1);
- }
-
- @Test
- public void testGfshCommand() throws Exception{
- // set up locator with security
- int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
- int locatorPort = ports[0];
- int jmxPort = ports[1];
- locator.invoke(()->{
- Properties props = new Properties();
- props.setProperty(SampleSecurityManager.SECURITY_JSON, "com/gemstone/gemfire/management/internal/security/clientServer.json");
- props.setProperty(SECURITY_MANAGER, SampleSecurityManager.class.getName());
- props.setProperty(MCAST_PORT, "0");
- props.put(JMX_MANAGER, "true");
- props.put(JMX_MANAGER_START, "true");
- props.put(JMX_MANAGER_PORT, jmxPort+"");
- props.setProperty(SECURITY_POST_PROCESSOR, PDXPostProcessor.class.getName());
- Locator.startLocatorAndDS(locatorPort, new File("locator.log"), props);
- });
-
- // set up server with security
- String locators = "localhost[" + locatorPort + "]";
- server.invoke(()->{
- Properties props = new Properties();
- props.setProperty(MCAST_PORT, "0");
- props.setProperty(LOCATORS, locators);
- props.setProperty(SECURITY_MANAGER, SampleSecurityManager.class.getName());
- props.setProperty(SampleSecurityManager.SECURITY_JSON, "com/gemstone/gemfire/management/internal/security/clientServer.json");
- props.setProperty(SECURITY_POST_PROCESSOR, PDXPostProcessor.class.getName());
-
- // the following are needed for peer-to-peer authentication
- props.setProperty(SECURITY_PEER_AUTH_INIT, UserPasswordAuthInit.class.getName());
- props.setProperty("security-username", "super-user");
- props.setProperty("security-password", "1234567");
- InternalDistributedSystem ds = getSystem(props);
-
- Cache cache = CacheFactory.create(ds);
- Region region = cache.createRegionFactory(RegionShortcut.REPLICATE).create(REGION_NAME);
-
- CacheServer server = cache.addCacheServer();
- server.setPort(0);
- server.start();
-
- for(int i=0; i<5; i++){
- SimpleClass obj = new SimpleClass(i, (byte)i);
- region.put("key"+i, obj);
- }
- });
-
- // wait until the region bean is visible
- locator.invoke(()->{
- Awaitility.await().pollInterval(500, TimeUnit.MICROSECONDS).atMost(5, TimeUnit.SECONDS).until(()->{
- Cache cache = CacheFactory.getAnyInstance();
- Object bean = ManagementService.getManagementService(cache).getDistributedRegionMXBean("/"+REGION_NAME);
- return bean != null;
- });
- });
-
- // run gfsh command in this vm
- CliUtil.isGfshVM = true;
- String shellId = getClass().getSimpleName();
- HeadlessGfsh gfsh = new HeadlessGfsh(shellId, 30, "gfsh_files");
-
- // connect to the jmx server
- final CommandStringBuilder connectCommand = new CommandStringBuilder(CliStrings.CONNECT);
- connectCommand.addOption(CliStrings.CONNECT__USERNAME, "dataUser");
- connectCommand.addOption(CliStrings.CONNECT__PASSWORD, "1234567");
-
- String endpoint = "localhost[" + jmxPort + "]";
- connectCommand.addOption(CliStrings.CONNECT__JMX_MANAGER, endpoint);
-
- gfsh.executeCommand(connectCommand.toString());
- CommandResult result = (CommandResult)gfsh.getResult();
-
- // get command
- gfsh.executeCommand("get --key=key1 --region=AuthRegion");
- result = (CommandResult) gfsh.getResult();
- assertEquals(result.getStatus(), Status.OK);
- assertTrue(result.getContent().toString().contains(SimpleClass.class.getName()));
-
- gfsh.executeCommand("query --query=\"select * from /AuthRegion\"");
- result = (CommandResult)gfsh.getResult();
-
- CliUtil.isGfshVM = false;
- server.invoke(()-> {
- PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
- // verify that the post processor is called 6 times. (5 for the query, 1 for the get)
- assertEquals(pp.getCount(), 6);
- });
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d7a6960/geode-core/src/test/java/com/gemstone/gemfire/security/PDXPostProcessor.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/PDXPostProcessor.java b/geode-core/src/test/java/com/gemstone/gemfire/security/PDXPostProcessor.java
deleted file mode 100644
index 0b03b66..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/PDXPostProcessor.java
+++ /dev/null
@@ -1,60 +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 com.gemstone.gemfire.security;
-
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-import java.util.Properties;
-
-import org.apache.geode.security.PostProcessor;
-
-import com.gemstone.gemfire.pdx.SimpleClass;
-import com.gemstone.gemfire.pdx.internal.PdxInstanceImpl;
-
-public class PDXPostProcessor implements PostProcessor{
- public static byte[] BYTES = {1,0};
-
- private boolean pdx = false;
- private int count = 0;
-
- public void init(Properties props){
- pdx = Boolean.parseBoolean(props.getProperty("security-pdx"));
- count = 0;
- }
- @Override
- public Object processRegionValue(final Object principal,
- final String regionName,
- final Object key,
- final Object value) {
- count ++;
- if(value instanceof byte[]){
- assertTrue(Arrays.equals(BYTES, (byte[])value));
- }
- else if(pdx){
- assertTrue(value instanceof PdxInstanceImpl);
- }
- else {
- assertTrue(value instanceof SimpleClass);
- }
- return value;
- }
-
- public int getCount(){
- return count;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d7a6960/geode-core/src/test/java/com/gemstone/gemfire/security/PDXPostProcessorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/PDXPostProcessorDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/PDXPostProcessorDUnitTest.java
deleted file mode 100644
index 1e87952..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/PDXPostProcessorDUnitTest.java
+++ /dev/null
@@ -1,233 +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 com.gemstone.gemfire.security;
-
-import static org.junit.Assert.*;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.concurrent.TimeUnit;
-
-import com.jayway.awaitility.Awaitility;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-
-import com.gemstone.gemfire.cache.EntryEvent;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.client.ClientCache;
-import com.gemstone.gemfire.cache.client.ClientCacheFactory;
-import com.gemstone.gemfire.cache.client.ClientRegionFactory;
-import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
-import com.gemstone.gemfire.cache.query.SelectResults;
-import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
-import com.gemstone.gemfire.internal.AvailablePortHelper;
-import com.gemstone.gemfire.internal.cache.EntryEventImpl;
-import com.gemstone.gemfire.internal.security.SecurityService;
-import com.gemstone.gemfire.management.cli.Result.Status;
-import com.gemstone.gemfire.management.internal.cli.CliUtil;
-import com.gemstone.gemfire.management.internal.cli.HeadlessGfsh;
-import com.gemstone.gemfire.management.internal.cli.i18n.CliStrings;
-import com.gemstone.gemfire.management.internal.cli.result.CommandResult;
-import com.gemstone.gemfire.management.internal.cli.util.CommandStringBuilder;
-import com.gemstone.gemfire.pdx.SimpleClass;
-import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-import com.gemstone.gemfire.test.junit.categories.SecurityTest;
-import com.gemstone.gemfire.test.junit.runners.CategoryWithParameterizedRunnerFactory;
-
-@Category({ DistributedTest.class, SecurityTest.class })
-@RunWith(Parameterized.class)
-@Parameterized.UseParametersRunnerFactory(CategoryWithParameterizedRunnerFactory.class)
-public class PDXPostProcessorDUnitTest extends AbstractSecureServerDUnitTest {
- private static byte[] BYTES = PDXPostProcessor.BYTES;
-
- @Parameterized.Parameters
- public static Collection<Object[]> parameters(){
- Object[][] params = {{true}, {false}};
- return Arrays.asList(params);
- }
-
- public PDXPostProcessorDUnitTest(boolean pdxPersistent){
- this.postProcessor = PDXPostProcessor.class;
- this.pdxPersistent = pdxPersistent;
- this.jmxPort = AvailablePortHelper.getRandomAvailableTCPPort();
- values = new HashMap();
- }
-
- @Test
- public void testRegionGet(){
- client2.invoke(()->{
- ClientCache cache = createClientCache("super-user", "1234567", serverPort);
- Region region = cache.getRegion(REGION_NAME);
- // put in a value that's a domain object
- region.put("key1", new SimpleClass(1, (byte) 1));
- // put in a byte value
- region.put("key2", BYTES);
- });
-
- client1.invoke(()->{
- ClientCache cache = createClientCache("super-user", "1234567", serverPort);
- Region region = cache.getRegion(REGION_NAME);
-
- // post process for get the client domain object
- Object value = region.get("key1");
- assertTrue(value instanceof SimpleClass);
-
- // post process for get the raw byte value
- value = region.get("key2");
- assertTrue(Arrays.equals(BYTES, (byte[])value));
- });
-
- // this makes sure PostProcessor is getting called
- PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
- assertEquals(pp.getCount(), 2);
- }
-
- @Test
- public void testQuery(){
- client2.invoke(()->{
- ClientCache cache = createClientCache("super-user", "1234567", serverPort);
- Region region = cache.getRegion(REGION_NAME);
- // put in a value that's a domain object
- region.put("key1", new SimpleClass(1, (byte) 1));
- region.put("key2", BYTES);
- });
-
- client1.invoke(()->{
- ClientCache cache = createClientCache("super-user", "1234567", serverPort);
- Region region = cache.getRegion(REGION_NAME);
-
- // post process for query
- String query = "select * from /AuthRegion";
- SelectResults result = region.query(query);
-
- Iterator itr = result.iterator();
- while (itr.hasNext()) {
- Object obj = itr.next();
- if(obj instanceof byte[]){
- assertTrue(Arrays.equals(BYTES, (byte[])obj));
- }
- else{
- assertTrue(obj instanceof SimpleClass);
- }
- }
- });
-
- // this makes sure PostProcessor is getting called
- PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
- assertEquals(pp.getCount(), 2);
- }
-
- @Test
- public void testRegisterInterest(){
- client1.invoke(()->{
- ClientCache cache = new ClientCacheFactory(createClientProperties("super-user", "1234567"))
- .setPoolSubscriptionEnabled(true)
- .addPoolServer("localhost", serverPort)
- .create();
-
- ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
- factory.addCacheListener(new CacheListenerAdapter() {
- @Override
- public void afterUpdate(EntryEvent event) {
- Object key = event.getKey();
- Object value = ((EntryEventImpl) event).getDeserializedValue();
- if(key.equals("key1")) {
- assertTrue(value instanceof SimpleClass);
- }
- else if(key.equals("key2")){
- assertTrue(Arrays.equals(BYTES, (byte[])value));
- }
- }
- });
-
- Region region = factory.create(REGION_NAME);
- region.put("key1", "value1");
- region.registerInterest("key1");
- region.registerInterest("key2");
- });
-
- client2.invoke(()->{
- ClientCache cache = createClientCache("dataUser", "1234567", serverPort);
- Region region = cache.getRegion(REGION_NAME);
- // put in a value that's a domain object
- region.put("key1", new SimpleClass(1, (byte) 1));
- region.put("key2", BYTES);
- });
-
- // wait for events to fire
- Awaitility.await().atMost(1, TimeUnit.SECONDS);
- PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
- assertEquals(pp.getCount(), 2);
- }
-
- @Test
- public void testGfshCommand(){
- // have client2 input some domain data into the region
- client2.invoke(()->{
- ClientCache cache = createClientCache("super-user", "1234567", serverPort);
- Region region = cache.getRegion(REGION_NAME);
- // put in a value that's a domain object
- region.put("key1", new SimpleClass(1, (byte) 1));
- // put in a byte value
- region.put("key2", BYTES);
- });
-
- client1.invoke(()->{
- CliUtil.isGfshVM = true;
- String shellId = getClass().getSimpleName();
- HeadlessGfsh gfsh = new HeadlessGfsh(shellId, 30, "gfsh_files");
-
- // connect to the jmx server
- final CommandStringBuilder connectCommand = new CommandStringBuilder(CliStrings.CONNECT);
- connectCommand.addOption(CliStrings.CONNECT__USERNAME, "dataUser");
- connectCommand.addOption(CliStrings.CONNECT__PASSWORD, "1234567");
-
- String endpoint = "localhost[" + jmxPort + "]";
- connectCommand.addOption(CliStrings.CONNECT__JMX_MANAGER, endpoint);
-
- gfsh.executeCommand(connectCommand.toString());
- CommandResult result = (CommandResult) gfsh.getResult();
-
- // get command
- gfsh.executeCommand("get --key=key1 --region=AuthRegion");
- result = (CommandResult) gfsh.getResult();
- assertEquals(result.getStatus(), Status.OK);
- if(pdxPersistent)
- assertTrue(result.getContent().toString().contains("com.gemstone.gemfire.pdx.internal.PdxInstanceImpl"));
- else
- assertTrue(result.getContent().toString().contains("SimpleClass"));
-
- gfsh.executeCommand("get --key=key2 --region=AuthRegion");
- result = (CommandResult)gfsh.getResult();
- assertEquals(result.getStatus(), Status.OK);
- assertTrue(result.getContent().toString().contains("byte[]"));
-
- gfsh.executeCommand("query --query=\"select * from /AuthRegion\"");
- result = (CommandResult)gfsh.getResult();
- System.out.println("gfsh result: " + result);
- });
-
- PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
- assertEquals(pp.getCount(), 4);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9d7a6960/geode-core/src/test/java/com/gemstone/gemfire/security/PostProcessorDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/PostProcessorDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/PostProcessorDUnitTest.java
deleted file mode 100644
index 4a546e2..0000000
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/PostProcessorDUnitTest.java
+++ /dev/null
@@ -1,126 +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 com.gemstone.gemfire.security;
-
-import static org.junit.Assert.*;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.geode.security.templates.SamplePostProcessor;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import com.gemstone.gemfire.cache.EntryEvent;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.client.ClientCache;
-import com.gemstone.gemfire.cache.client.ClientCacheFactory;
-import com.gemstone.gemfire.cache.client.ClientRegionFactory;
-import com.gemstone.gemfire.cache.client.ClientRegionShortcut;
-import com.gemstone.gemfire.cache.client.Pool;
-import com.gemstone.gemfire.cache.client.PoolManager;
-import com.gemstone.gemfire.cache.query.SelectResults;
-import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
-import com.gemstone.gemfire.test.junit.categories.DistributedTest;
-import com.gemstone.gemfire.test.junit.categories.SecurityTest;
-
-@Category({ DistributedTest.class, SecurityTest.class })
-public class PostProcessorDUnitTest extends AbstractSecureServerDUnitTest {
-
- public PostProcessorDUnitTest(){
- this.postProcessor = SamplePostProcessor.class;
- }
-
- @Test
- public void testPostProcessRegionGet(){
- List<String> keys = new ArrayList<>();
- keys.add("key1");
- keys.add("key2");
-
- client1.invoke(()->{
- ClientCache cache = createClientCache("super-user", "1234567", serverPort);
- Region region = cache.getRegion(REGION_NAME);
-
- // post process for get
- Object value = region.get("key3");
- assertEquals("super-user/AuthRegion/key3/value3", value);
-
- // post processs for getAll
- Map values = region.getAll(keys);
- assertEquals(2, values.size());
- assertEquals("super-user/AuthRegion/key1/value1", values.get("key1"));
- assertEquals("super-user/AuthRegion/key2/value2", values.get("key2"));
- });
- }
-
- @Test
- public void testPostProcessQuery(){
- client1.invoke(()->{
- ClientCache cache = createClientCache("super-user", "1234567", serverPort);
- Region region = cache.getRegion(REGION_NAME);
-
- // post process for query
- String query = "select * from /AuthRegion";
- SelectResults result = region.query(query);
- assertEquals(5, result.size());
-
- assertTrue(result.contains("super-user/null/null/value0"));
- assertTrue(result.contains("super-user/null/null/value1"));
- assertTrue(result.contains("super-user/null/null/value2"));
- assertTrue(result.contains("super-user/null/null/value3"));
- assertTrue(result.contains("super-user/null/null/value4"));
-
- Pool pool = PoolManager.find(region);
- result = (SelectResults)pool.getQueryService().newQuery(query).execute();
- assertTrue(result.contains("super-user/null/null/value0"));
- assertTrue(result.contains("super-user/null/null/value1"));
- assertTrue(result.contains("super-user/null/null/value2"));
- assertTrue(result.contains("super-user/null/null/value3"));
- assertTrue(result.contains("super-user/null/null/value4"));
- });
- }
-
- @Test
- public void testRegisterInterestPostProcess(){
- client1.invoke(()->{
- ClientCache cache = new ClientCacheFactory(createClientProperties("super-user", "1234567"))
- .setPoolSubscriptionEnabled(true)
- .addPoolServer("localhost", serverPort)
- .create();
-
- ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
- factory.addCacheListener(new CacheListenerAdapter() {
- @Override
- public void afterUpdate(EntryEvent event) {
- assertEquals("super-user/AuthRegion/key1/value2", event.getSerializedNewValue().getDeserializedValue());
- }
- });
-
- Region region = factory.create(REGION_NAME);
- region.put("key1", "value1");
- region.registerInterest("key1");
- });
-
- client2.invoke(()->{
- ClientCache cache = createClientCache("dataUser", "1234567", serverPort);
- Region region = cache.getRegion(REGION_NAME);
- region.put("key1", "value2");
- });
- }
-
-}