You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by kl...@apache.org on 2016/03/29 21:12:55 UTC
[1/4] incubator-geode git commit: Cleanup
Repository: incubator-geode
Updated Branches:
refs/heads/feature/GEODE-693 4f6a5311f -> c5bc82d48
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java b/geode-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java
index cce3002..e456689 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/SecurityTestUtil.java
@@ -18,6 +18,7 @@
*/
package com.gemstone.gemfire.security;
+import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*;
import static com.gemstone.gemfire.internal.AvailablePort.*;
import static com.gemstone.gemfire.test.dunit.Assert.*;
import static com.gemstone.gemfire.test.dunit.DistributedTestUtils.*;
@@ -25,6 +26,8 @@ import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
import static com.gemstone.gemfire.test.dunit.NetworkUtils.*;
import static com.gemstone.gemfire.test.dunit.Wait.*;
+import static com.gemstone.gemfire.cache30.ClientServerTestCase.configureConnectionPoolWithNameAndFactory;
+
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
@@ -39,7 +42,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
-
import javax.net.ServerSocketFactory;
import javax.net.SocketFactory;
import javax.net.ssl.KeyManager;
@@ -49,7 +51,6 @@ import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
-import com.gemstone.gemfire.LogWriter;
import com.gemstone.gemfire.cache.AttributesFactory;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.CacheFactory;
@@ -75,18 +76,13 @@ import com.gemstone.gemfire.cache.query.Query;
import com.gemstone.gemfire.cache.query.QueryInvocationTargetException;
import com.gemstone.gemfire.cache.query.SelectResults;
import com.gemstone.gemfire.cache.server.CacheServer;
-import com.gemstone.gemfire.cache30.ClientServerTestCase;
import com.gemstone.gemfire.distributed.DistributedSystem;
import com.gemstone.gemfire.distributed.Locator;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
-import com.gemstone.gemfire.internal.logging.InternalLogWriter;
-import com.gemstone.gemfire.internal.logging.PureLogWriter;
import com.gemstone.gemfire.internal.util.Callable;
import com.gemstone.gemfire.pdx.PdxReader;
import com.gemstone.gemfire.pdx.PdxSerializable;
import com.gemstone.gemfire.pdx.PdxWriter;
import com.gemstone.gemfire.test.dunit.DistributedTestCase;
-import com.gemstone.gemfire.test.dunit.IgnoredException;
import com.gemstone.gemfire.test.dunit.WaitCriterion;
/**
@@ -97,7 +93,7 @@ import com.gemstone.gemfire.test.dunit.WaitCriterion;
*/
public final class SecurityTestUtil {
- private final DistributedTestCase distributedTestCase = new DistributedTestCase(getClass().getSimpleName()) {};
+ private final DistributedTestCase distributedTestCase = new DistributedTestCase(getClass().getSimpleName()) {}; // TODO: delete
protected static final int NO_EXCEPTION = 0;
protected static final int AUTHREQ_EXCEPTION = 1;
@@ -122,7 +118,6 @@ public final class SecurityTestUtil {
private static Cache cache = null;
private static Properties currentJavaProps = null;
private static String locatorString = null;
- private static Integer mcastPort = null;
private static Pool pool = null;
private static boolean multiUserAuthMode = false;
@@ -131,38 +126,38 @@ public final class SecurityTestUtil {
private static Region regionRef = null;
- public SecurityTestUtil(String name) {
+ public SecurityTestUtil(String name) { // TODO: delete
}
/**
- * @deprecated Please {@link IgnoredException} instead
+ * @deprecated Please use {@link com.gemstone.gemfire.test.dunit.IgnoredException} instead
*/
- protected static void addIgnoredExceptions(String[] expectedExceptions, LogWriter logWriter) {
+ private static void addIgnoredExceptions(final String[] expectedExceptions) { // TODO: delete
if (expectedExceptions != null) {
for (int index = 0; index < expectedExceptions.length; index++) {
- logWriter.info("<ExpectedException action=add>" + expectedExceptions[index] + "</ExpectedException>");
+ getLogWriter().info("<ExpectedException action=add>" + expectedExceptions[index] + "</ExpectedException>");
}
}
}
/**
- * @deprecated Please {@link IgnoredException} instead
+ * @deprecated Please use {@link com.gemstone.gemfire.test.dunit.IgnoredException} instead
*/
- protected static void removeExpectedExceptions(String[] expectedExceptions, LogWriter logWriter) {
+ private static void removeExpectedExceptions(final String[] expectedExceptions) { // TODO: delete
if (expectedExceptions != null) {
for (int index = 0; index < expectedExceptions.length; index++) {
- logWriter.info("<ExpectedException action=remove>" + expectedExceptions[index] + "</ExpectedException>");
+ getLogWriter().info("<ExpectedException action=remove>" + expectedExceptions[index] + "</ExpectedException>");
}
}
}
- protected static void setJavaProps(Properties javaProps) {
+ protected static void setJavaProps(final Properties javaProps) {
removeJavaProperties(currentJavaProps);
addJavaProperties(javaProps);
currentJavaProps = javaProps;
}
- protected static ProxyCache getProxyCaches(int index) {
+ protected static ProxyCache getProxyCaches(final int index) {
return proxyCaches[index];
}
@@ -185,13 +180,13 @@ public final class SecurityTestUtil {
* Note that this clears the string after returning for convenience in reusing
* for other tests. Hence it should normally be invoked only once for a test.
*/
- protected static String getLocatorString() {
+ protected static String getLocatorString() { // TODO: rename
String locString = locatorString;
locatorString = null;
return locString;
}
- protected static Properties concatProperties(Properties[] propsList) {
+ protected static Properties concatProperties(final Properties[] propsList) {
Properties props = new Properties();
for (int index = 0; index < propsList.length; ++index) {
if (propsList[index] != null) {
@@ -201,26 +196,26 @@ public final class SecurityTestUtil {
return props;
}
- protected static void registerExpectedExceptions(String[] expectedExceptions) {
+ protected static void registerExpectedExceptions(final String[] expectedExceptions) { // TODO: delete
SecurityTestUtil.ignoredExceptions = expectedExceptions;
}
- protected static int createCacheServer(Properties authProps, Properties javaProps, int dsPort, String locatorString, int serverPort, int expectedResult) {
+ protected static int createCacheServer(final Properties authProps, final Properties javaProps, final int dsPort, final String locatorString, final int serverPort, final int expectedResult) {
return createCacheServer(authProps, javaProps, dsPort, locatorString, serverPort, false, expectedResult);
}
- protected static int createCacheServer(Properties authProps, Properties javaProps, int locatorPort, String locatorString, int serverPort, boolean setupDynamicRegionFactory, int expectedResult) {
+ protected static int createCacheServer(Properties authProps, final Properties javaProps, final int locatorPort, final String locatorString, final int serverPort, final boolean setupDynamicRegionFactory, final int expectedResult) {
if (authProps == null) {
authProps = new Properties();
}
- authProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
+ authProps.setProperty(MCAST_PORT_NAME, "0");
if (locatorString != null && locatorString.length() > 0) {
- authProps.setProperty(DistributionConfig.LOCATORS_NAME, locatorString);
- authProps.setProperty(DistributionConfig.START_LOCATOR_NAME, getIPLiteral() + "[" + locatorPort + ']');
+ authProps.setProperty(LOCATORS_NAME, locatorString);
+ authProps.setProperty(START_LOCATOR_NAME, getIPLiteral() + "[" + locatorPort + ']');
} else {
authProps.setProperty("locators", "localhost["+getDUnitLocatorPort()+"]");
}
- authProps.setProperty(DistributionConfig.SECURITY_LOG_LEVEL_NAME, "finest");
+ authProps.setProperty(SECURITY_LOG_LEVEL_NAME, "finest");
getLogWriter().info("Set the server properties to: " + authProps);
getLogWriter().info("Set the java properties to: " + javaProps);
@@ -282,47 +277,47 @@ public final class SecurityTestUtil {
}
// 1
- protected static void createCacheClient(String authInitModule, Properties authProps, Properties javaProps, int[] ports, int numConnections, int expectedResult) {
+ protected static void createCacheClient(final String authInitModule, final Properties authProps, final Properties javaProps, final int[] ports, final int numConnections, final int expectedResult) {
createCacheClient(authInitModule, authProps, javaProps, ports, numConnections, false, expectedResult);
}
- // 2
- protected static void createCacheClient(String authInitModule, Properties authProps, Properties javaProps, int[] ports, int numConnections, boolean multiUserMode, int expectedResult) {
+ // 2 a
+ protected static void createCacheClient(final String authInitModule, final Properties authProps, final Properties javaProps, final int[] ports, final int numConnections, final boolean multiUserMode, final int expectedResult) {
createCacheClient(authInitModule, authProps, javaProps, ports, numConnections, false, multiUserMode, expectedResult);
}
// 3
- protected static void createCacheClientWithDynamicRegion(String authInitModule, Properties authProps, Properties javaProps, int[] ports, int numConnections, boolean setupDynamicRegionFactory, int expectedResult) {
+ protected static void createCacheClientWithDynamicRegion(final String authInitModule, final Properties authProps, final Properties javaProps, final int[] ports, final int numConnections, final boolean setupDynamicRegionFactory, final int expectedResult) {
createCacheClient(authInitModule, authProps, javaProps, ports, numConnections, setupDynamicRegionFactory, false, expectedResult);
}
// 4
- protected static void createCacheClient(String authInitModule,
- Properties authProps, Properties javaProps, int[] ports,
- int numConnections, boolean setupDynamicRegionFactory,
- boolean multiUserMode, int expectedResult) {
+ protected static void createCacheClient(final String authInitModule,
+ final Properties authProps, final Properties javaProps, final int[] ports,
+ final int numConnections, final boolean setupDynamicRegionFactory,
+ final boolean multiUserMode, final int expectedResult) {
createCacheClient(authInitModule, authProps, javaProps, ports,
numConnections, setupDynamicRegionFactory, multiUserMode, Boolean.TRUE,
expectedResult);
}
// 5
- protected static void createCacheClient(String authInitModule,
- Properties authProps, Properties javaProps, int[] ports,
- int numConnections, boolean setupDynamicRegionFactory,
- boolean multiUserMode, boolean subscriptionEnabled,
- int expectedResult) {
+ protected static void createCacheClient(final String authInitModule,
+ Properties authProps, final Properties javaProps, int[] ports,
+ final int numConnections, final boolean setupDynamicRegionFactory,
+ final boolean multiUserMode, final boolean subscriptionEnabled,
+ final int expectedResult) {
multiUserAuthMode = Boolean.valueOf(multiUserMode);
if (authProps == null) {
authProps = new Properties();
}
- authProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
- authProps.setProperty(DistributionConfig.LOCATORS_NAME, "");
- authProps.setProperty(DistributionConfig.SECURITY_LOG_LEVEL_NAME, "finest");
+ authProps.setProperty(MCAST_PORT_NAME, "0");
+ authProps.setProperty(LOCATORS_NAME, "");
+ authProps.setProperty(SECURITY_LOG_LEVEL_NAME, "finest");
// TODO (ashetkar) Add " && (!multiUserAuthMode)" below.
if (authInitModule != null) {
- authProps.setProperty(DistributionConfig.SECURITY_CLIENT_AUTH_INIT_NAME,
+ authProps.setProperty(SECURITY_CLIENT_AUTH_INIT_NAME,
authInitModule);
}
@@ -344,7 +339,7 @@ public final class SecurityTestUtil {
// Actually setting it to false causes MultiuserAPIDUnitTest to fail.
//poolFactory.setSubscriptionEnabled(false);
}
- pool = ClientServerTestCase.configureConnectionPoolWithNameAndFactory(factory,
+ pool = configureConnectionPoolWithNameAndFactory(factory,
getIPLiteral(), portsI, subscriptionEnabled, 0,
numConnections, null, null,
poolFactory);
@@ -415,20 +410,20 @@ public final class SecurityTestUtil {
}
}
- protected static void createCacheClientForMultiUserMode(int numOfUsers,
- String authInitModule, Properties[] authProps, Properties javaProps,
- int[] ports, int numConnections,
- boolean setupDynamicRegionFactory, int expectedResult) {
+ protected static void createCacheClientForMultiUserMode(final int numOfUsers,
+ final String authInitModule, final Properties[] authProps, final Properties javaProps,
+ final int[] ports, final int numConnections,
+ final boolean setupDynamicRegionFactory, final int expectedResult) {
createCacheClientForMultiUserMode(numOfUsers, authInitModule, authProps,
javaProps, ports, numConnections, setupDynamicRegionFactory, null,
expectedResult);
}
- protected static void createCacheClientForMultiUserMode(int numOfUsers,
- String authInitModule, Properties[] authProps, Properties javaProps,
- int[] ports, int numConnections,
- boolean setupDynamicRegionFactory, String durableClientId,
- int expectedResult) {
+ protected static void createCacheClientForMultiUserMode(final int numOfUsers,
+ final String authInitModule, final Properties[] authProps, final Properties javaProps,
+ final int[] ports, final int numConnections,
+ final boolean setupDynamicRegionFactory, final String durableClientId,
+ final int expectedResult) {
if (numOfUsers < 1) {
fail("Number of users cannot be less than one");
@@ -441,22 +436,22 @@ public final class SecurityTestUtil {
if (authProps[0] == null) {
authProps[0] = new Properties();
}
- authProps[0].setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
- authProps[0].setProperty(DistributionConfig.LOCATORS_NAME, "");
- authProps[0].setProperty(DistributionConfig.SECURITY_LOG_LEVEL_NAME,
+ authProps[0].setProperty(MCAST_PORT_NAME, "0");
+ authProps[0].setProperty(LOCATORS_NAME, "");
+ authProps[0].setProperty(SECURITY_LOG_LEVEL_NAME,
"finest");
Properties props = new Properties();
if (authInitModule != null) {
authProps[0].setProperty(
- DistributionConfig.SECURITY_CLIENT_AUTH_INIT_NAME, authInitModule);
- props.setProperty(DistributionConfig.SECURITY_CLIENT_AUTH_INIT_NAME,
+ SECURITY_CLIENT_AUTH_INIT_NAME, authInitModule);
+ props.setProperty(SECURITY_CLIENT_AUTH_INIT_NAME,
authInitModule);
}
if (durableClientId != null) {
- props.setProperty(DistributionConfig.DURABLE_CLIENT_ID_NAME,
+ props.setProperty(DURABLE_CLIENT_ID_NAME,
durableClientId);
- props.setProperty(DistributionConfig.DURABLE_CLIENT_TIMEOUT_NAME, String
- .valueOf(DistributionConfig.DEFAULT_DURABLE_CLIENT_TIMEOUT));
+ props.setProperty(DURABLE_CLIENT_TIMEOUT_NAME, String
+ .valueOf(DEFAULT_DURABLE_CLIENT_TIMEOUT));
}
SecurityTestUtil tmpInstance = new SecurityTestUtil("temp");
@@ -473,7 +468,7 @@ public final class SecurityTestUtil {
poolFactory.setRetryAttempts(200);
poolFactory.setMultiuserAuthentication(multiUserAuthMode);
poolFactory.setSubscriptionEnabled(true);
- pool = ClientServerTestCase.configureConnectionPoolWithNameAndFactory(factory,
+ pool = configureConnectionPoolWithNameAndFactory(factory,
getIPLiteral(), portsI, true, 1,
numConnections, null, null,
poolFactory);
@@ -531,7 +526,7 @@ public final class SecurityTestUtil {
}
}
- protected static void createProxyCache(Integer[] userIndices, Properties[] props) {
+ protected static void createProxyCache(final int[] userIndices, final Properties[] props) {
int j = 0;
for (int i : userIndices) {
proxyCaches[i] = (ProxyCache)((PoolImpl) pool)
@@ -540,48 +535,23 @@ public final class SecurityTestUtil {
}
}
- protected static void stopCacheServers() {
- Iterator iter = getCache().getCacheServers().iterator();
- if (iter.hasNext()) {
- CacheServer server = (CacheServer)iter.next();
- server.stop();
- assertFalse(server.isRunning());
- }
- }
-
- protected static void restartCacheServers() {
- Iterator iter = getCache().getCacheServers().iterator();
- if (iter.hasNext()) {
- CacheServer server = (CacheServer)iter.next();
- try {
- server.start();
- }
- catch (Exception ex) {
- fail("Unexpected exception when restarting cache servers", ex);
- }
- assertTrue(server.isRunning());
- }
- }
-
- protected static void startLocator(String name, Integer port, Object extraProps,
- Object javaProps, String[] expectedExceptions) {
+ protected static void startLocator(final String name, Integer port, final Object extraProps,
+ final Object javaProps, final String[] expectedExceptions) {
File logFile = new File(name + "-locator" + port.intValue() + ".log");
try {
Properties authProps = new Properties();
if (extraProps != null) {
authProps.putAll((Properties)extraProps);
}
- authProps.setProperty(DistributionConfig.MCAST_PORT_NAME, "0");
- authProps.setProperty(DistributionConfig.LOCATORS_NAME,
+ authProps.setProperty(MCAST_PORT_NAME, "0");
+ authProps.setProperty(LOCATORS_NAME,
getIPLiteral() + "[" + port + "]");
- authProps.setProperty(DistributionConfig.ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
+ authProps.setProperty(ENABLE_CLUSTER_CONFIGURATION_NAME, "false");
clearStaticSSLContext();
setJavaProps((Properties)javaProps);
FileOutputStream logOut = new FileOutputStream(logFile);
PrintStream logStream = new PrintStream(logOut);
- LogWriter logger = new PureLogWriter(InternalLogWriter.CONFIG_LEVEL,
- logStream);
- addIgnoredExceptions(expectedExceptions, logger);
+ addIgnoredExceptions(expectedExceptions);
logStream.flush();
locator = Locator.startLocatorAndDS(port.intValue(), logFile, null,
authProps);
@@ -591,10 +561,10 @@ public final class SecurityTestUtil {
}
}
- protected static void stopLocator(Integer port, String[] expectedExceptions) {
+ protected static void stopLocator(final Integer port, final String[] expectedExceptions) {
try {
locator.stop();
- removeExpectedExceptions(expectedExceptions, getLogWriter());
+ removeExpectedExceptions(expectedExceptions);
}
catch (Exception ex) {
fail("While stopping locator on port " + port.intValue(), ex);
@@ -607,12 +577,12 @@ public final class SecurityTestUtil {
// Some useful region methods used by security tests
- protected static void waitForCondition(Callable cond) {
+ protected static void waitForCondition(final Callable cond) {
waitForCondition(cond, 100, 120);
}
- protected static void waitForCondition(final Callable cond, int sleepMillis,
- int numTries) {
+ protected static void waitForCondition(final Callable cond, final int sleepMillis,
+ final int numTries) {
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
try {
@@ -630,7 +600,7 @@ public final class SecurityTestUtil {
waitForCriterion(ev, sleepMillis * numTries, 200, true);
}
- protected static Object getLocalValue(Region region, Object key) {
+ protected static Object getLocalValue(final Region region, final Object key) {
Region.Entry entry = region.getEntry(key);
return (entry != null ? entry.getValue() : null);
}
@@ -650,16 +620,16 @@ public final class SecurityTestUtil {
region.putAll(map);
}
- protected static void doPuts(Integer num) {
+ protected static void doPuts(final Integer num) {
doPutsP(num, new Integer(NO_EXCEPTION), false);
}
- protected static void doPuts(Integer num, Integer expectedResult) {
+ protected static void doPuts(final Integer num, final Integer expectedResult) {
doPutsP(num, expectedResult, false);
}
- protected static void doMultiUserPuts(Integer num, Integer numOfUsers,
- Integer[] expectedResults) {
+ protected static void doMultiUserPuts(final Integer num, final Integer numOfUsers,
+ final Integer[] expectedResults) {
if (numOfUsers != expectedResults.length) {
fail("SecurityTestUtil.doMultiUserPuts(): numOfUsers = " + numOfUsers
+ ", but expected results " + expectedResults.length);
@@ -670,20 +640,20 @@ public final class SecurityTestUtil {
}
}
- protected static void doGets(Integer num) {
+ protected static void doGets(final Integer num) {
doGetsP(num, new Integer(NO_EXCEPTION), false);
}
- protected static void doGets(Integer num, Integer expectedResult) {
+ protected static void doGets(final Integer num, final Integer expectedResult) {
doGetsP(num, expectedResult, false);
}
- protected static void doMultiUserGetAll(Integer numOfUsers, Integer[] expectedResults) {
+ protected static void doMultiUserGetAll(final Integer numOfUsers, final Integer[] expectedResults) {
doMultiUserGetAll(numOfUsers, expectedResults, false);
}
- protected static void doMultiUserGetAll(Integer numOfUsers,
- Integer[] expectedResults, boolean useTX) {
+ protected static void doMultiUserGetAll(final Integer numOfUsers,
+ final Integer[] expectedResults, final boolean useTX) {
if (numOfUsers != expectedResults.length) {
fail("SecurityTestUtil.doMultiUserGetAll(): numOfUsers = " + numOfUsers
+ ", but expected results " + expectedResults.length);
@@ -695,8 +665,8 @@ public final class SecurityTestUtil {
}
}
- protected static void doMultiUserGets(Integer num, Integer numOfUsers,
- Integer[] expectedResults) {
+ protected static void doMultiUserGets(final Integer num, final Integer numOfUsers,
+ final Integer[] expectedResults) {
if (numOfUsers != expectedResults.length) {
fail("SecurityTestUtil.doMultiUserGets(): numOfUsers = " + numOfUsers
+ ", but expected results " + expectedResults.length);
@@ -707,8 +677,8 @@ public final class SecurityTestUtil {
}
}
- protected static void doMultiUserRegionDestroys(Integer numOfUsers,
- Integer[] expectedResults) {
+ protected static void doMultiUserRegionDestroys(final Integer numOfUsers,
+ final Integer[] expectedResults) {
if (numOfUsers != expectedResults.length) {
fail("SecurityTestUtil.doMultiUserRegionDestroys(): numOfUsers = " + numOfUsers
+ ", but expected results " + expectedResults.length);
@@ -719,8 +689,8 @@ public final class SecurityTestUtil {
}
}
- protected static void doMultiUserDestroys(Integer num, Integer numOfUsers,
- Integer[] expectedResults) {
+ protected static void doMultiUserDestroys(final Integer num, final Integer numOfUsers,
+ final Integer[] expectedResults) {
if (numOfUsers != expectedResults.length) {
fail("SecurityTestUtil.doMultiUserDestroys(): numOfUsers = " + numOfUsers
+ ", but expected results " + expectedResults.length);
@@ -731,8 +701,8 @@ public final class SecurityTestUtil {
}
}
- protected static void doMultiUserInvalidates(Integer num, Integer numOfUsers,
- Integer[] expectedResults) {
+ protected static void doMultiUserInvalidates(final Integer num, final Integer numOfUsers,
+ final Integer[] expectedResults) {
if (numOfUsers != expectedResults.length) {
fail("SecurityTestUtil.doMultiUserInvalidates(): numOfUsers = " + numOfUsers
+ ", but expected results " + expectedResults.length);
@@ -743,8 +713,8 @@ public final class SecurityTestUtil {
}
}
- protected static void doMultiUserContainsKeys(Integer num, Integer numOfUsers,
- Integer[] expectedResults, Boolean[] results) {
+ protected static void doMultiUserContainsKeys(final Integer num, final Integer numOfUsers,
+ final Integer[] expectedResults, final Boolean[] results) {
if (numOfUsers != expectedResults.length) {
fail("SecurityTestUtil.doMultiUserContainsKeys(): numOfUsers = " + numOfUsers
+ ", but #expected results " + expectedResults.length);
@@ -759,8 +729,8 @@ public final class SecurityTestUtil {
}
}
- protected static void doMultiUserQueries(Integer numOfUsers,
- Integer[] expectedResults, Integer valueSize) {
+ protected static void doMultiUserQueries(final Integer numOfUsers,
+ final Integer[] expectedResults, final Integer valueSize) {
if (numOfUsers != expectedResults.length) {
fail("SecurityTestUtil.doMultiUserQueries(): numOfUsers = " + numOfUsers
+ ", but #expected results " + expectedResults.length);
@@ -771,8 +741,8 @@ public final class SecurityTestUtil {
}
}
- protected static void doMultiUserFE(Integer numOfUsers, Function function,
- Integer[] expectedResults, Object[] results, Boolean isFailoverCase) {
+ protected static void doMultiUserFE(final Integer numOfUsers, final Function function,
+ final Integer[] expectedResults, final Object[] results, final Boolean isFailoverCase) {
if (numOfUsers != expectedResults.length) {
fail("SecurityTestUtil.doMultiUserFE(): numOfUsers = " + numOfUsers
+ ", but #expected results " + expectedResults.length);
@@ -798,8 +768,8 @@ public final class SecurityTestUtil {
}
}
- protected static void doMultiUserQueryExecute(Integer numOfUsers,
- Integer[] expectedResults, Integer result) {
+ protected static void doMultiUserQueryExecute(final Integer numOfUsers,
+ final Integer[] expectedResults, final Integer result) {
if (numOfUsers != expectedResults.length) {
fail("SecurityTestUtil.doMultiUserFE(): numOfUsers = " + numOfUsers
+ ", but #expected results " + expectedResults.length);
@@ -810,31 +780,31 @@ public final class SecurityTestUtil {
}
}
- protected static void doLocalGets(Integer num) {
+ protected static void doLocalGets(final Integer num) {
doLocalGetsP(num.intValue(), false);
}
- protected static void doNPuts(Integer num) {
+ protected static void doNPuts(final Integer num) {
doPutsP(num, new Integer(NO_EXCEPTION), true);
}
- protected static void doNPuts(Integer num, Integer expectedResult) {
+ protected static void doNPuts(final Integer num, final Integer expectedResult) {
doPutsP(num, expectedResult, true);
}
- protected static void doNGets(Integer num) {
+ protected static void doNGets(final Integer num) {
doGetsP(num, new Integer(NO_EXCEPTION), true);
}
- protected static void doNGets(Integer num, Integer expectedResult) {
+ protected static void doNGets(final Integer num, final Integer expectedResult) {
doGetsP(num, expectedResult, true);
}
- protected static void doNLocalGets(Integer num) {
+ protected static void doNLocalGets(final Integer num) {
doLocalGetsP(num.intValue(), true);
}
- protected static void doSimpleGet(String expectedResult) {
+ protected static void doSimpleGet(final String expectedResult) {
if (regionRef != null) {
try {
regionRef.get("KEY");
@@ -854,7 +824,7 @@ public final class SecurityTestUtil {
}
}
- protected static void doSimplePut(String expectedResult) {
+ protected static void doSimplePut(final String expectedResult) {
if (regionRef != null) {
try {
regionRef.put("KEY", "VALUE");
@@ -912,7 +882,7 @@ public final class SecurityTestUtil {
}
protected static void closeCache() {
- removeExpectedExceptions(ignoredExceptions, getLogWriter());
+ removeExpectedExceptions(ignoredExceptions);
if (cache != null && !cache.isClosed()) {
DistributedSystem sys = cache.getDistributedSystem();
cache.close();
@@ -922,8 +892,8 @@ public final class SecurityTestUtil {
DistributedTestCase.disconnectFromDS();
}
- protected static void closeCache(Boolean keepAlive) {
- removeExpectedExceptions(ignoredExceptions, getLogWriter());
+ protected static void closeCache(final Boolean keepAlive) {
+ removeExpectedExceptions(ignoredExceptions);
if (cache != null && !cache.isClosed()) {
DistributedSystem sys = cache.getDistributedSystem();
cache.close(keepAlive);
@@ -935,11 +905,11 @@ public final class SecurityTestUtil {
// ------------------------- private static methods -------------------------
- private static void initClientDynamicRegionFactory(String poolName) {
+ private static void initClientDynamicRegionFactory(final String poolName) {
DynamicRegionFactory.get().open(new DynamicRegionFactory.Config(null, poolName, false, true));
}
- private static void addJavaProperties(Properties javaProps) {
+ private static void addJavaProperties(final Properties javaProps) {
if (javaProps != null) {
Iterator iter = javaProps.entrySet().iterator();
while (iter.hasNext()) {
@@ -949,7 +919,7 @@ public final class SecurityTestUtil {
}
}
- private static void removeJavaProperties(Properties javaProps) {
+ private static void removeJavaProperties(final Properties javaProps) {
if (javaProps != null) {
Properties props = System.getProperties();
Iterator iter = javaProps.keySet().iterator();
@@ -960,13 +930,13 @@ public final class SecurityTestUtil {
}
}
- private static void doPutsP(Integer num, Integer expectedResult,
- boolean newVals) {
+ private static void doPutsP(final Integer num, final Integer expectedResult,
+ final boolean newVals) {
doPutsP(num, Integer.valueOf(0), expectedResult, newVals);
}
- private static void doPutsP(Integer num, Integer multiUserIndex,
- Integer expectedResult, boolean newVals) {
+ private static void doPutsP(final Integer num, final Integer multiUserIndex,
+ final Integer expectedResult, final boolean newVals) {
assertTrue(num.intValue() <= KEYS.length);
Region region = null;
try {
@@ -1050,7 +1020,7 @@ public final class SecurityTestUtil {
}
}
- private static HashMap getSSLFields(Object obj, Class[] classes) {
+ private static HashMap getSSLFields(final Object obj, final Class[] classes) {
HashMap resultFields = new HashMap();
Field[] fields = obj.getClass().getDeclaredFields();
for (int index = 0; index < fields.length; ++index) {
@@ -1075,7 +1045,7 @@ public final class SecurityTestUtil {
return resultFields;
}
- private static void makeNullSSLFields(Object obj, Map fieldMap) {
+ private static void makeNullSSLFields(final Object obj, final Map fieldMap) {
Iterator fieldIter = fieldMap.entrySet().iterator();
while (fieldIter.hasNext()) {
Map.Entry entry = (Map.Entry)fieldIter.next();
@@ -1094,7 +1064,7 @@ public final class SecurityTestUtil {
}
// Deal with javax SSL properties
- private static void makeNullStaticField(Class cls) {
+ private static void makeNullStaticField(final Class cls) {
Field[] fields = cls.getDeclaredFields();
for (int index = 0; index < fields.length; ++index) {
Field field = fields[index];
@@ -1122,8 +1092,8 @@ public final class SecurityTestUtil {
}
}
- private static void doQueryExecuteP(Integer multiUserIndex,
- Integer expectedResult, Integer expectedValue) {
+ private static void doQueryExecuteP(final Integer multiUserIndex,
+ final Integer expectedResult, final Integer expectedValue) {
Region region = null;
try {
if (multiUserAuthMode) {
@@ -1184,9 +1154,9 @@ public final class SecurityTestUtil {
}
}
- private static void doFunctionExecuteP(Integer multiUserIndex,
- Function function, Integer expectedResult, Object expectedValue,
- String method) {
+ private static void doFunctionExecuteP(final Integer multiUserIndex,
+ final Function function, Integer expectedResult, final Object expectedValue,
+ final String method) {
Region region = null;
try {
if (multiUserAuthMode) {
@@ -1269,8 +1239,8 @@ public final class SecurityTestUtil {
}
}
- private static void doQueriesP(Integer multiUserIndex,
- Integer expectedResult, Integer expectedValue) {
+ private static void doQueriesP(final Integer multiUserIndex,
+ final Integer expectedResult, final Integer expectedValue) {
Region region = null;
try {
if (multiUserAuthMode) {
@@ -1333,8 +1303,8 @@ public final class SecurityTestUtil {
}
}
- private static void doContainsKeysP(Integer num, Integer multiUserIndex,
- Integer expectedResult, boolean newVals, boolean expectedValue) {
+ private static void doContainsKeysP(final Integer num, final Integer multiUserIndex,
+ final Integer expectedResult, final boolean newVals, final boolean expectedValue) {
assertTrue(num.intValue() <= KEYS.length);
Region region = null;
@@ -1401,8 +1371,8 @@ public final class SecurityTestUtil {
}
}
- private static void doInvalidatesP(Integer num, Integer multiUserIndex,
- Integer expectedResult, boolean newVals) {
+ private static void doInvalidatesP(final Integer num, final Integer multiUserIndex,
+ final Integer expectedResult, final boolean newVals) {
assertTrue(num.intValue() <= KEYS.length);
Region region = null;
try {
@@ -1466,8 +1436,8 @@ public final class SecurityTestUtil {
}
}
- private static void doDestroysP(Integer num, Integer multiUserIndex,
- Integer expectedResult, boolean newVals) {
+ private static void doDestroysP(final Integer num, final Integer multiUserIndex,
+ final Integer expectedResult, final boolean newVals) {
assertTrue(num.intValue() <= KEYS.length);
Region region = null;
try {
@@ -1531,8 +1501,8 @@ public final class SecurityTestUtil {
}
}
- private static void doRegionDestroysP(Integer multiuserIndex,
- Integer expectedResult) {
+ private static void doRegionDestroysP(final Integer multiuserIndex,
+ final Integer expectedResult) {
Region region = null;
try {
if (multiUserAuthMode) {
@@ -1591,7 +1561,7 @@ public final class SecurityTestUtil {
}
}
- private static void doLocalGetsP(int num, boolean checkNVals) {
+ private static void doLocalGetsP(final int num, final boolean checkNVals) {
assertTrue(num <= KEYS.length);
String[] vals = VALUES;
if (checkNVals) {
@@ -1616,8 +1586,8 @@ public final class SecurityTestUtil {
}
}
- private static void doGetAllP(Integer multiUserIndex,
- Integer expectedResult, boolean useTX) {
+ private static void doGetAllP(final Integer multiUserIndex,
+ final Integer expectedResult, final boolean useTX) {
Region region = null;
try {
if (multiUserAuthMode) {
@@ -1685,13 +1655,13 @@ public final class SecurityTestUtil {
}
}
- private static void doGetsP(Integer num, Integer expectedResult,
- boolean newVals) {
+ private static void doGetsP(final Integer num, final Integer expectedResult,
+ final boolean newVals) {
doGetsP(num, Integer.valueOf(0), expectedResult, newVals);
}
- private static void doGetsP(Integer num, Integer multiUserIndex,
- Integer expectedResult, boolean newVals) {
+ private static void doGetsP(final Integer num, final Integer multiUserIndex,
+ final Integer expectedResult, final boolean newVals) {
assertTrue(num.intValue() <= KEYS.length);
Region region = null;
try {
@@ -1770,14 +1740,14 @@ public final class SecurityTestUtil {
// ----------------------------- member methods -----------------------------
- public DistributedSystem createSystem(Properties sysProps, Properties javaProps) {
+ public DistributedSystem createSystem(final Properties sysProps, final Properties javaProps) {
closeCache();
clearStaticSSLContext();
setJavaProps(javaProps);
DistributedSystem dsys = distributedTestCase.getSystem(sysProps);
assertNotNull(dsys);
- addIgnoredExceptions(ignoredExceptions, getLogWriter());
+ addIgnoredExceptions(ignoredExceptions);
return dsys;
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationTwoDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationTwoDUnitTest.java b/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationTwoDUnitTest.java
index 724fa72..e55d7a6 100644
--- a/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationTwoDUnitTest.java
+++ b/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationTwoDUnitTest.java
@@ -161,8 +161,7 @@ public class ClientAuthorizationTwoDUnitTest extends ClientAuthorizationTestBase
new OperationWithAction(OperationCode.REGION_DESTROY, 1, OpFlags.NONE, 1),
new OperationWithAction(OperationCode.GET, 2, OpFlags.CHECK_NOKEY | OpFlags.CHECK_EXCEPTION, 4),
- // Skip failover for region destroy since it shall fail
- // without restarting the server
+ // Skip failover for region destroy since it shall fail without restarting the server
OperationWithAction.OPBLOCK_NO_FAILOVER };
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientAuthzObjectModDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientAuthzObjectModDUnitTest.java b/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientAuthzObjectModDUnitTest.java
index 2a1fa7b..3f08ff1 100644
--- a/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientAuthzObjectModDUnitTest.java
+++ b/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientAuthzObjectModDUnitTest.java
@@ -16,6 +16,7 @@
*/
package com.gemstone.gemfire.security;
+import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*;
import static com.gemstone.gemfire.internal.AvailablePort.*;
import static com.gemstone.gemfire.security.SecurityTestUtil.*;
import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
@@ -28,7 +29,6 @@ import java.util.Random;
import com.gemstone.gemfire.DataSerializable;
import com.gemstone.gemfire.Instantiator;
import com.gemstone.gemfire.cache.operations.OperationContext.OperationCode;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
import com.gemstone.gemfire.internal.security.FilterPostAuthorization;
import com.gemstone.gemfire.internal.security.FilterPreAuthorization;
import com.gemstone.gemfire.internal.security.ObjectWithAuthz;
@@ -214,13 +214,13 @@ public class ClientAuthzObjectModDUnitTest extends ClientAuthorizationTestBase {
private Properties buildProperties(final String authenticator, final Properties extraProps, final String preAccessor, final String postAccessor) {
Properties authProps = new Properties();
if (authenticator != null) {
- authProps.setProperty(DistributionConfig.SECURITY_CLIENT_AUTHENTICATOR_NAME, authenticator);
+ authProps.setProperty(SECURITY_CLIENT_AUTHENTICATOR_NAME, authenticator);
}
if (preAccessor != null) {
- authProps.setProperty(DistributionConfig.SECURITY_CLIENT_ACCESSOR_NAME, preAccessor);
+ authProps.setProperty(SECURITY_CLIENT_ACCESSOR_NAME, preAccessor);
}
if (postAccessor != null) {
- authProps.setProperty(DistributionConfig.SECURITY_CLIENT_ACCESSOR_PP_NAME, postAccessor);
+ authProps.setProperty(SECURITY_CLIENT_ACCESSOR_PP_NAME, postAccessor);
}
if (extraProps != null) {
authProps.putAll(extraProps);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientCQPostAuthorizationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientCQPostAuthorizationDUnitTest.java b/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientCQPostAuthorizationDUnitTest.java
index 8d3876f..4ea494e 100644
--- a/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientCQPostAuthorizationDUnitTest.java
+++ b/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientCQPostAuthorizationDUnitTest.java
@@ -74,11 +74,7 @@ public class ClientCQPostAuthorizationDUnitTest extends ClientAuthorizationTestB
}
@Override
- public final void preTearDownClientAuthorizationTestBase() throws Exception {
- client1.invoke(() -> closeCache());
- client2.invoke(() -> closeCache());
- server1.invoke(() -> closeCache());
- server2.invoke(() -> closeCache());
+ public final void postTearDownClientAuthorizationTestBase() throws Exception {
this.cqNameToQueryStrings.clear();
}
@@ -181,7 +177,7 @@ public class ClientCQPostAuthorizationDUnitTest extends ClientAuthorizationTestB
server1.invoke(() -> closeCache());
server2.invoke(() -> closeCache());
- server1.invoke(() -> createServerCache(serverProps, javaProps, locatorPort, port1));
+ server1.invoke(() -> createTheServerCache(serverProps, javaProps, locatorPort, port1));
client1.invoke(() -> createClientCache(javaProps2, authInit, authProps, new int[] {port1, port2}, numOfUsers, postAuthzAllowed));
client2.invoke(() -> createClientCache(javaProps2, authInit, authProps, new int[] {port1, port2}, numOfUsers, postAuthzAllowed));
@@ -203,7 +199,7 @@ public class ClientCQPostAuthorizationDUnitTest extends ClientAuthorizationTestB
client1.invoke(() -> checkCQListeners(numOfUsers, postAuthzAllowed, numOfPuts + 1/* last key */, 0, !failover));
if (failover) {
- server2.invoke(() -> createServerCache(serverProps, javaProps, locatorPort, port2));
+ server2.invoke(() -> createTheServerCache(serverProps, javaProps, locatorPort, port2));
server1.invoke(() -> closeCache());
// Allow time for client1 to register its CQs on server2
@@ -215,8 +211,8 @@ public class ClientCQPostAuthorizationDUnitTest extends ClientAuthorizationTestB
}
}
- private void createServerCache(final Properties serverProps, final Properties javaProps, final int locatorPort, final int serverPort) {
- SecurityTestUtil.createCacheServer(serverProps, javaProps, locatorPort, null, serverPort, true, NO_EXCEPTION);
+ private void createTheServerCache(final Properties serverProps, final Properties javaProps, final int locatorPort, final int serverPort) {
+ SecurityTestUtil.createCacheServer(serverProps, javaProps, locatorPort, (String)null, serverPort, true, NO_EXCEPTION);
}
private void createClientCache(final Properties javaProps, final String authInit, final Properties[] authProps, final int ports[], final int numOfUsers, final boolean[] postAuthzAllowed) {
@@ -318,7 +314,7 @@ public class ClientCQPostAuthorizationDUnitTest extends ClientAuthorizationTestB
private void waitForLastKey(final int cqIndex) {
String cqName = "CQ_" + cqIndex;
- QueryService qService = SecurityTestUtil.getProxyCaches(cqIndex).getQueryService();
+ QueryService qService = getProxyCaches(cqIndex).getQueryService();
ClientCQImpl cqQuery = (ClientCQImpl)qService.getCq(cqName);
((CqQueryTestListener)cqQuery.getCqListeners()[0]).waitForCreated("LAST_KEY");
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientPostAuthorizationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientPostAuthorizationDUnitTest.java b/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientPostAuthorizationDUnitTest.java
index b234741..54ae3f4 100644
--- a/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientPostAuthorizationDUnitTest.java
+++ b/geode-cq/src/test/java/com/gemstone/gemfire/security/ClientPostAuthorizationDUnitTest.java
@@ -16,6 +16,7 @@
*/
package com.gemstone.gemfire.security;
+import static com.gemstone.gemfire.internal.AvailablePort.*;
import static com.gemstone.gemfire.security.SecurityTestUtil.*;
import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
@@ -26,7 +27,6 @@ import java.util.Properties;
import java.util.Random;
import com.gemstone.gemfire.cache.operations.OperationContext.OperationCode;
-import com.gemstone.gemfire.internal.AvailablePort;
import com.gemstone.gemfire.security.generator.AuthzCredentialGenerator;
import com.gemstone.gemfire.security.generator.CredentialGenerator;
import com.gemstone.gemfire.test.junit.Retry;
@@ -74,8 +74,8 @@ public class ClientPostAuthorizationDUnitTest extends ClientAuthorizationTestBas
Properties serverProps = buildProperties(authenticator, accessor, true, extraAuthProps, extraAuthzProps);
// Get ports for the servers
- Integer port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
- Integer port2 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+ int port1 = getRandomAvailablePort(SOCKET);
+ int port2 = getRandomAvailablePort(SOCKET);
// Close down any running servers
server1.invoke(() -> closeCache());
@@ -97,7 +97,7 @@ public class ClientPostAuthorizationDUnitTest extends ClientAuthorizationTestBas
executeOpBlock(opBlock, port1, port2, authInit, extraAuthProps, extraAuthzProps, tgen, rnd);
if (!currentOp.equals(OperationWithAction.OPBLOCK_NO_FAILOVER)) {
// Failover to the second server and run the block again
- server2.invoke(() -> createCacheServer(SecurityTestUtil.getLocatorPort(), port2, serverProps, javaProps ));
+ server2.invoke(() -> createCacheServer(getLocatorPort(), port2, serverProps, javaProps ));
server1.invoke(() -> closeCache());
executeOpBlock(opBlock, port1, port2, authInit, extraAuthProps, extraAuthzProps, tgen, rnd);
}
@@ -135,9 +135,10 @@ public class ClientPostAuthorizationDUnitTest extends ClientAuthorizationTestBas
// Start servers with all required properties
Properties serverProps = buildProperties(authenticator, accessor, true, extraAuthProps, extraAuthzProps);
+
// Get ports for the servers
- Integer port1 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
- Integer port2 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+ int port1 = getRandomAvailablePort(SOCKET);
+ int port2 = getRandomAvailablePort(SOCKET);
// Perform all the ops on the clients
List opBlock = new ArrayList();
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-cq/src/test/java/com/gemstone/gemfire/security/MultiuserAPIDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/com/gemstone/gemfire/security/MultiuserAPIDUnitTest.java b/geode-cq/src/test/java/com/gemstone/gemfire/security/MultiuserAPIDUnitTest.java
index 931cc6d..9ca06e9 100644
--- a/geode-cq/src/test/java/com/gemstone/gemfire/security/MultiuserAPIDUnitTest.java
+++ b/geode-cq/src/test/java/com/gemstone/gemfire/security/MultiuserAPIDUnitTest.java
@@ -16,6 +16,7 @@
*/
package com.gemstone.gemfire.security;
+import static com.gemstone.gemfire.distributed.internal.DistributionConfig.*;
import static com.gemstone.gemfire.security.SecurityTestUtil.*;
import static com.gemstone.gemfire.test.dunit.Assert.*;
import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
@@ -32,7 +33,6 @@ import com.gemstone.gemfire.cache.query.CqAttributesFactory;
import com.gemstone.gemfire.cache.query.CqException;
import com.gemstone.gemfire.cache.query.CqQuery;
import com.gemstone.gemfire.cache.query.Query;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.PoolManagerImpl;
import com.gemstone.gemfire.security.generator.CredentialGenerator;
@@ -58,33 +58,23 @@ public class MultiUserAPIDUnitTest extends ClientAuthorizationTestBase {
AuthenticationFailedException.class.getName(),
SSLHandshakeException.class.getName()};
- @Override
- public final void preTearDownClientAuthorizationTestBase() throws Exception {
- // close the clients first
- client1.invoke(() -> closeCache());
- client2.invoke(() -> closeCache());
- // then close the servers
- server1.invoke(() -> closeCache());
- server2.invoke(() -> closeCache());
- }
-
@Test
public void testSingleUserUnsupportedAPIs() {
// Start servers
// Start clients with multiuser-authentication set to false
- setUpVMs(new DummyCredentialGenerator(), Boolean.FALSE);
- client1.invoke(() -> verifyDisallowedOps(Boolean.FALSE));
+ setUpVMs(new DummyCredentialGenerator(), false);
+ client1.invoke(() -> verifyDisallowedOps(false));
}
@Test
public void testMultiUserUnsupportedAPIs() {
// Start servers.
// Start clients with multiuser-authentication set to true.
- setUpVMs(new DummyCredentialGenerator(), Boolean.TRUE);
- client1.invoke(() -> verifyDisallowedOps(Boolean.TRUE));
+ setUpVMs(new DummyCredentialGenerator(), true);
+ client1.invoke(() -> verifyDisallowedOps(true));
}
- private void verifyDisallowedOps(Boolean multiUserMode) throws Exception {
+ private void verifyDisallowedOps(final boolean multiUserMode) throws Exception {
String op = "unknown";
boolean success = false;
@@ -269,7 +259,7 @@ public class MultiUserAPIDUnitTest extends ClientAuthorizationTestBase {
}
}
- private void setUpVMs(CredentialGenerator gen, Boolean multiUser) {
+ private void setUpVMs(final CredentialGenerator gen, final boolean multiUser) {
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
String authenticator = gen.getAuthenticator();
@@ -299,25 +289,26 @@ public class MultiUserAPIDUnitTest extends ClientAuthorizationTestBase {
client1.invoke(() -> createCacheClient(authInit, credentials1, javaProps1, port1, port2, 0, multiUser, NO_EXCEPTION));
}
- private Integer createCacheServer(int dsPort, String locatorString, String authenticator, Properties extraProps, Properties javaProps) {
+ private int createCacheServer(final int dsPort, final String locatorString, final String authenticator, final Properties extraProps, final Properties javaProps) {
Properties authProps = new Properties();
if (extraProps != null) {
authProps.putAll(extraProps);
}
if (authenticator != null) {
- authProps.setProperty(DistributionConfig.SECURITY_CLIENT_AUTHENTICATOR_NAME, authenticator.toString());
+ authProps.setProperty(SECURITY_CLIENT_AUTHENTICATOR_NAME, authenticator);
}
+
return SecurityTestUtil.createCacheServer(authProps, javaProps, dsPort, locatorString, 0, NO_EXCEPTION);
}
// a
- protected static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int[] ports, int numConnections, boolean multiUserMode, int expectedResult) {
+ protected static void createCacheClient(final String authInit, final Properties authProps, final Properties javaProps, final int[] ports, final int numConnections, final boolean multiUserMode, final int expectedResult) {
SecurityTestUtil.createCacheClient(authInit, authProps, javaProps, ports, numConnections, multiUserMode, expectedResult); // invokes SecurityTestUtil 2
}
// b
- private void createCacheClient(String authInit, Properties authProps, Properties javaProps, int port1, int port2, int numConnections, boolean multiUserMode, int expectedResult) {
+ private void createCacheClient(final String authInit, final Properties authProps, final Properties javaProps, final int port1, final int port2, final int numConnections, final boolean multiUserMode, final int expectedResult) {
createCacheClient(authInit, authProps, javaProps, new int[] {port1, port2}, numConnections, multiUserMode, expectedResult); // invokes a
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-cq/src/test/java/com/gemstone/gemfire/security/MultiuserDurableCQAuthzDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-cq/src/test/java/com/gemstone/gemfire/security/MultiuserDurableCQAuthzDUnitTest.java b/geode-cq/src/test/java/com/gemstone/gemfire/security/MultiuserDurableCQAuthzDUnitTest.java
index c425969..9a5bab3 100644
--- a/geode-cq/src/test/java/com/gemstone/gemfire/security/MultiuserDurableCQAuthzDUnitTest.java
+++ b/geode-cq/src/test/java/com/gemstone/gemfire/security/MultiuserDurableCQAuthzDUnitTest.java
@@ -16,6 +16,7 @@
*/
package com.gemstone.gemfire.security;
+import static com.gemstone.gemfire.internal.AvailablePort.*;
import static com.gemstone.gemfire.security.SecurityTestUtil.*;
import static com.gemstone.gemfire.test.dunit.Assert.*;
import static com.gemstone.gemfire.test.dunit.Invoke.*;
@@ -39,10 +40,7 @@ import com.gemstone.gemfire.cache.query.RegionNotFoundException;
import com.gemstone.gemfire.cache.query.SelectResults;
import com.gemstone.gemfire.cache.query.cq.dunit.CqQueryTestListener;
import com.gemstone.gemfire.cache.query.internal.cq.ClientCQImpl;
-import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
-import com.gemstone.gemfire.internal.AvailablePort;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
-import com.gemstone.gemfire.internal.logging.InternalLogWriter;
import com.gemstone.gemfire.security.generator.AuthzCredentialGenerator;
import com.gemstone.gemfire.security.generator.CredentialGenerator;
import com.gemstone.gemfire.test.dunit.SerializableRunnable;
@@ -53,7 +51,7 @@ import org.junit.experimental.categories.Category;
@Category(DistributedTest.class)
public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBase {
- private final Map<String, String> cqNameToQueryStrings = new HashMap<String, String>();
+ private final Map<String, String> cqNameToQueryStrings = new HashMap<>();
@Override
public final void preSetUpClientAuthorizationTestBase() throws Exception {
@@ -111,7 +109,7 @@ public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBas
int numOfPuts = 5;
boolean[] postAuthzAllowed = new boolean[] {true, true};
- doTest(numOfUsers, numOfPuts, postAuthzAllowed, getXmlAuthzGenerator(), Boolean.TRUE);
+ doTest(numOfUsers, numOfPuts, postAuthzAllowed, getXmlAuthzGenerator(), true);
}
@Test
@@ -130,9 +128,12 @@ public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBas
int numOfPuts = 5;
boolean[] postAuthzAllowed = new boolean[] {true, true};
- doTest(numOfUsers, numOfPuts, postAuthzAllowed, getXmlAuthzGenerator(), Boolean.FALSE);
+ doTest(numOfUsers, numOfPuts, postAuthzAllowed, getXmlAuthzGenerator(), false);
}
+ /**
+ * WARNING: "final Boolean keepAlive" is treated as a ternary value: null, true, false
+ */
private void doTest(int numOfUsers, int numOfPuts, boolean[] postAuthzAllowed, final AuthzCredentialGenerator authzGenerator, final Boolean keepAlive) throws Exception {
CredentialGenerator credentialGenerator = authzGenerator.getCredentialGenerator();
Properties extraAuthProps = credentialGenerator.getSystemProperties();
@@ -177,7 +178,7 @@ public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBas
rand);
}
- authProps[i] = SecurityTestUtil.concatProperties(new Properties[] {opCredentials, extraAuthProps, extraAuthzProps});
+ authProps[i] = concatProperties(new Properties[] {opCredentials, extraAuthProps, extraAuthzProps});
if (client2Credentials == null) {
client2Credentials = tgen.getAllowedCredentials(
@@ -189,31 +190,31 @@ public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBas
}
// Get ports for the servers
- Integer port1 = new Integer(AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET));
- Integer port2 = new Integer(AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET));
- Integer locatorPort = new Integer(AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET));
+ int port1 = getRandomAvailablePort(SOCKET);
+ int port2 = getRandomAvailablePort(SOCKET);
+ int locatorPort = getRandomAvailablePort(SOCKET);
// Close down any running servers
- server1.invoke(() -> SecurityTestUtil.closeCache());
- server2.invoke(() -> SecurityTestUtil.closeCache());
+ server1.invoke(() -> closeCache());
+ server2.invoke(() -> closeCache());
server1.invoke(() -> createServerCache(serverProps, javaProps, locatorPort, port1));
client1.invoke(() -> createClientCache(javaProps2, authInit, authProps, new int[] {port1, port2}, numOfUsers, durableClientId, postAuthzAllowed));
- client1.invoke(() -> createCQ(numOfUsers, Boolean.TRUE));
+ client1.invoke(() -> createCQ(numOfUsers, true));
client1.invoke(() -> executeCQ(numOfUsers, new boolean[] {false, false}, numOfPuts, new String[numOfUsers]));
client1.invoke(() -> readyForEvents());
if (keepAlive == null) {
- client1.invoke(() -> SecurityTestUtil.closeCache());
+ client1.invoke(() -> closeCache());
} else {
- client1.invoke(() -> SecurityTestUtil.closeCache(keepAlive));
+ client1.invoke(() -> closeCache(keepAlive));
}
- server1.invoke(() -> doPuts(numOfPuts, Boolean.TRUE/* put last key */));
+ server1.invoke(() -> doPuts(numOfPuts, true/* put last key */));
client1.invoke(() -> createClientCache(javaProps2, authInit, authProps, new int[] {port1, port2}, numOfUsers, durableClientId, postAuthzAllowed));
- client1.invoke(() -> createCQ(numOfUsers, Boolean.TRUE));
+ client1.invoke(() -> createCQ(numOfUsers, true));
client1.invoke(() ->executeCQ(numOfUsers, new boolean[] {false, false}, numOfPuts, new String[numOfUsers]));
client1.invoke(() -> readyForEvents());
@@ -221,54 +222,49 @@ public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBas
// Don't wait as no user is authorized to receive cq events.
Thread.sleep(1000); // TODO: use Awaitility
} else {
- client1.invoke(() -> waitForLastKey(Integer.valueOf(0), Boolean.TRUE));
+ client1.invoke(() -> waitForLastKey(0, true));
}
- Integer numOfCreates = keepAlive == null ? 0 : (keepAlive ? numOfPuts + 1/* last key */ : 0);
+ int numOfCreates = keepAlive == null ? 0 : (keepAlive ? numOfPuts + 1/* last key */ : 0);
client1.invoke(() -> checkCQListeners(numOfUsers, postAuthzAllowed, numOfCreates, 0));
client1.invoke(() -> proxyCacheClose(new int[] {0, 1}, keepAlive));
- client1.invoke(() -> SecurityTestUtil.createProxyCache(new Integer[] {0, 1}, authProps));
- client1.invoke(() -> createCQ(numOfUsers, Boolean.TRUE));
+ client1.invoke(() -> createProxyCache(new int[] {0, 1}, authProps));
+ client1.invoke(() -> createCQ(numOfUsers, true));
client1.invoke(() -> executeCQ(numOfUsers, new boolean[] {false, false}, numOfPuts, new String[numOfUsers]));
- server1.invoke(() -> doPuts(numOfPuts, Boolean.TRUE/* put last key */));
+ server1.invoke(() -> doPuts(numOfPuts, true/* put last key */));
if (!postAuthzAllowed[0] || keepAlive == null || !keepAlive) {
// Don't wait as no user is authorized to receive cq events.
Thread.sleep(1000); // TODO: use Awaitility
} else {
- client1.invoke(() -> waitForLastKey(Integer.valueOf(0), Boolean.FALSE));
+ client1.invoke(() -> waitForLastKey(0, false));
}
- Integer numOfUpdates = numOfPuts + 1;
+ int numOfUpdates = numOfPuts + 1;
client1.invoke(() -> checkCQListeners(numOfUsers, postAuthzAllowed, 0, numOfUpdates));
}
- private void createServerCache(Properties serverProps, Properties javaProps, Integer locatorPort, Integer serverPort) {
- SecurityTestUtil.createCacheServer((Properties)serverProps, javaProps, locatorPort, null, serverPort, true, NO_EXCEPTION);
- }
-
- private void createClientCache(Properties javaProps, String authInit, Properties[] authProps, int ports[], int numOfUsers, boolean[] postAuthzAllowed) {
- SecurityTestUtil.createCacheClientForMultiUserMode(numOfUsers, authInit, authProps, javaProps, ports, 0, false, NO_EXCEPTION);
+ private void createServerCache(final Properties serverProps, final Properties javaProps, final int locatorPort, final int serverPort) {
+ SecurityTestUtil.createCacheServer(serverProps, javaProps, locatorPort, null, serverPort, true, NO_EXCEPTION);
}
private void readyForEvents() {
GemFireCacheImpl.getInstance().readyForEvents();
}
- private void createClientCache(Properties javaProps, String authInit, Properties[] authProps, int ports[], int numOfUsers, String durableId, boolean[] postAuthzAllowed) {
- SecurityTestUtil.createCacheClientForMultiUserMode(numOfUsers, authInit, authProps, javaProps, ports, 0, false, durableId, NO_EXCEPTION);
+ /**
+ * NOTE: "final boolean[] postAuthzAllowed" is never used
+ */
+ private void createClientCache(final Properties javaProps, final String authInit, final Properties[] authProps, final int ports[], final int numOfUsers, final String durableId, final boolean[] postAuthzAllowed) {
+ createCacheClientForMultiUserMode(numOfUsers, authInit, authProps, javaProps, ports, 0, false, durableId, NO_EXCEPTION);
}
- private void createCQ(Integer num) throws CqException, CqExistsException {
- createCQ(num, false);
- }
-
- private void createCQ(int num, boolean isDurable) throws CqException, CqExistsException {
+ private void createCQ(final int num, final boolean isDurable) throws CqException, CqExistsException {
for (int i = 0; i < num; i++) {
- QueryService cqService = SecurityTestUtil.getProxyCaches(i).getQueryService();
+ QueryService cqService = getProxyCaches(i).getQueryService();
String cqName = "CQ_" + i;
- String queryStr = cqNameToQueryStrings.get(cqName) + SecurityTestUtil.getProxyCaches(i).getRegion(regionName).getFullPath();
+ String queryStr = cqNameToQueryStrings.get(cqName) + getProxyCaches(i).getRegion(regionName).getFullPath();
// Create CQ Attributes.
CqAttributesFactory cqf = new CqAttributesFactory();
@@ -284,19 +280,17 @@ public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBas
}
}
- private void executeCQ(int num, boolean[] initialResults, int expectedResultsSize, String[] expectedErr) throws CqException, RegionNotFoundException {
- InternalLogWriter logWriter = InternalDistributedSystem.getStaticInternalLogWriter();
-
+ private void executeCQ(final int num, final boolean[] initialResults, final int expectedResultsSize, final String[] expectedErr) throws CqException, RegionNotFoundException {
for (int i = 0; i < num; i++) {
try {
if (expectedErr[i] != null) {
- logWriter.info("<ExpectedException action=add>" + expectedErr[i]+ "</ExpectedException>");
+ getLogWriter().info("<ExpectedException action=add>" + expectedErr[i]+ "</ExpectedException>");
}
CqQuery cq1 = null;
String cqName = "CQ_" + i;
- String queryStr = cqNameToQueryStrings.get(cqName) + SecurityTestUtil.getProxyCaches(i).getRegion(regionName).getFullPath();
- QueryService cqService = SecurityTestUtil.getProxyCaches(i).getQueryService();
+ String queryStr = cqNameToQueryStrings.get(cqName) + getProxyCaches(i).getRegion(regionName).getFullPath();
+ QueryService cqService = getProxyCaches(i).getQueryService();
// Get CqQuery object.
cq1 = cqService.getCq(cqName);
@@ -328,13 +322,13 @@ public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBas
} finally {
if (expectedErr[i] != null) {
- logWriter.info("<ExpectedException action=remove>" + expectedErr[i]+ "</ExpectedException>");
+ getLogWriter().info("<ExpectedException action=remove>" + expectedErr[i]+ "</ExpectedException>");
}
}
}
}
- private void doPuts(Integer num, Boolean putLastKey) {
+ private void doPuts(final int num, final boolean putLastKey) {
Region region = GemFireCacheImpl.getInstance().getRegion(regionName);
for (int i = 0; i < num; i++) {
region.put("CQ_key"+i, "CQ_value"+i);
@@ -344,14 +338,9 @@ public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBas
}
}
- private void putLastKey() {
- Region region = GemFireCacheImpl.getInstance().getRegion(regionName);
- region.put("LAST_KEY", "LAST_KEY");
- }
-
- private void waitForLastKey(int cqIndex, boolean isCreate) {
+ private void waitForLastKey(final int cqIndex, final boolean isCreate) {
String cqName = "CQ_" + cqIndex;
- QueryService qService = SecurityTestUtil.getProxyCaches(cqIndex).getQueryService();
+ QueryService qService = getProxyCaches(cqIndex).getQueryService();
ClientCQImpl cqQuery = (ClientCQImpl)qService.getCq(cqName);
if (isCreate) {
((CqQueryTestListener)cqQuery.getCqListeners()[cqIndex]).waitForCreated("LAST_KEY");
@@ -360,10 +349,10 @@ public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBas
}
}
- private void checkCQListeners(int numOfUsers, boolean[] expectedListenerInvocation, int createEventsSize, int updateEventsSize) {
+ private void checkCQListeners(final int numOfUsers, final boolean[] expectedListenerInvocation, final int createEventsSize, final int updateEventsSize) {
for (int i = 0; i < numOfUsers; i++) {
String cqName = "CQ_" + i;
- QueryService qService = SecurityTestUtil.getProxyCaches(i).getQueryService();
+ QueryService qService = getProxyCaches(i).getQueryService();
ClientCQImpl cqQuery = (ClientCQImpl)qService.getCq(cqName);
if (expectedListenerInvocation[i]) {
@@ -380,19 +369,18 @@ public class MultiUserDurableCQAuthzDUnitTest extends ClientAuthorizationTestBas
}
}
- private void proxyCacheClose(int[] userIndices) {
- proxyCacheClose(userIndices, null);
- }
-
- private void proxyCacheClose(int[] userIndices, Boolean keepAliveFlags) {
+ /**
+ * WARNING: "final Boolean keepAliveFlags" is treated as a ternary: null, true, false
+ */
+ private void proxyCacheClose(final int[] userIndices, final Boolean keepAliveFlags) {
if (keepAliveFlags != null) {
for (int i : userIndices) {
- SecurityTestUtil.getProxyCaches(i).close(keepAliveFlags);
+ getProxyCaches(i).close(keepAliveFlags);
}
} else {
for (int i : userIndices) {
- SecurityTestUtil.getProxyCaches(i).close();
+ getProxyCaches(i).close();
}
}
}
[2/4] incubator-geode git commit: Cleanup
Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java
index 50c1811..835c241 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientMultiUserAuthzDUnitTest.java
@@ -18,6 +18,11 @@
*/
package com.gemstone.gemfire.security;
+//import static com.gemstone.gemfire.security.ClientAuthenticationUtils.*;
+//import static com.gemstone.gemfire.security.ClientAuthorizationTestBase.*;
+import static com.gemstone.gemfire.security.SecurityTestUtil.*;
+import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
+
import java.util.Iterator;
import java.util.Properties;
@@ -29,7 +34,6 @@ import com.gemstone.gemfire.internal.cache.execute.PRClientServerTestBase;
import com.gemstone.gemfire.internal.cache.functions.TestFunction;
import com.gemstone.gemfire.security.generator.AuthzCredentialGenerator;
import com.gemstone.gemfire.security.generator.CredentialGenerator;
-import com.gemstone.gemfire.test.dunit.LogWriterUtils;
import com.gemstone.gemfire.test.dunit.VM;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;
import org.junit.Test;
@@ -40,13 +44,7 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase {
@Override
public final void preTearDownClientAuthorizationTestBase() throws Exception {
- // close the clients first
- client1.invoke(() -> SecurityTestUtil.closeCache());
- client2.invoke(() -> SecurityTestUtil.closeCache());
- SecurityTestUtil.closeCache();
- // then close the servers
- server1.invoke(() -> SecurityTestUtil.closeCache());
- server2.invoke(() -> SecurityTestUtil.closeCache());
+ closeCache();
}
/**
@@ -55,8 +53,7 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase {
*/
@Test
public void testOps1() throws Exception {
- Iterator iter = getDummyGeneratorCombos().iterator();
- while (iter.hasNext()) {
+ for (Iterator iter = getDummyGeneratorCombos().iterator(); iter.hasNext();) {
AuthzCredentialGenerator gen = (AuthzCredentialGenerator)iter.next();
CredentialGenerator cGen = gen.getCredentialGenerator();
Properties extraAuthProps = cGen.getSystemProperties();
@@ -66,127 +63,204 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase {
String authInit = cGen.getAuthInit();
String accessor = gen.getAuthorizationCallback();
- LogWriterUtils.getLogWriter().info("testOps1: Using authinit: " + authInit);
- LogWriterUtils.getLogWriter().info(
- "testOps1: Using authenticator: " + authenticator);
- LogWriterUtils.getLogWriter().info("testOps1: Using accessor: " + accessor);
+ getLogWriter().info("testOps1: Using authinit: " + authInit);
+ getLogWriter().info("testOps1: Using authenticator: " + authenticator);
+ getLogWriter().info("testOps1: Using accessor: " + accessor);
// Start servers with all required properties
- Properties serverProps = buildProperties(authenticator, accessor, false,
- extraAuthProps, extraAuthzProps);
+ Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
- Integer port1 = createCacheServerOnVM(server1, javaProps, serverProps);
- Integer port2 = createCacheServerOnVM(server2, javaProps, serverProps);
+ int port1 = createCacheServerOnVM(server1, javaProps, serverProps);
+ int port2 = createCacheServerOnVM(server2, javaProps, serverProps);
- if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
- OperationCode.PUT, OperationCode.PUT}, new OperationCode[] {
- OperationCode.GET, OperationCode.GET}, javaProps, authInit, port1,
- port2)) {
+ if (!prepareClientsForOps(gen, cGen, new OperationCode[] { OperationCode.PUT, OperationCode.PUT}, new OperationCode[] { OperationCode.GET, OperationCode.GET}, javaProps, authInit, port1, port2)) {
continue;
}
+
verifyPutsGets();
- if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
- OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] {
- OperationCode.DESTROY, OperationCode.DESTROY},
- javaProps, authInit, port1, port2)) {
+ if (!prepareClientsForOps(gen, cGen, new OperationCode[] { OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] { OperationCode.DESTROY, OperationCode.DESTROY}, javaProps, authInit, port1, port2)) {
continue;
}
+
verifyContainsKeyDestroys();
- if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
- OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] {
- OperationCode.INVALIDATE, OperationCode.INVALIDATE},
- javaProps, authInit, port1, port2)) {
+ if (!prepareClientsForOps(gen, cGen, new OperationCode[] { OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] { OperationCode.INVALIDATE, OperationCode.INVALIDATE}, javaProps, authInit, port1, port2)) {
continue;
}
+
verifyContainsKeyInvalidates();
- if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
- OperationCode.GET, OperationCode.GET}, new OperationCode[] {
- OperationCode.REGION_DESTROY, OperationCode.REGION_DESTROY},
- javaProps, authInit, port1, port2)) {
+ if (!prepareClientsForOps(gen, cGen, new OperationCode[] { OperationCode.GET, OperationCode.GET}, new OperationCode[] { OperationCode.REGION_DESTROY, OperationCode.REGION_DESTROY}, javaProps, authInit, port1, port2)) {
continue;
}
+
verifyGetAllInTX();
verifyGetAllRegionDestroys();
}
}
- private boolean prepareClientsForOps(AuthzCredentialGenerator gen,
- CredentialGenerator cGen, OperationCode[] client1OpCodes,
- OperationCode[] client2OpCodes, Properties javaProps, String authInit,
- Integer port1, Integer port2) {
- return prepareClientsForOps(gen, cGen, client1OpCodes, client2OpCodes,
- javaProps, authInit, port1, port2, Boolean.TRUE /*
- * both clients in
- * multiuser mode
- */, Boolean.FALSE /* unused */);
+ /**
+ * Test query/function execute
+ */
+ @Test
+ public void testOps2() throws Exception {
+ AuthzCredentialGenerator gen = getXmlAuthzGenerator();
+ CredentialGenerator cGen = gen.getCredentialGenerator();
+ Properties extraAuthProps = cGen.getSystemProperties();
+ Properties javaProps = cGen.getJavaProperties();
+ Properties extraAuthzProps = gen.getSystemProperties();
+ String authenticator = cGen.getAuthenticator();
+ String authInit = cGen.getAuthInit();
+ String accessor = gen.getAuthorizationCallback();
+
+ getLogWriter().info("testOps2: Using authinit: " + authInit);
+ getLogWriter().info("testOps2: Using authenticator: " + authenticator);
+ getLogWriter().info("testOps2: Using accessor: " + accessor);
+
+ // Start servers with all required properties
+ Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
+
+ int port1 = createCacheServerOnVM(server1, javaProps, serverProps);
+ int port2 = createCacheServerOnVM(server2, javaProps, serverProps);
+
+ // Start client1 with valid/invalid QUERY credentials
+ Properties[] client1Credentials = new Properties[] {
+ gen.getAllowedCredentials(new OperationCode[] {OperationCode.PUT, OperationCode.QUERY}, new String[] {regionName}, 1),
+ gen.getDisallowedCredentials(new OperationCode[] {OperationCode.PUT, OperationCode.QUERY}, new String[] {regionName}, 1)
+ };
+
+ javaProps = cGen.getJavaProperties();
+ getLogWriter().info("testOps2: For first client credentials: " + client1Credentials[0] + "\n" + client1Credentials[1]);
+
+ final Properties finalJavaProps = javaProps;
+ client1.invoke(() -> createCacheClientForMultiUserMode(2, authInit, client1Credentials, finalJavaProps, new int[] {port1, port2}, -1, false, NO_EXCEPTION));
+
+ // Start client2 with valid/invalid EXECUTE_FUNCTION credentials
+ Properties[] client2Credentials = new Properties[] {
+ gen.getAllowedCredentials(new OperationCode[] {OperationCode.EXECUTE_FUNCTION}, new String[] {regionName}, 2),
+ gen.getDisallowedCredentials(new OperationCode[] {OperationCode.EXECUTE_FUNCTION}, new String[] {regionName}, 9)
+ };
+
+ javaProps = cGen.getJavaProperties();
+ getLogWriter().info("testOps2: For second client credentials: " + client2Credentials[0] + "\n" + client2Credentials[1]);
+
+ final Properties finalJavaProps2 = javaProps;
+ client2.invoke(() -> createCacheClientForMultiUserMode(2, authInit, client2Credentials, finalJavaProps2, new int[] {port1, port2}, -1, false, NO_EXCEPTION));
+
+ Function function = new TestFunction(true,TestFunction.TEST_FUNCTION1);
+
+ server1.invoke(() -> PRClientServerTestBase.registerFunction(function));
+
+ server2.invoke(() -> PRClientServerTestBase.registerFunction(function));
+
+ // Perform some put operations before verifying queries
+ client1.invoke(() -> doMultiUserPuts(4, 2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}));
+ client1.invoke(() -> doMultiUserQueries(2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}, 4));
+ client1.invoke(() -> doMultiUserQueryExecute(2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}, 4));
+
+ // Verify that the FE succeeds/fails
+ client2.invoke(() ->doMultiUserFE(2, function, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}, new Object[] {null, null}, false));
+
+ // Failover
+ server1.invoke(() -> closeCache());
+ Thread.sleep(2000);
+
+ client1.invoke(() -> doMultiUserPuts(4, 2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}));
+
+ client1.invoke(() -> doMultiUserQueries(2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}, 4));
+ client1.invoke(() -> doMultiUserQueryExecute(2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}, 4));
+
+ // Verify that the FE succeeds/fails
+ client2.invoke(() -> doMultiUserFE(2, function, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}, new Object[] {null, null}, true));
+ }
+
+ @Test
+ public void testOpsWithClientsInDifferentModes() throws Exception {
+ for (Iterator iter = getDummyGeneratorCombos().iterator(); iter.hasNext();) {
+ AuthzCredentialGenerator gen = (AuthzCredentialGenerator)iter.next();
+ CredentialGenerator cGen = gen.getCredentialGenerator();
+ Properties extraAuthProps = cGen.getSystemProperties();
+ Properties javaProps = cGen.getJavaProperties();
+ Properties extraAuthzProps = gen.getSystemProperties();
+ String authenticator = cGen.getAuthenticator();
+ String authInit = cGen.getAuthInit();
+ String accessor = gen.getAuthorizationCallback();
+
+ getLogWriter().info("testOpsWithClientsInDifferentModes: Using authinit: " + authInit);
+ getLogWriter().info("testOpsWithClientsInDifferentModes: Using authenticator: " + authenticator);
+ getLogWriter().info("testOpsWithClientsInDifferentModes: Using accessor: " + accessor);
+
+ // Start servers with all required properties
+ Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
+
+ int port1 = createCacheServerOnVM(server1, javaProps, serverProps);
+ int port2 = createCacheServerOnVM(server2, javaProps, serverProps);
+
+ if (!prepareClientsForOps(gen, cGen, new OperationCode[] { OperationCode.PUT, OperationCode.PUT}, new OperationCode[] { OperationCode.GET, OperationCode.GET}, javaProps, authInit, port1, port2, false, true)) {
+ continue;
+ }
+
+ verifyPutsGets(false, true);
+
+ if (!prepareClientsForOps(gen, cGen, new OperationCode[] { OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] { OperationCode.DESTROY, OperationCode.DESTROY}, javaProps, authInit, port1, port2, false, false)) {
+ continue;
+ }
+
+ verifyContainsKeyDestroys(false, false);
+ }
}
- private boolean prepareClientsForOps(AuthzCredentialGenerator gen,
- CredentialGenerator cGen, OperationCode[] client1OpCodes,
- OperationCode[] client2OpCodes, Properties javaProps, String authInit,
- Integer port1, Integer port2, Boolean bothClientsInMultiuserMode,
- Boolean allowOp) {
+ private boolean prepareClientsForOps(final AuthzCredentialGenerator gen, final CredentialGenerator cGen, final OperationCode[] client1OpCodes, final OperationCode[] client2OpCodes, final Properties javaProps, final String authInit, final int port1, final int port2) {
+ return prepareClientsForOps(gen, cGen, client1OpCodes, client2OpCodes, javaProps, authInit, port1, port2, true /* both clients in multiuser mode */, false /* unused */);
+ }
+
+ private boolean prepareClientsForOps(final AuthzCredentialGenerator gen, final CredentialGenerator cGen, final OperationCode[] client1OpCodes, final OperationCode[] client2OpCodes, Properties javaProps, final String authInit, final int port1, final int port2, final boolean bothClientsInMultiuserMode, final boolean allowOp) {
// Start client1 with valid/invalid client1OpCodes credentials
- Properties[] client1Credentials = new Properties[] {
- gen.getAllowedCredentials(client1OpCodes, new String[] {regionName}, 1),
- gen.getDisallowedCredentials(new OperationCode[] {client1OpCodes[1]},
- new String[] {regionName}, 1)};
+ Properties[] client1Credentials = new Properties[] { gen.getAllowedCredentials(client1OpCodes, new String[] {regionName}, 1), gen.getDisallowedCredentials(new OperationCode[] {client1OpCodes[1]}, new String[] {regionName}, 1)};
+
if (client1Credentials[0] == null || client1Credentials[0].size() == 0) {
- LogWriterUtils.getLogWriter().info(
- "testOps1: Unable to obtain valid credentials with "
- + client1OpCodes[0].toString()
- + " permission; skipping this combination.");
+ getLogWriter().info("testOps1: Unable to obtain valid credentials with " + client1OpCodes[0].toString() + " permission; skipping this combination.");
return false;
}
+
if (client1Credentials[1] == null || client1Credentials[1].size() == 0) {
- LogWriterUtils.getLogWriter().info(
- "testOps1: Unable to obtain valid credentials with no "
- + client1OpCodes[0].toString()
- + " permission; skipping this combination.");
+ getLogWriter().info("testOps1: Unable to obtain valid credentials with no " + client1OpCodes[0].toString() + " permission; skipping this combination.");
return false;
}
+
javaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testOps1: For first client credentials: " + client1Credentials[0]
- + "\n" + client1Credentials[1]);
+ getLogWriter().info("testOps1: For first client credentials: " + client1Credentials[0] + "\n" + client1Credentials[1]);
final Properties finalJavaProps = javaProps;
- client1.invoke(() -> SecurityTestUtil.createCacheClientForMultiUserMode(2, authInit, client1Credentials, finalJavaProps, new int[] {port1, port2}, -1, false, SecurityTestUtil.NO_EXCEPTION));
+
+ client1.invoke(() -> createCacheClientForMultiUserMode(2, authInit, client1Credentials, finalJavaProps, new int[] {port1, port2}, -1, false, NO_EXCEPTION));
// Start client2 with valid/invalid client2OpCodes credentials
- Properties[] client2Credentials = new Properties[] {
- gen.getAllowedCredentials(client2OpCodes,
- new String[] {regionName}, 2),
- gen.getDisallowedCredentials(client2OpCodes,
- new String[] {regionName}, 9)};
+ Properties[] client2Credentials = new Properties[] { gen.getAllowedCredentials(client2OpCodes, new String[] {regionName}, 2), gen.getDisallowedCredentials(client2OpCodes, new String[] {regionName}, 9)};
+
if (client2Credentials[0] == null || client2Credentials[0].size() == 0) {
- LogWriterUtils.getLogWriter().info(
- "testOps1: Unable to obtain valid credentials with "
- + client2OpCodes[0].toString()
- + " permission; skipping this combination.");
+ getLogWriter().info("testOps1: Unable to obtain valid credentials with " + client2OpCodes[0].toString() + " permission; skipping this combination.");
return false;
}
+
if (client2Credentials[1] == null || client2Credentials[1].size() == 0) {
- LogWriterUtils.getLogWriter().info(
- "testOps1: Unable to obtain valid credentials with no "
- + client2OpCodes[0].toString()
- + " permission; skipping this combination.");
+ getLogWriter().info("testOps1: Unable to obtain valid credentials with no " + client2OpCodes[0].toString() + " permission; skipping this combination.");
return false;
}
+
javaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testOps1: For second client credentials: " + client2Credentials[0]
- + "\n" + client2Credentials[1]);
+ getLogWriter().info("testOps1: For second client credentials: " + client2Credentials[0] + "\n" + client2Credentials[1]);
+
if (bothClientsInMultiuserMode) {
final Properties finalJavaProps2 = javaProps;
- client2.invoke(() -> SecurityTestUtil.createCacheClientForMultiUserMode(2, authInit, client2Credentials, finalJavaProps2, new int[] {port1, port2}, -1, false, SecurityTestUtil.NO_EXCEPTION));
+ client2.invoke(() -> createCacheClientForMultiUserMode(2, authInit, client2Credentials, finalJavaProps2, new int[] {port1, port2}, -1, false, NO_EXCEPTION));
+
} else {
int credentialsIndex = allowOp ? 0 : 1;
final Properties finalJavaProps2 = javaProps;
- client2.invoke(() -> SecurityTestUtil.createCacheClient(authInit, client2Credentials[credentialsIndex], finalJavaProps2, new int[] {port1, port2}, -1, false, false, SecurityTestUtil.NO_EXCEPTION));
+ client2.invoke(() -> createCacheClient(authInit, client2Credentials[credentialsIndex], finalJavaProps2, new int[] {port1, port2}, -1, false, false, NO_EXCEPTION));
}
+
return true;
}
@@ -194,18 +268,17 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase {
verifyPutsGets(true, false /*unused */);
}
- private void verifyPutsGets(Boolean isMultiuser, Boolean opAllowed)
- throws Exception {
+ private void verifyPutsGets(final boolean isMultiuser, final boolean opAllowed) throws Exception {
// Perform some put operations from client1
- client1.invoke(() -> SecurityTestUtil.doMultiUserPuts(2, 2, new Integer[] { SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}));
+ client1.invoke(() -> doMultiUserPuts(2, 2, new Integer[] { NO_EXCEPTION, NOTAUTHZ_EXCEPTION}));
// Verify that the gets succeed/fail
if (isMultiuser) {
- client2.invoke(() -> SecurityTestUtil.doMultiUserGets(2, 2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}));
+ client2.invoke(() -> doMultiUserGets(2, 2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}));
+
} else {
- int expectedResult = (opAllowed) ? SecurityTestUtil.NO_EXCEPTION
- : SecurityTestUtil.NOTAUTHZ_EXCEPTION;
- client2.invoke(() -> SecurityTestUtil.doMultiUserGets(1, 1, new Integer[] {expectedResult}));
+ int expectedResult = (opAllowed) ? NO_EXCEPTION : NOTAUTHZ_EXCEPTION;
+ client2.invoke(() -> doMultiUserGets(1, 1, new Integer[] {expectedResult}));
}
}
@@ -213,19 +286,18 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase {
verifyContainsKeyDestroys(true, false /* unused */);
}
- private void verifyContainsKeyDestroys(Boolean isMultiuser, Boolean opAllowed)
- throws Exception {
+ private void verifyContainsKeyDestroys(final boolean isMultiuser, final boolean opAllowed) throws Exception {
// Do puts before verifying containsKey
- client1.invoke(() -> SecurityTestUtil.doMultiUserPuts(2, 2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NO_EXCEPTION}));
- client1.invoke(() -> SecurityTestUtil.doMultiUserContainsKeys(1, 2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}, new Boolean[] {Boolean.TRUE, Boolean.FALSE}));
+ client1.invoke(() -> doMultiUserPuts(2, 2, new Integer[] {NO_EXCEPTION, NO_EXCEPTION}));
+ client1.invoke(() -> doMultiUserContainsKeys(1, 2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}, new Boolean[] {true, false}));
// Verify that the destroys succeed/fail
if (isMultiuser) {
- client2.invoke(() -> SecurityTestUtil.doMultiUserDestroys(2, 2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}));
+ client2.invoke(() -> doMultiUserDestroys(2, 2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}));
+
} else {
- int expectedResult = (opAllowed) ? SecurityTestUtil.NO_EXCEPTION
- : SecurityTestUtil.NOTAUTHZ_EXCEPTION;
- client2.invoke(() -> SecurityTestUtil.doMultiUserDestroys(1, 1, new Integer[] {expectedResult}));
+ int expectedResult = (opAllowed) ? NO_EXCEPTION : NOTAUTHZ_EXCEPTION;
+ client2.invoke(() -> doMultiUserDestroys(1, 1, new Integer[] {expectedResult}));
}
}
@@ -233,167 +305,41 @@ public class ClientMultiUserAuthzDUnitTest extends ClientAuthorizationTestBase {
verifyContainsKeyInvalidates(true, false /* unused */);
}
- private void verifyContainsKeyInvalidates(Boolean isMultiuser, Boolean opAllowed)
- throws Exception {
+ private void verifyContainsKeyInvalidates(final boolean isMultiuser, final boolean opAllowed) throws Exception {
// Do puts before verifying containsKey
- client1.invoke(() -> SecurityTestUtil.doMultiUserPuts(2, 2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NO_EXCEPTION}));
- client1.invoke(() -> SecurityTestUtil.doMultiUserContainsKeys(1, 2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}, new Boolean[] {Boolean.TRUE, Boolean.FALSE}));
+ client1.invoke(() -> doMultiUserPuts(2, 2, new Integer[] {NO_EXCEPTION, NO_EXCEPTION}));
+ client1.invoke(() -> doMultiUserContainsKeys(1, 2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}, new Boolean[] {true, false}));
// Verify that the invalidates succeed/fail
if (isMultiuser) {
- client2.invoke(() -> SecurityTestUtil.doMultiUserInvalidates(2, 2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}));
+ client2.invoke(() -> doMultiUserInvalidates(2, 2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}));
+
} else {
- int expectedResult = (opAllowed) ? SecurityTestUtil.NO_EXCEPTION
- : SecurityTestUtil.NOTAUTHZ_EXCEPTION;
- client2.invoke(() -> SecurityTestUtil.doMultiUserInvalidates(1, 1, new Integer[] {expectedResult}));
+ int expectedResult = (opAllowed) ? NO_EXCEPTION : NOTAUTHZ_EXCEPTION;
+ client2.invoke(() -> doMultiUserInvalidates(1, 1, new Integer[] {expectedResult}));
}
}
private void verifyGetAllInTX() {
- server1.invoke(() -> ClientMultiUserAuthzDUnitTest.doPuts());
- client1.invoke(() -> SecurityTestUtil.doMultiUserGetAll(2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}, Boolean.TRUE/*use TX*/));
+ server1.invoke(() -> doPuts());
+ client1.invoke(() -> doMultiUserGetAll(2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}, true/*use TX*/));
}
private void verifyGetAllRegionDestroys() {
- server1.invoke(() -> ClientMultiUserAuthzDUnitTest.doPuts());
- client1.invoke(() -> SecurityTestUtil.doMultiUserGetAll(2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}));
+ server1.invoke(() -> doPuts());
+ client1.invoke(() -> doMultiUserGetAll(2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}));
// Verify that the region destroys succeed/fail
- client2.invoke(() -> SecurityTestUtil.doMultiUserRegionDestroys(2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}));
+ client2.invoke(() -> doMultiUserRegionDestroys(2, new Integer[] {NO_EXCEPTION, NOTAUTHZ_EXCEPTION}));
}
- public static void doPuts() {
- Region region = GemFireCacheImpl.getInstance().getRegion(SecurityTestUtil.REGION_NAME);
+ private void doPuts() {
+ Region region = GemFireCacheImpl.getInstance().getRegion(REGION_NAME);
region.put("key1", "value1");
region.put("key2", "value2");
}
- /**
- * Test query/function execute
- */
- @Test
- public void testOps2() throws Exception {
- AuthzCredentialGenerator gen = getXmlAuthzGenerator();
- CredentialGenerator cGen = gen.getCredentialGenerator();
- Properties extraAuthProps = cGen.getSystemProperties();
- Properties javaProps = cGen.getJavaProperties();
- Properties extraAuthzProps = gen.getSystemProperties();
- String authenticator = cGen.getAuthenticator();
- String authInit = cGen.getAuthInit();
- String accessor = gen.getAuthorizationCallback();
-
- LogWriterUtils.getLogWriter().info("testOps2: Using authinit: " + authInit);
- LogWriterUtils.getLogWriter().info("testOps2: Using authenticator: " + authenticator);
- LogWriterUtils.getLogWriter().info("testOps2: Using accessor: " + accessor);
-
- // Start servers with all required properties
- Properties serverProps = buildProperties(authenticator, accessor, false,
- extraAuthProps, extraAuthzProps);
- Integer port1 = createCacheServerOnVM(server1, javaProps, serverProps);
- Integer port2 = createCacheServerOnVM(server2, javaProps, serverProps);
-
- // Start client1 with valid/invalid QUERY credentials
- Properties[] client1Credentials = new Properties[] {
- gen.getAllowedCredentials(
- new OperationCode[] {OperationCode.PUT, OperationCode.QUERY},
- new String[] {regionName},
- 1),
- gen.getDisallowedCredentials(
- new OperationCode[] {OperationCode.PUT, OperationCode.QUERY},
- new String[] {regionName},
- 1)
- };
-
- javaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testOps2: For first client credentials: " + client1Credentials[0]
- + "\n" + client1Credentials[1]);
- final Properties finalJavaProps = javaProps;
- client1.invoke(() -> SecurityTestUtil.createCacheClientForMultiUserMode(2, authInit, client1Credentials, finalJavaProps, new int[] {port1, port2}, -1, false, SecurityTestUtil.NO_EXCEPTION));
-
- // Start client2 with valid/invalid EXECUTE_FUNCTION credentials
- Properties[] client2Credentials = new Properties[] {
- gen.getAllowedCredentials(new OperationCode[] {OperationCode.EXECUTE_FUNCTION},
- new String[] {regionName}, 2),
- gen.getDisallowedCredentials(new OperationCode[] {OperationCode.EXECUTE_FUNCTION},
- new String[] {regionName}, 9)};
-
- javaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testOps2: For second client credentials: " + client2Credentials[0]
- + "\n" + client2Credentials[1]);
- final Properties finalJavaProps2 = javaProps;
- client2.invoke(() -> SecurityTestUtil.createCacheClientForMultiUserMode(2, authInit, client2Credentials, finalJavaProps2, new int[] {port1, port2}, -1, false, SecurityTestUtil.NO_EXCEPTION));
-
- Function function = new TestFunction(true,TestFunction.TEST_FUNCTION1);
- server1.invoke(() -> PRClientServerTestBase.registerFunction(function));
-
- server2.invoke(() -> PRClientServerTestBase.registerFunction(function));
-
- // Perform some put operations before verifying queries
- client1.invoke(() -> SecurityTestUtil.doMultiUserPuts(4, 2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}));
- client1.invoke(() -> SecurityTestUtil.doMultiUserQueries(2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}, 4));
- client1.invoke(() -> SecurityTestUtil.doMultiUserQueryExecute(2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}, 4));
-
- // Verify that the FE succeeds/fails
- client2.invoke(() ->SecurityTestUtil.doMultiUserFE(2, function, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}, new Object[] {null, null}, false));
-
- // Failover
- server1.invoke(() -> SecurityTestUtil.closeCache());
- Thread.sleep(2000);
-
- client1.invoke(() -> SecurityTestUtil.doMultiUserPuts(4, 2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}));
-
- client1.invoke(() -> SecurityTestUtil.doMultiUserQueries(2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}, 4));
- client1.invoke(() -> SecurityTestUtil.doMultiUserQueryExecute(2, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}, 4));
-
- // Verify that the FE succeeds/fails
- client2.invoke(() -> SecurityTestUtil.doMultiUserFE(2, function, new Integer[] {SecurityTestUtil.NO_EXCEPTION, SecurityTestUtil.NOTAUTHZ_EXCEPTION}, new Object[] {null, null}, true));
- }
-
- protected Integer createCacheServerOnVM(VM server, Properties javaProps, Properties serverProps) {
- return server.invoke(() -> ClientAuthorizationTestBase.createCacheServer(SecurityTestUtil.getLocatorPort(), serverProps, javaProps));
-
- }
-
- public void testOpsWithClientsInDifferentModes() throws Exception {
- Iterator iter = getDummyGeneratorCombos().iterator();
- while (iter.hasNext()) {
- AuthzCredentialGenerator gen = (AuthzCredentialGenerator)iter.next();
- CredentialGenerator cGen = gen.getCredentialGenerator();
- Properties extraAuthProps = cGen.getSystemProperties();
- Properties javaProps = cGen.getJavaProperties();
- Properties extraAuthzProps = gen.getSystemProperties();
- String authenticator = cGen.getAuthenticator();
- String authInit = cGen.getAuthInit();
- String accessor = gen.getAuthorizationCallback();
-
- LogWriterUtils.getLogWriter().info("testOpsWithClientsInDifferentModes: Using authinit: " + authInit);
- LogWriterUtils.getLogWriter().info(
- "testOpsWithClientsInDifferentModes: Using authenticator: " + authenticator);
- LogWriterUtils.getLogWriter().info("testOpsWithClientsInDifferentModes: Using accessor: " + accessor);
-
- // Start servers with all required properties
- Properties serverProps = buildProperties(authenticator, accessor, false,
- extraAuthProps, extraAuthzProps);
- Integer port1 = createCacheServerOnVM(server1, javaProps, serverProps);
- Integer port2 = createCacheServerOnVM(server2, javaProps, serverProps);
-
- if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
- OperationCode.PUT, OperationCode.PUT}, new OperationCode[] {
- OperationCode.GET, OperationCode.GET}, javaProps, authInit, port1,
- port2, Boolean.FALSE, Boolean.TRUE)) {
- continue;
- }
- verifyPutsGets(false, true);
-
- if (!prepareClientsForOps(gen, cGen, new OperationCode[] {
- OperationCode.PUT, OperationCode.CONTAINS_KEY}, new OperationCode[] {
- OperationCode.DESTROY, OperationCode.DESTROY},
- javaProps, authInit, port1, port2, Boolean.FALSE, Boolean.FALSE)) {
- continue;
- }
- verifyContainsKeyDestroys(false, false);
- }
+ private int createCacheServerOnVM(final VM server, final Properties javaProps, final Properties serverProps) {
+ return server.invoke(() -> ClientAuthorizationTestBase.createCacheServer(getLocatorPort(), serverProps, javaProps));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientAuthorizationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientAuthorizationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientAuthorizationDUnitTest.java
index 708140c..58e05a0 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientAuthorizationDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientAuthorizationDUnitTest.java
@@ -18,6 +18,8 @@
*/
package com.gemstone.gemfire.security;
+import static com.gemstone.gemfire.security.ClientAuthenticationUtils.*;
+import static com.gemstone.gemfire.security.ClientAuthorizationTestBase.*;
import static com.gemstone.gemfire.security.SecurityTestUtil.*;
import static com.gemstone.gemfire.test.dunit.Assert.*;
import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
@@ -72,19 +74,21 @@ public final class DeltaClientAuthorizationDUnitTest extends ClientAuthorization
// Start servers with all required properties
Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
- Integer port1 = createServer1(javaProps, serverProps);
- Integer port2 = createServer2(javaProps, serverProps);
+ int port1 = createServer1(javaProps, serverProps);
+ int port2 = createServer2(javaProps, serverProps);
// Start client1 with valid CREATE credentials
Properties createCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.PUT }, new String[] { REGION_NAME }, 1);
javaProps = cGen.getJavaProperties();
getLogWriter().info("testAllowPutsGets: For first client credentials: " + createCredentials);
+
createClient1(javaProps, authInit, port1, port2, createCredentials);
// Start client2 with valid GET credentials
Properties getCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.GET }, new String[] { REGION_NAME }, 2);
javaProps = cGen.getJavaProperties();
+
getLogWriter().info("testAllowPutsGets: For second client credentials: " + getCredentials);
createClient2(javaProps, authInit, port1, port2, getCredentials);
@@ -99,23 +103,23 @@ public final class DeltaClientAuthorizationDUnitTest extends ClientAuthorization
client2.invoke(() -> doGets(2, NO_EXCEPTION));
}
- private void createClient2(Properties javaProps, String authInit, int port1, int port2, Properties getCredentials) {
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, getCredentials, javaProps, port1, port2, 0, NO_EXCEPTION));
+ private void createClient2(final Properties javaProps, final String authInit, final int port1, final int port2, final Properties getCredentials) {
+ client2.invoke(() -> createCacheClient(authInit, getCredentials, javaProps, port1, port2, 0, NO_EXCEPTION));
}
- private void createClient1(Properties javaProps, String authInit, int port1, int port2, Properties createCredentials) {
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, createCredentials, javaProps, port1, port2, 0, NO_EXCEPTION));
+ private void createClient1(final Properties javaProps, final String authInit, final int port1, final int port2, final Properties createCredentials) {
+ client1.invoke(() -> createCacheClient(authInit, createCredentials, javaProps, port1, port2, 0, NO_EXCEPTION));
}
- private Integer createServer2(Properties javaProps, Properties serverProps) {
- return server2.invoke(() -> ClientAuthorizationTestBase.createCacheServer(getLocatorPort(), serverProps, javaProps));
+ private int createServer2(final Properties javaProps, final Properties serverProps) {
+ return server2.invoke(() -> createCacheServer(getLocatorPort(), serverProps, javaProps));
}
- private Integer createServer1(Properties javaProps, Properties serverProps) {
- return server1.invoke(() -> ClientAuthorizationTestBase.createCacheServer(getLocatorPort(), serverProps, javaProps));
+ private int createServer1(final Properties javaProps, final Properties serverProps) {
+ return server1.invoke(() -> createCacheServer(getLocatorPort(), serverProps, javaProps));
}
- private void doPuts(int num, int expectedResult) {
+ private void doPuts(final int num, final int expectedResult) {
assertTrue(num <= KEYS.length);
Region region = getCache().getRegion(REGION_NAME);
assertNotNull(region);
@@ -130,10 +134,10 @@ public final class DeltaClientAuthorizationDUnitTest extends ClientAuthorization
}
}
- private void doGets(int num, int expectedResult) {
+ private void doGets(final int num, final int expectedResult) {
assertTrue(num <= KEYS.length);
- Region region = SecurityTestUtil.getCache().getRegion(REGION_NAME);
+ Region region = getCache().getRegion(REGION_NAME);
assertNotNull(region);
for (int index = 0; index < num; ++index) {
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientPostAuthorizationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientPostAuthorizationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientPostAuthorizationDUnitTest.java
index b838957..7c7fe9b 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientPostAuthorizationDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/DeltaClientPostAuthorizationDUnitTest.java
@@ -19,6 +19,7 @@
package com.gemstone.gemfire.security;
import static com.gemstone.gemfire.internal.AvailablePort.*;
+import static com.gemstone.gemfire.security.DeltaClientPostAuthorizationDUnitTest.*;
import static com.gemstone.gemfire.security.SecurityTestUtil.*;
import static com.gemstone.gemfire.test.dunit.Assert.*;
import static com.gemstone.gemfire.test.dunit.IgnoredException.*;
@@ -27,19 +28,12 @@ import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Properties;
import java.util.Random;
import com.gemstone.gemfire.DeltaTestImpl;
-import com.gemstone.gemfire.cache.InterestResultPolicy;
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.cache.client.ServerConnectivityException;
import com.gemstone.gemfire.cache.operations.OperationContext.OperationCode;
-import com.gemstone.gemfire.cache.query.CqException;
-import com.gemstone.gemfire.cache.query.QueryInvocationTargetException;
import com.gemstone.gemfire.internal.cache.PartitionedRegionLocalMaxMemoryDUnitTest;
-import com.gemstone.gemfire.internal.util.Callable;
import com.gemstone.gemfire.security.generator.AuthzCredentialGenerator;
import com.gemstone.gemfire.security.generator.CredentialGenerator;
import com.gemstone.gemfire.test.dunit.VM;
@@ -66,7 +60,7 @@ public class DeltaClientPostAuthorizationDUnitTest extends ClientAuthorizationTe
@Override
public final void preTearDownClientAuthorizationTestBase() throws Exception {
- SecurityTestUtil.closeCache();
+ closeCache();
}
@Test
@@ -106,15 +100,15 @@ public class DeltaClientPostAuthorizationDUnitTest extends ClientAuthorizationTe
// End of current operation block; execute all the operations on the servers with failover
if (opBlock.size() > 0) {
// Start the first server and execute the operation block
- server1.invoke(() -> ClientAuthorizationTestBase.createCacheServer(SecurityTestUtil.getLocatorPort(), port1, serverProps, javaProps ));
- server2.invoke(() -> SecurityTestUtil.closeCache());
+ server1.invoke(() -> ClientAuthorizationTestBase.createCacheServer(getLocatorPort(), port1, serverProps, javaProps ));
+ server2.invoke(() -> closeCache());
executeOpBlock(opBlock, port1, port2, authInit, extraAuthProps, extraAuthzProps, tgen, rnd);
if (!currentOp.equals(OperationWithAction.OPBLOCK_NO_FAILOVER)) {
// Failover to the second server and run the block again
- server2.invoke(() -> ClientAuthorizationTestBase.createCacheServer(SecurityTestUtil.getLocatorPort(), port2, serverProps, javaProps ));
- server1.invoke(() -> SecurityTestUtil.closeCache());
+ server2.invoke(() -> ClientAuthorizationTestBase.createCacheServer(getLocatorPort(), port2, serverProps, javaProps ));
+ server1.invoke(() -> closeCache());
executeOpBlock(opBlock, port1, port2, authInit, extraAuthProps, extraAuthzProps, tgen, rnd);
}
@@ -180,26 +174,26 @@ public class DeltaClientPostAuthorizationDUnitTest extends ClientAuthorizationTe
credentialsTypeStr = " authorized " + authOpCode;
}
- Properties clientProps = SecurityTestUtil.concatProperties(new Properties[] { opCredentials, extraAuthProps, extraAuthzProps });
+ Properties clientProps = concatProperties(new Properties[] { opCredentials, extraAuthProps, extraAuthzProps });
// Start the client with valid credentials but allowed or disallowed to perform an operation
getLogWriter().info("executeOpBlock: For client" + clientNum + credentialsTypeStr + " credentials: " + opCredentials);
boolean setupDynamicRegionFactory = (opFlags & OpFlags.ENABLE_DRF) > 0;
if (useThisVM) {
- createCacheClient(authInit, clientProps, javaProps, new int[] { port1, port2 }, 0, setupDynamicRegionFactory, SecurityTestUtil.NO_EXCEPTION);
+ createCacheClient(authInit, clientProps, javaProps, new int[] { port1, port2 }, 0, setupDynamicRegionFactory, NO_EXCEPTION);
} else {
- clientVM.invoke(() -> createCacheClient(authInit, clientProps, javaProps, new int[] { port1, port2 }, 0, setupDynamicRegionFactory, SecurityTestUtil.NO_EXCEPTION));
+ clientVM.invoke(() -> createCacheClient(authInit, clientProps, javaProps, new int[] { port1, port2 }, 0, setupDynamicRegionFactory, NO_EXCEPTION));
}
}
int expectedResult;
if ((opFlags & OpFlags.CHECK_NOTAUTHZ) > 0) {
- expectedResult = SecurityTestUtil.NOTAUTHZ_EXCEPTION;
+ expectedResult = NOTAUTHZ_EXCEPTION;
} else if ((opFlags & OpFlags.CHECK_EXCEPTION) > 0) {
- expectedResult = SecurityTestUtil.OTHER_EXCEPTION;
+ expectedResult = OTHER_EXCEPTION;
} else {
- expectedResult = SecurityTestUtil.NO_EXCEPTION;
+ expectedResult = NO_EXCEPTION;
}
// Perform the operation from selected client
@@ -208,15 +202,14 @@ public class DeltaClientPostAuthorizationDUnitTest extends ClientAuthorizationTe
} else {
byte ordinal = opCode.toOrdinal();
int[] indices = currentOp.getIndices();
- clientVM.invoke(() -> DeltaClientPostAuthorizationDUnitTest.doOp(new Byte(ordinal), indices, new Integer(opFlags), new Integer(expectedResult) ));
+ clientVM.invoke(() -> doOp(new Byte(ordinal), indices, new Integer(opFlags), new Integer(expectedResult) ));
}
}
}
- private final void setUpDeltas() {
+ private void setUpDeltas() {
for (int i = 0; i < 8; i++) {
- deltas[i] = new DeltaTestImpl(0, "0", new Double(0), new byte[0],
- new PartitionedRegionLocalMaxMemoryDUnitTest.TestObject1("0", 0));
+ deltas[i] = new DeltaTestImpl(0, "0", new Double(0), new byte[0], new PartitionedRegionLocalMaxMemoryDUnitTest.TestObject1("0", 0));
}
deltas[1].setIntVar(5);
deltas[2].setIntVar(5);
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/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
index ba6b26f..e514b1c 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/P2PAuthenticationDUnitTest.java
@@ -58,9 +58,6 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
private static VM locatorVM = null;
- private static final String USER_NAME = "security-username";
- private static final String PASSWORD = "security-password";
-
private static final String[] ignoredExceptions = {
AuthenticationRequiredException.class.getName(),
AuthenticationFailedException.class.getName(),
@@ -160,7 +157,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
props.setProperty(SECURITY_PEER_AUTH_INIT_NAME, "Incorrect_AuthInitialize");
props.setProperty(SECURITY_PEER_AUTHENTICATOR_NAME, gen.getAuthenticator());
- startLocator(props, gen.getJavaProperties(), locatorPort);
+ startTheLocator(props, gen.getJavaProperties(), locatorPort);
try {
new SecurityTestUtil("tmp").createSystem(props, null);
@@ -191,7 +188,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
props.setProperty(SECURITY_PEER_AUTH_INIT_NAME, gen.getAuthInit());
props.setProperty(SECURITY_PEER_AUTHENTICATOR_NAME, "xyz");
- startLocator(props, null, locatorPort);
+ startTheLocator(props, null, locatorPort);
try {
new SecurityTestUtil("tmp").createSystem(props, null);
@@ -201,7 +198,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
// success
} finally {
- locatorVM.invoke(() -> SecurityTestUtil.stopLocator(locatorPort, ignoredExceptions));
+ locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
}
}
@@ -221,7 +218,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
props.setProperty(SECURITY_PEER_AUTH_INIT_NAME, gen.getAuthInit());
props.setProperty(SECURITY_PEER_AUTHENTICATOR_NAME, gen.getAuthenticator());
- startLocator(props, null, locatorPort);
+ startTheLocator(props, null, locatorPort);
try {
new SecurityTestUtil("tmp").createSystem(props, null);
@@ -231,7 +228,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
// success
} finally {
- locatorVM.invoke(() -> SecurityTestUtil.stopLocator(locatorPort, ignoredExceptions));
+ locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
}
}
@@ -253,7 +250,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
props.setProperty(SECURITY_PEER_AUTHENTICATOR_NAME, gen.getAuthenticator());
props.putAll(gen.getValidCredentials(1));
- startLocator(props, gen.getJavaProperties(), locatorPort);
+ startTheLocator(props, gen.getJavaProperties(), locatorPort);
try {
createDS(props, gen.getJavaProperties());
@@ -261,7 +258,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
disconnectFromDS();
} finally {
- locatorVM.invoke(() -> SecurityTestUtil.stopLocator(locatorPort, ignoredExceptions));
+ locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
}
}
@@ -287,7 +284,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
props.setProperty(SECURITY_PEER_AUTHENTICATOR_NAME, gen.getAuthenticator());
props.putAll(gen.getValidCredentials(1));
- startLocator(props, null, locatorPort);
+ startTheLocator(props, null, locatorPort);
try {
// invalid credentials for the peer
@@ -308,7 +305,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
disconnectFromDS();
} finally {
- locatorVM.invoke(() -> SecurityTestUtil.stopLocator(locatorPort, ignoredExceptions));
+ locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
}
}
@@ -361,7 +358,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
props.putAll(credentials);
props.putAll(extraProps);
- startLocator(props, javaProps, port);
+ startTheLocator(props, javaProps, port);
try {
@@ -399,34 +396,34 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
pause(2000);
// Verify the number of members on all peers and locator
- locatorVM.invoke(() -> P2PAuthenticationDUnitTest.verifyMembers(4));
+ locatorVM.invoke(() -> verifyMembers(4));
verifyMembers(2);
- peer2.invoke(() -> P2PAuthenticationDUnitTest.verifyMembers(4));
- peer3.invoke(() -> P2PAuthenticationDUnitTest.verifyMembers(4));
+ peer2.invoke(() -> verifyMembers(4));
+ peer3.invoke(() -> verifyMembers(4));
// Disconnect the first peer and check again
disconnectFromDS();
pause(2000);
- locatorVM.invoke(() -> P2PAuthenticationDUnitTest.verifyMembers(3));
- peer2.invoke(() -> P2PAuthenticationDUnitTest.verifyMembers(3));
- peer3.invoke(() -> P2PAuthenticationDUnitTest.verifyMembers(3));
+ 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(() -> P2PAuthenticationDUnitTest.verifyMembers(2));
- peer3.invoke(() -> P2PAuthenticationDUnitTest.verifyMembers(2));
+ locatorVM.invoke(() -> verifyMembers(2));
+ peer3.invoke(() -> verifyMembers(2));
// Same for last peer
peer3.invoke(() -> disconnectFromDS());
pause(2000);
- locatorVM.invoke(() -> P2PAuthenticationDUnitTest.verifyMembers(1));
+ locatorVM.invoke(() -> verifyMembers(1));
} finally {
- locatorVM.invoke(() -> SecurityTestUtil.stopLocator(port, ignoredExceptions));
+ locatorVM.invoke(() -> stopLocator(port, ignoredExceptions));
}
}
@@ -461,7 +458,7 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
props.setProperty(SECURITY_PEER_AUTHENTICATOR_NAME, gen.getAuthenticator());
props.putAll(credentials);
- startLocator(props, null, locatorPort);
+ startTheLocator(props, null, locatorPort);
try {
// Start the first peer with huge credentials
@@ -514,24 +511,24 @@ public class P2PAuthenticationDUnitTest extends JUnit4DistributedTestCase {
peer3.invoke(() -> disconnectFromDS());
} finally {
- locatorVM.invoke(() -> SecurityTestUtil.stopLocator(locatorPort, ignoredExceptions));
+ locatorVM.invoke(() -> stopLocator(locatorPort, ignoredExceptions));
}
}
- private void createDS(VM peer2, Properties props, Properties javaProps) {
+ private void createDS(final VM peer2, final Properties props, final Properties javaProps) {
peer2.invoke(() -> createDS(props, javaProps));
}
- private void startLocator(Properties props, Properties javaProps, int port) {
- locatorVM.invoke(() -> SecurityTestUtil.startLocator(getUniqueName(), port, props, javaProps, ignoredExceptions));
+ private void startTheLocator(final Properties props, final Properties javaProps, final int port) {
+ locatorVM.invoke(() -> startLocator(getUniqueName(), port, props, javaProps, ignoredExceptions));
}
- private static void createDS(Properties props, Properties javaProps) {
+ private static void createDS(final Properties props, final Properties javaProps) {
SecurityTestUtil tmpUtil = new SecurityTestUtil("tmp");
tmpUtil.createSystem(props, javaProps);
}
- private static void verifyMembers(int numExpectedMembers) {
+ private static void verifyMembers(final int numExpectedMembers) {
DistributedSystem ds = InternalDistributedSystem.getAnyInstance();
MembershipManager mgr = MembershipManagerHelper.getMembershipManager(ds);
assertEquals(numExpectedMembers, mgr.getView().size());
[3/4] incubator-geode git commit: Cleanup
Posted by kl...@apache.org.
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationDUnitTest.java
index 7a738f1..69e2843 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationDUnitTest.java
@@ -18,8 +18,13 @@
*/
package com.gemstone.gemfire.security;
+import static com.gemstone.gemfire.internal.AvailablePort.*;
+//import static com.gemstone.gemfire.security.ClientAuthenticationUtils.*;
+//import static com.gemstone.gemfire.security.ClientAuthorizationTestBase.*;
import static com.gemstone.gemfire.security.SecurityTestUtil.*;
import static com.gemstone.gemfire.test.dunit.Assert.*;
+import static com.gemstone.gemfire.test.dunit.IgnoredException.*;
+import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
import java.util.ArrayList;
import java.util.Iterator;
@@ -27,14 +32,11 @@ import java.util.List;
import java.util.Properties;
import com.gemstone.gemfire.cache.operations.OperationContext.OperationCode;
-import com.gemstone.gemfire.internal.AvailablePort;
import com.gemstone.gemfire.security.generator.AuthzCredentialGenerator;
import com.gemstone.gemfire.security.generator.CredentialGenerator;
import com.gemstone.gemfire.security.generator.DummyCredentialGenerator;
import com.gemstone.gemfire.security.generator.XmlAuthzCredentialGenerator;
import com.gemstone.gemfire.security.templates.UserPasswordAuthInit;
-import com.gemstone.gemfire.test.dunit.IgnoredException;
-import com.gemstone.gemfire.test.dunit.LogWriterUtils;
import com.gemstone.gemfire.test.dunit.VM;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;
import org.junit.Test;
@@ -53,187 +55,51 @@ public class ClientAuthorizationDUnitTest extends ClientAuthorizationTestBase {
@Override
public final void preTearDownClientAuthorizationTestBase() throws Exception {
- // close the clients first
- client1.invoke(() -> SecurityTestUtil.closeCache());
- client2.invoke(() -> SecurityTestUtil.closeCache());
- SecurityTestUtil.closeCache();
- // then close the servers
- server1.invoke(() -> SecurityTestUtil.closeCache());
- server2.invoke(() -> SecurityTestUtil.closeCache());
+ closeCache();
}
- private Properties getUserPassword(String userName) {
+ @Test
+ public void testAllowPutsGets() {
+ AuthzCredentialGenerator gen = getXmlAuthzGenerator();
+ CredentialGenerator cGen = gen.getCredentialGenerator();
+ Properties extraAuthProps = cGen.getSystemProperties();
+ Properties javaProps = cGen.getJavaProperties();
+ Properties extraAuthzProps = gen.getSystemProperties();
+ String authenticator = cGen.getAuthenticator();
+ String authInit = cGen.getAuthInit();
+ String accessor = gen.getAuthorizationCallback();
- Properties props = new Properties();
- props.setProperty(UserPasswordAuthInit.USER_NAME, userName);
- props.setProperty(UserPasswordAuthInit.PASSWORD, userName);
- return props;
- }
+ getLogWriter().info("testAllowPutsGets: Using authinit: " + authInit);
+ getLogWriter().info("testAllowPutsGets: Using authenticator: " + authenticator);
+ getLogWriter().info("testAllowPutsGets: Using accessor: " + accessor);
- private void executeRIOpBlock(List opBlock, Integer port1, Integer port2,
- String authInit, Properties extraAuthProps, Properties extraAuthzProps,
- Properties javaProps) throws InterruptedException {
+ // Start servers with all required properties
+ Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
- Iterator opIter = opBlock.iterator();
- while (opIter.hasNext()) {
- // Start client with valid credentials as specified in
- // OperationWithAction
- OperationWithAction currentOp = (OperationWithAction)opIter.next();
- OperationCode opCode = currentOp.getOperationCode();
- int opFlags = currentOp.getFlags();
- int clientNum = currentOp.getClientNum();
- VM clientVM = null;
- boolean useThisVM = false;
- switch (clientNum) {
- case 1:
- clientVM = client1;
- break;
- case 2:
- clientVM = client2;
- break;
- case 3:
- useThisVM = true;
- break;
- default:
- fail("executeRIOpBlock: Unknown client number " + clientNum);
- break;
- }
- LogWriterUtils.getLogWriter().info(
- "executeRIOpBlock: performing operation number ["
- + currentOp.getOpNum() + "]: " + currentOp);
- if ((opFlags & OpFlags.USE_OLDCONN) == 0) {
- Properties opCredentials = null;
- String currentRegionName = '/' + regionName;
- if ((opFlags & OpFlags.USE_SUBREGION) > 0) {
- currentRegionName += ('/' + subregionName);
- }
- String credentialsTypeStr;
- OperationCode authOpCode = currentOp.getAuthzOperationCode();
- if ((opFlags & OpFlags.CHECK_NOTAUTHZ) > 0
- || (opFlags & OpFlags.USE_NOTAUTHZ) > 0
- || !authOpCode.equals(opCode)) {
- credentialsTypeStr = " unauthorized " + authOpCode;
- if (authOpCode.isRegisterInterest()) {
- opCredentials = getUserPassword("reader7");
- }
- else if (authOpCode.isUnregisterInterest()) {
- opCredentials = getUserPassword("reader6");
- }
- else {
- fail("executeRIOpBlock: cannot determine credentials for"
- + credentialsTypeStr);
- }
- }
- else {
- credentialsTypeStr = " authorized " + authOpCode;
- if (authOpCode.isRegisterInterest()
- || authOpCode.isUnregisterInterest()) {
- opCredentials = getUserPassword("reader5");
- }
- else if (authOpCode.isPut()) {
- opCredentials = getUserPassword("writer1");
- }
- else if (authOpCode.isGet()) {
- opCredentials = getUserPassword("reader1");
- }
- else {
- fail("executeRIOpBlock: cannot determine credentials for"
- + credentialsTypeStr);
- }
- }
- Properties clientProps = SecurityTestUtil
- .concatProperties(new Properties[] { opCredentials, extraAuthProps,
- extraAuthzProps });
- // Start the client with valid credentials but allowed or disallowed to
- // perform an operation
- LogWriterUtils.getLogWriter().info(
- "executeRIOpBlock: For client" + clientNum + credentialsTypeStr
- + " credentials: " + opCredentials);
- if (useThisVM) {
- SecurityTestUtil.createCacheClientWithDynamicRegion(authInit, clientProps, javaProps, new int[] { port1, port2 }, 0, false, NO_EXCEPTION);
- }
- else {
- clientVM.invoke(() -> createCacheClient(authInit, clientProps, javaProps, new int[] { port1, port2 }, 0, false, SecurityTestUtil.NO_EXCEPTION));
- }
- }
- int expectedResult;
- if ((opFlags & OpFlags.CHECK_NOTAUTHZ) > 0) {
- expectedResult = SecurityTestUtil.NOTAUTHZ_EXCEPTION;
- }
- else if ((opFlags & OpFlags.CHECK_EXCEPTION) > 0) {
- expectedResult = SecurityTestUtil.OTHER_EXCEPTION;
- }
- else {
- expectedResult = SecurityTestUtil.NO_EXCEPTION;
- }
+ int port1 = createServer1(javaProps, serverProps);
+ int port2 = createServer2(javaProps, serverProps);
- // Perform the operation from selected client
- if (useThisVM) {
- doOp(new Byte(opCode.toOrdinal()), currentOp.getIndices(), new Integer(
- opFlags), new Integer(expectedResult));
- }
- else {
- byte ordinal = opCode.toOrdinal();
- int[] indices = currentOp.getIndices();
- clientVM.invoke(() -> ClientAuthorizationTestBase.doOp( new Byte(ordinal),
- indices, new Integer(opFlags),
- new Integer(expectedResult) ));
- }
- }
- }
+ // Start client1 with valid CREATE credentials
+ Properties createCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.PUT }, new String[] { regionName }, 1);
+ javaProps = cGen.getJavaProperties();
- @Test
- public void testAllowPutsGets() {
- AuthzCredentialGenerator gen = getXmlAuthzGenerator();
- CredentialGenerator cGen = gen.getCredentialGenerator();
- Properties extraAuthProps = cGen.getSystemProperties();
- Properties javaProps = cGen.getJavaProperties();
- Properties extraAuthzProps = gen.getSystemProperties();
- String authenticator = cGen.getAuthenticator();
- String authInit = cGen.getAuthInit();
- String accessor = gen.getAuthorizationCallback();
-
- LogWriterUtils.getLogWriter().info("testAllowPutsGets: Using authinit: " + authInit);
- LogWriterUtils.getLogWriter().info(
- "testAllowPutsGets: Using authenticator: " + authenticator);
- LogWriterUtils.getLogWriter().info("testAllowPutsGets: Using accessor: " + accessor);
-
- // Start servers with all required properties
- Properties serverProps = buildProperties(authenticator, accessor, false,
- extraAuthProps, extraAuthzProps);
- Integer port1 = createServer1(javaProps, serverProps);
- Integer port2 = createServer2(javaProps, serverProps);
-
- // Start client1 with valid CREATE credentials
- Properties createCredentials = gen.getAllowedCredentials(
- new OperationCode[] { OperationCode.PUT },
- new String[] { regionName }, 1);
- javaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testAllowPutsGets: For first client credentials: "
- + createCredentials);
- createClient1NoException(javaProps, authInit, port1, port2,
- createCredentials);
-
- // Start client2 with valid GET credentials
- Properties getCredentials = gen.getAllowedCredentials(
- new OperationCode[] { OperationCode.GET },
- new String[] { regionName }, 2);
- javaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter()
- .info(
- "testAllowPutsGets: For second client credentials: "
- + getCredentials);
- createClient2NoException(javaProps, authInit, port1, port2,
- getCredentials);
-
- // Perform some put operations from client1
- client1.invoke(() -> SecurityTestUtil.doPuts(
- new Integer(2), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
-
- // Verify that the gets succeed
- client2.invoke(() -> SecurityTestUtil.doGets(
- new Integer(2), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
+ getLogWriter().info("testAllowPutsGets: For first client credentials: " + createCredentials);
+
+ createClient1NoException(javaProps, authInit, port1, port2, createCredentials);
+
+ // Start client2 with valid GET credentials
+ Properties getCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.GET }, new String[] { regionName }, 2);
+ javaProps = cGen.getJavaProperties();
+
+ getLogWriter().info("testAllowPutsGets: For second client credentials: " + getCredentials);
+
+ createClient2NoException(javaProps, authInit, port1, port2, getCredentials);
+
+ // Perform some put operations from client1
+ client1.invoke(() -> doPuts(2, NO_EXCEPTION));
+
+ // Verify that the gets succeed
+ client2.invoke(() -> doGets(2, NO_EXCEPTION));
}
@Test
@@ -247,382 +113,228 @@ public class ClientAuthorizationDUnitTest extends ClientAuthorizationTestBase {
String authInit = cGen.getAuthInit();
String accessor = gen.getAuthorizationCallback();
- LogWriterUtils.getLogWriter().info("testPutAllWithSecurity: Using authinit: " + authInit);
- LogWriterUtils.getLogWriter().info("testPutAllWithSecurity: Using authenticator: " + authenticator);
- LogWriterUtils.getLogWriter().info("testPutAllWithSecurity: Using accessor: " + accessor);
+ getLogWriter().info("testPutAllWithSecurity: Using authinit: " + authInit);
+ getLogWriter().info("testPutAllWithSecurity: Using authenticator: " + authenticator);
+ getLogWriter().info("testPutAllWithSecurity: Using accessor: " + accessor);
// Start servers with all required properties
Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
- Integer port1 = createServer1(javaProps, serverProps);
- Integer port2 = createServer2(javaProps, serverProps);
+
+ int port1 = createServer1(javaProps, serverProps);
+ int port2 = createServer2(javaProps, serverProps);
// Start client1 with valid CREATE credentials
Properties createCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.PUTALL }, new String[] { regionName }, 1);
javaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info("testPutAllWithSecurity: For first client credentials: " + createCredentials);
+
+ getLogWriter().info("testPutAllWithSecurity: For first client credentials: " + createCredentials);
+
createClient1NoException(javaProps, authInit, port1, port2, createCredentials);
// Perform some put all operations from client1
- client1.invoke(() -> SecurityTestUtil.doPutAllP());
- }
-
- protected void createClient2NoException(Properties javaProps, String authInit,
- Integer port1, Integer port2, Properties getCredentials) {
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, getCredentials, javaProps, port1, port2,
- 0, SecurityTestUtil.NO_EXCEPTION));
+ client1.invoke(() -> doPutAllP());
}
- protected void createClient1NoException(Properties javaProps, String authInit,
- Integer port1, Integer port2, Properties createCredentials) {
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, createCredentials, javaProps, port1, port2,
- 0, SecurityTestUtil.NO_EXCEPTION));
- }
+ @Test
+ public void testDisallowPutsGets() {
+ AuthzCredentialGenerator gen = getXmlAuthzGenerator();
+ CredentialGenerator cGen = gen.getCredentialGenerator();
+ Properties extraAuthProps = cGen.getSystemProperties();
+ Properties javaProps = cGen.getJavaProperties();
+ Properties extraAuthzProps = gen.getSystemProperties();
+ String authenticator = cGen.getAuthenticator();
+ String authInit = cGen.getAuthInit();
+ String accessor = gen.getAuthorizationCallback();
- protected Integer createServer2(Properties javaProps,
- Properties serverProps) {
- Integer port2 = ((Integer)server2.invoke(() -> ClientAuthorizationTestBase.createCacheServer(
- SecurityTestUtil.getLocatorPort(), serverProps, javaProps )));
- return port2;
- }
+ getLogWriter().info("testDisallowPutsGets: Using authinit: " + authInit);
+ getLogWriter().info("testDisallowPutsGets: Using authenticator: " + authenticator);
+ getLogWriter().info("testDisallowPutsGets: Using accessor: " + accessor);
- protected Integer createServer1(Properties javaProps,
- Properties serverProps) {
- Integer port1 = ((Integer)server1.invoke(() -> ClientAuthorizationTestBase.createCacheServer(
- SecurityTestUtil.getLocatorPort(), serverProps, javaProps )));
- return port1;
- }
+ // Check that we indeed can obtain valid credentials not allowed to do gets
+ Properties createCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.PUT }, new String[] { regionName }, 1);
+ Properties createJavaProps = cGen.getJavaProperties();
- @Test
- public void testDisallowPutsGets() {
+ getLogWriter().info("testDisallowPutsGets: For first client credentials: " + createCredentials);
+
+ Properties getCredentials = gen.getDisallowedCredentials(new OperationCode[] { OperationCode.GET }, new String[] { regionName }, 2);
+ Properties getJavaProps = cGen.getJavaProperties();
+
+ getLogWriter().info("testDisallowPutsGets: For second client disallowed GET credentials: " + getCredentials);
+
+ // Start servers with all required properties
+ Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
+
+ int port1 = createServer1(javaProps, serverProps);
+ int port2 = createServer2(javaProps, serverProps);
+
+ createClient1NoException(createJavaProps, authInit, port1, port2, createCredentials);
+
+ createClient2NoException(getJavaProps, authInit, port1, port2, getCredentials);
+
+ // Perform some put operations from client1
+ client1.invoke(() -> doPuts(2, NO_EXCEPTION));
- AuthzCredentialGenerator gen = getXmlAuthzGenerator();
- CredentialGenerator cGen = gen.getCredentialGenerator();
- Properties extraAuthProps = cGen.getSystemProperties();
- Properties javaProps = cGen.getJavaProperties();
- Properties extraAuthzProps = gen.getSystemProperties();
- String authenticator = cGen.getAuthenticator();
- String authInit = cGen.getAuthInit();
- String accessor = gen.getAuthorizationCallback();
-
- LogWriterUtils.getLogWriter().info("testDisallowPutsGets: Using authinit: " + authInit);
- LogWriterUtils.getLogWriter().info(
- "testDisallowPutsGets: Using authenticator: " + authenticator);
- LogWriterUtils.getLogWriter().info("testDisallowPutsGets: Using accessor: " + accessor);
-
- // Check that we indeed can obtain valid credentials not allowed to do
- // gets
- Properties createCredentials = gen.getAllowedCredentials(
- new OperationCode[] { OperationCode.PUT },
- new String[] { regionName }, 1);
- Properties createJavaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testDisallowPutsGets: For first client credentials: "
- + createCredentials);
- Properties getCredentials = gen.getDisallowedCredentials(
- new OperationCode[] { OperationCode.GET },
- new String[] { regionName }, 2);
- Properties getJavaProps = cGen.getJavaProperties();
-
- LogWriterUtils.getLogWriter().info(
- "testDisallowPutsGets: For second client disallowed GET credentials: "
- + getCredentials);
-
- // Start servers with all required properties
- Properties serverProps = buildProperties(authenticator, accessor, false,
- extraAuthProps, extraAuthzProps);
- Integer port1 = createServer1(javaProps, serverProps);
- Integer port2 = createServer2(javaProps, serverProps);
-
- createClient1NoException(createJavaProps, authInit, port1, port2,
- createCredentials);
-
- createClient2NoException(getJavaProps, authInit, port1, port2,
- getCredentials);
-
- // Perform some put operations from client1
- client1.invoke(() -> SecurityTestUtil.doPuts(
- new Integer(2), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
-
- // Gets as normal user should throw exception
- client2.invoke(() -> SecurityTestUtil.doGets(
- new Integer(2), new Integer(SecurityTestUtil.NOTAUTHZ_EXCEPTION) ));
-
- // Try to connect client2 with reader credentials
- getCredentials = gen.getAllowedCredentials(
- new OperationCode[] { OperationCode.GET },
- new String[] { regionName }, 5);
- getJavaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testDisallowPutsGets: For second client with GET credentials: "
- + getCredentials);
- createClient2NoException(getJavaProps, authInit, port1, port2,
- getCredentials);
-
- // Verify that the gets succeed
- client2.invoke(() -> SecurityTestUtil.doGets(
- new Integer(2), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
-
- // Verify that the puts throw exception
- client2.invoke(() -> SecurityTestUtil.doNPuts(
- new Integer(2), new Integer(SecurityTestUtil.NOTAUTHZ_EXCEPTION) ));
+ // Gets as normal user should throw exception
+ client2.invoke(() -> doGets(2, NOTAUTHZ_EXCEPTION));
+
+ // Try to connect client2 with reader credentials
+ getCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.GET }, new String[] { regionName }, 5);
+ getJavaProps = cGen.getJavaProperties();
+
+ getLogWriter().info("testDisallowPutsGets: For second client with GET credentials: " + getCredentials);
+
+ createClient2NoException(getJavaProps, authInit, port1, port2, getCredentials);
+
+ // Verify that the gets succeed
+ client2.invoke(() -> doGets(2, NO_EXCEPTION));
+
+ // Verify that the puts throw exception
+ client2.invoke(() -> doNPuts(2, NOTAUTHZ_EXCEPTION));
}
@Test
public void testInvalidAccessor() {
- AuthzCredentialGenerator gen = getXmlAuthzGenerator();
- CredentialGenerator cGen = gen.getCredentialGenerator();
- Properties extraAuthProps = cGen.getSystemProperties();
- Properties javaProps = cGen.getJavaProperties();
- Properties extraAuthzProps = gen.getSystemProperties();
- String authenticator = cGen.getAuthenticator();
- String authInit = cGen.getAuthInit();
- String accessor = gen.getAuthorizationCallback();
-
- LogWriterUtils.getLogWriter().info("testInvalidAccessor: Using authinit: " + authInit);
- LogWriterUtils.getLogWriter().info(
- "testInvalidAccessor: Using authenticator: " + authenticator);
-
- // Start server1 with invalid accessor
- Properties serverProps = buildProperties(authenticator,
- "com.gemstone.none", false, extraAuthProps, extraAuthzProps);
- Integer port1 = createServer1(javaProps, serverProps);
- Integer port2 = new Integer(AvailablePort
- .getRandomAvailablePort(AvailablePort.SOCKET));
-
- // Client creation should throw exceptions
- Properties createCredentials = gen.getAllowedCredentials(
- new OperationCode[] { OperationCode.PUT },
- new String[] { regionName }, 3);
- Properties createJavaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testInvalidAccessor: For first client CREATE credentials: "
- + createCredentials);
- Properties getCredentials = gen.getAllowedCredentials(
- new OperationCode[] { OperationCode.GET },
- new String[] { regionName }, 7);
- Properties getJavaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testInvalidAccessor: For second client GET credentials: "
- + getCredentials);
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient( authInit, createCredentials, createJavaProps, port1,
- port2, 0, Boolean.FALSE, Boolean.FALSE,
- Integer.valueOf(SecurityTestUtil.NO_EXCEPTION) ));
- client1.invoke(() -> SecurityTestUtil.doPuts(
- new Integer(1), new Integer(SecurityTestUtil.AUTHFAIL_EXCEPTION) ));
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient( authInit, getCredentials, getJavaProps, port1, port2,
- 0, Boolean.FALSE, Boolean.FALSE,
- Integer.valueOf(SecurityTestUtil.NO_EXCEPTION) ));
- client2.invoke(() -> SecurityTestUtil.doPuts(
- new Integer(1), new Integer(SecurityTestUtil.AUTHFAIL_EXCEPTION) ));
-
- // Now start server2 that has valid accessor
- LogWriterUtils.getLogWriter().info("testInvalidAccessor: Using accessor: " + accessor);
- serverProps = buildProperties(authenticator, accessor, false,
- extraAuthProps, extraAuthzProps);
- createServer2(javaProps, serverProps, port2);
- server1.invoke(() -> SecurityTestUtil.closeCache());
-
- createClient1NoException(createJavaProps, authInit, port1, port2,
- createCredentials);
- createClient2NoException(getJavaProps, authInit, port1, port2,
- getCredentials);
-
- // Now perform some put operations from client1
- client1.invoke(() -> SecurityTestUtil.doPuts(
- new Integer(4), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
-
- // Verify that the gets succeed
- client2.invoke(() -> SecurityTestUtil.doGets(
- new Integer(4), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
- }
+ AuthzCredentialGenerator gen = getXmlAuthzGenerator();
+ CredentialGenerator cGen = gen.getCredentialGenerator();
+ Properties extraAuthProps = cGen.getSystemProperties();
+ Properties javaProps = cGen.getJavaProperties();
+ Properties extraAuthzProps = gen.getSystemProperties();
+ String authenticator = cGen.getAuthenticator();
+ String authInit = cGen.getAuthInit();
+ String accessor = gen.getAuthorizationCallback();
+
+ getLogWriter().info("testInvalidAccessor: Using authinit: " + authInit);
+ getLogWriter().info("testInvalidAccessor: Using authenticator: " + authenticator);
+
+ // Start server1 with invalid accessor
+ Properties serverProps = buildProperties(authenticator, "com.gemstone.none", false, extraAuthProps, extraAuthzProps);
+
+ int port1 = createServer1(javaProps, serverProps);
+ int port2 = getRandomAvailablePort(SOCKET);
+
+ // Client creation should throw exceptions
+ Properties createCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.PUT }, new String[] { regionName }, 3);
+ Properties createJavaProps = cGen.getJavaProperties();
+
+ getLogWriter().info("testInvalidAccessor: For first client CREATE credentials: " + createCredentials);
+
+ Properties getCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.GET }, new String[] { regionName }, 7);
+ Properties getJavaProps = cGen.getJavaProperties();
- protected void createServer2(Properties javaProps, Properties serverProps,
- Integer port2) {
- server2.invoke(() -> ClientAuthorizationTestBase.createCacheServer( SecurityTestUtil.getLocatorPort(), port2, serverProps,
- javaProps ));
+ getLogWriter().info("testInvalidAccessor: For second client GET credentials: " + getCredentials);
+
+ client1.invoke(() -> ClientAuthenticationUtils.createCacheClient( authInit, createCredentials, createJavaProps, port1, port2, 0, false, false, NO_EXCEPTION));
+ client1.invoke(() -> doPuts(1, AUTHFAIL_EXCEPTION));
+
+ client2.invoke(() -> ClientAuthenticationUtils.createCacheClient( authInit, getCredentials, getJavaProps, port1, port2, 0, false, false, NO_EXCEPTION));
+ client2.invoke(() -> doPuts(1, AUTHFAIL_EXCEPTION));
+
+ // Now start server2 that has valid accessor
+ getLogWriter().info("testInvalidAccessor: Using accessor: " + accessor);
+ serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
+ createServer2(javaProps, serverProps, port2);
+ server1.invoke(() -> closeCache());
+
+ createClient1NoException(createJavaProps, authInit, port1, port2, createCredentials);
+ createClient2NoException(getJavaProps, authInit, port1, port2, getCredentials);
+
+ // Now perform some put operations from client1
+ client1.invoke(() -> doPuts(4, NO_EXCEPTION));
+
+ // Verify that the gets succeed
+ client2.invoke(() -> doGets(4, NO_EXCEPTION));
}
@Test
public void testPutsGetsWithFailover() {
- AuthzCredentialGenerator gen = getXmlAuthzGenerator();
- CredentialGenerator cGen = gen.getCredentialGenerator();
- Properties extraAuthProps = cGen.getSystemProperties();
- Properties javaProps = cGen.getJavaProperties();
- Properties extraAuthzProps = gen.getSystemProperties();
- String authenticator = cGen.getAuthenticator();
- String authInit = cGen.getAuthInit();
- String accessor = gen.getAuthorizationCallback();
-
- LogWriterUtils.getLogWriter().info(
- "testPutsGetsWithFailover: Using authinit: " + authInit);
- LogWriterUtils.getLogWriter().info(
- "testPutsGetsWithFailover: Using authenticator: " + authenticator);
- LogWriterUtils.getLogWriter().info(
- "testPutsGetsWithFailover: Using accessor: " + accessor);
-
- // Start servers with all required properties
- Properties serverProps = buildProperties(authenticator, accessor, false,
- extraAuthProps, extraAuthzProps);
- Integer port1 = createServer1(javaProps, serverProps);
- // Get a port for second server but do not start it
- // This forces the clients to connect to the first server
- Integer port2 = new Integer(AvailablePort
- .getRandomAvailablePort(AvailablePort.SOCKET));
-
- // Start client1 with valid CREATE credentials
- Properties createCredentials = gen.getAllowedCredentials(
- new OperationCode[] { OperationCode.PUT },
- new String[] { regionName }, 1);
- Properties createJavaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testPutsGetsWithFailover: For first client credentials: "
- + createCredentials);
- createClient1NoException(createJavaProps, authInit, port1, port2,
- createCredentials);
-
- // Start client2 with valid GET credentials
- Properties getCredentials = gen.getAllowedCredentials(
- new OperationCode[] { OperationCode.GET },
- new String[] { regionName }, 5);
- Properties getJavaProps = cGen.getJavaProperties();
- LogWriterUtils.getLogWriter().info(
- "testPutsGetsWithFailover: For second client credentials: "
- + getCredentials);
- createClient2NoException(getJavaProps, authInit, port1, port2,
- getCredentials);
-
- // Perform some put operations from client1
- client1.invoke(() -> SecurityTestUtil.doPuts(
- new Integer(2), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
- // Verify that the puts succeeded
- client2.invoke(() -> SecurityTestUtil.doGets(
- new Integer(2), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
-
- createServer2(javaProps, serverProps, port2);
- server1.invoke(() -> SecurityTestUtil.closeCache());
-
- // Perform some put operations from client1
- client1.invoke(() -> SecurityTestUtil.doNPuts(
- new Integer(4), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
- // Verify that the puts succeeded
- client2.invoke(() -> SecurityTestUtil.doNGets(
- new Integer(4), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
-
- // Now re-connect with credentials not allowed to do gets
- Properties noGetCredentials = gen.getDisallowedCredentials(
- new OperationCode[] { OperationCode.GET },
- new String[] { regionName }, 9);
- getJavaProps = cGen.getJavaProperties();
-
- LogWriterUtils.getLogWriter().info(
- "testPutsGetsWithFailover: For second client disallowed GET credentials: "
- + noGetCredentials);
-
- createClient2NoException(getJavaProps, authInit, port1, port2,
- noGetCredentials);
-
- // Perform some put operations from client1
- client1.invoke(() -> SecurityTestUtil.doPuts(
- new Integer(4), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
- // Gets as normal user should throw exception
- client2.invoke(() -> SecurityTestUtil.doGets(
- new Integer(4), new Integer(SecurityTestUtil.NOTAUTHZ_EXCEPTION) ));
-
- // force a failover and do the drill again
- server1.invoke(() -> ClientAuthorizationTestBase.createCacheServer( SecurityTestUtil.getLocatorPort(), port1, serverProps,
- javaProps ));
- server2.invoke(() -> SecurityTestUtil.closeCache());
-
- // Perform some put operations from client1
- client1.invoke(() -> SecurityTestUtil.doNPuts(
- new Integer(4), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
- // Gets as normal user should throw exception
- client2.invoke(() -> SecurityTestUtil.doNGets(
- new Integer(4), new Integer(SecurityTestUtil.NOTAUTHZ_EXCEPTION) ));
-
- createClient2NoException(getJavaProps, authInit, port1, port2,
- getCredentials);
-
- // Verify that the gets succeed
- client2.invoke(() -> SecurityTestUtil.doNGets(
- new Integer(4), new Integer(SecurityTestUtil.NO_EXCEPTION) ));
-
- // Verify that the puts throw exception
- client2.invoke(() -> SecurityTestUtil.doPuts(
- new Integer(4), new Integer(SecurityTestUtil.NOTAUTHZ_EXCEPTION) ));
- }
+ AuthzCredentialGenerator gen = getXmlAuthzGenerator();
+ CredentialGenerator cGen = gen.getCredentialGenerator();
+ Properties extraAuthProps = cGen.getSystemProperties();
+ Properties javaProps = cGen.getJavaProperties();
+ Properties extraAuthzProps = gen.getSystemProperties();
+ String authenticator = cGen.getAuthenticator();
+ String authInit = cGen.getAuthInit();
+ String accessor = gen.getAuthorizationCallback();
- @Test
- public void testUnregisterInterestWithFailover() throws InterruptedException {
+ getLogWriter().info("testPutsGetsWithFailover: Using authinit: " + authInit);
+ getLogWriter().info("testPutsGetsWithFailover: Using authenticator: " + authenticator);
+ getLogWriter().info("testPutsGetsWithFailover: Using accessor: " + accessor);
- OperationWithAction[] unregisterOps = {
- // Register interest in all KEYS using one key at a time
- new OperationWithAction(OperationCode.REGISTER_INTEREST,
- OperationCode.UNREGISTER_INTEREST, 3, OpFlags.NONE, 4),
- new OperationWithAction(OperationCode.REGISTER_INTEREST, 2),
- // UPDATE and test with GET
- new OperationWithAction(OperationCode.PUT),
- new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN
- | OpFlags.LOCAL_OP, 4),
+ // Start servers with all required properties
+ Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
- // Unregister interest in all KEYS using one key at a time
- new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 3,
- OpFlags.USE_OLDCONN | OpFlags.CHECK_NOTAUTHZ, 4),
- new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 2,
- OpFlags.USE_OLDCONN, 4),
- // UPDATE and test with GET for no updates
- new OperationWithAction(OperationCode.PUT, 1, OpFlags.USE_OLDCONN
- | OpFlags.USE_NEWVAL, 4),
- new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN
- | OpFlags.LOCAL_OP, 4),
+ int port1 = createServer1(javaProps, serverProps);
- OperationWithAction.OPBLOCK_END,
+ // Get a port for second server but do not start it. This forces the clients to connect to the first server
+ int port2 = getRandomAvailablePort(SOCKET);
- // Register interest in all KEYS using list
- new OperationWithAction(OperationCode.REGISTER_INTEREST,
- OperationCode.UNREGISTER_INTEREST, 3, OpFlags.USE_LIST, 4),
- new OperationWithAction(OperationCode.REGISTER_INTEREST, 1,
- OpFlags.USE_LIST, 4),
- // UPDATE and test with GET
- new OperationWithAction(OperationCode.PUT, 2),
- new OperationWithAction(OperationCode.GET, 1, OpFlags.USE_OLDCONN
- | OpFlags.LOCAL_OP, 4),
+ // Start client1 with valid CREATE credentials
+ Properties createCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.PUT }, new String[] { regionName }, 1);
+ Properties createJavaProps = cGen.getJavaProperties();
- // Unregister interest in all KEYS using list
- new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 3,
- OpFlags.USE_OLDCONN | OpFlags.USE_LIST | OpFlags.CHECK_NOTAUTHZ, 4),
- new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 1,
- OpFlags.USE_OLDCONN | OpFlags.USE_LIST, 4),
- // UPDATE and test with GET for no updates
- new OperationWithAction(OperationCode.PUT, 2, OpFlags.USE_OLDCONN
- | OpFlags.USE_NEWVAL, 4),
- new OperationWithAction(OperationCode.GET, 1, OpFlags.USE_OLDCONN
- | OpFlags.LOCAL_OP, 4),
+ getLogWriter().info("testPutsGetsWithFailover: For first client credentials: " + createCredentials);
- OperationWithAction.OPBLOCK_END,
+ createClient1NoException(createJavaProps, authInit, port1, port2, createCredentials);
- // Register interest in all KEYS using regular expression
- new OperationWithAction(OperationCode.REGISTER_INTEREST,
- OperationCode.UNREGISTER_INTEREST, 3, OpFlags.USE_REGEX, 4),
- new OperationWithAction(OperationCode.REGISTER_INTEREST, 2,
- OpFlags.USE_REGEX, 4),
- // UPDATE and test with GET
- new OperationWithAction(OperationCode.PUT),
- new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN
- | OpFlags.LOCAL_OP, 4),
+ // Start client2 with valid GET credentials
+ Properties getCredentials = gen.getAllowedCredentials(new OperationCode[] { OperationCode.GET }, new String[] { regionName }, 5);
+ Properties getJavaProps = cGen.getJavaProperties();
- // Unregister interest in all KEYS using regular expression
- new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 3,
- OpFlags.USE_OLDCONN | OpFlags.USE_REGEX | OpFlags.CHECK_NOTAUTHZ, 4),
- new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 2,
- OpFlags.USE_OLDCONN | OpFlags.USE_REGEX, 4),
- // UPDATE and test with GET for no updates
- new OperationWithAction(OperationCode.PUT, 1, OpFlags.USE_OLDCONN
- | OpFlags.USE_NEWVAL, 4),
- new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN
- | OpFlags.LOCAL_OP, 4),
+ getLogWriter().info("testPutsGetsWithFailover: For second client credentials: " + getCredentials);
- OperationWithAction.OPBLOCK_END };
+ createClient2NoException(getJavaProps, authInit, port1, port2, getCredentials);
+
+ // Perform some put operations from client1
+ client1.invoke(() -> doPuts(2, NO_EXCEPTION));
+
+ // Verify that the puts succeeded
+ client2.invoke(() -> doGets(2, NO_EXCEPTION));
+
+ createServer2(javaProps, serverProps, port2);
+ server1.invoke(() -> closeCache());
+
+ // Perform some put operations from client1
+ client1.invoke(() -> doNPuts(4, NO_EXCEPTION));
+
+ // Verify that the puts succeeded
+ client2.invoke(() -> doNGets(4, NO_EXCEPTION));
+
+ // Now re-connect with credentials not allowed to do gets
+ Properties noGetCredentials = gen.getDisallowedCredentials(new OperationCode[] { OperationCode.GET }, new String[] { regionName }, 9);
+ getJavaProps = cGen.getJavaProperties();
+
+ getLogWriter().info("testPutsGetsWithFailover: For second client disallowed GET credentials: " + noGetCredentials);
+
+ createClient2NoException(getJavaProps, authInit, port1, port2, noGetCredentials);
+
+ // Perform some put operations from client1
+ client1.invoke(() -> doPuts(4, NO_EXCEPTION));
+
+ // Gets as normal user should throw exception
+ client2.invoke(() -> doGets(4, NOTAUTHZ_EXCEPTION));
+
+ // force a failover and do the drill again
+ server1.invoke(() -> ClientAuthorizationTestBase.createCacheServer( getLocatorPort(), port1, serverProps, javaProps ));
+ server2.invoke(() -> closeCache());
+
+ // Perform some put operations from client1
+ client1.invoke(() -> doNPuts(4, NO_EXCEPTION));
+
+ // Gets as normal user should throw exception
+ client2.invoke(() -> doNGets(4, NOTAUTHZ_EXCEPTION));
+
+ createClient2NoException(getJavaProps, authInit, port1, port2, getCredentials);
+
+ // Verify that the gets succeed
+ client2.invoke(() -> doNGets(4, NO_EXCEPTION));
+
+ // Verify that the puts throw exception
+ client2.invoke(() -> doPuts(4, NOTAUTHZ_EXCEPTION));
+ }
+
+ @Test
+ public void testUnregisterInterestWithFailover() throws InterruptedException {
+ OperationWithAction[] unregisterOps = unregisterOpsForTestUnregisterInterestWithFailover();
AuthzCredentialGenerator gen = new XmlAuthzCredentialGenerator();
CredentialGenerator cGen = new DummyCredentialGenerator();
@@ -635,48 +347,43 @@ public class ClientAuthorizationDUnitTest extends ClientAuthorizationTestBase {
String authInit = cGen.getAuthInit();
String accessor = gen.getAuthorizationCallback();
- LogWriterUtils.getLogWriter().info("testAllOpsWithFailover: Using authinit: " + authInit);
- LogWriterUtils.getLogWriter().info(
- "testAllOpsWithFailover: Using authenticator: " + authenticator);
- LogWriterUtils.getLogWriter().info("testAllOpsWithFailover: Using accessor: " + accessor);
+ getLogWriter().info("testAllOpsWithFailover: Using authinit: " + authInit);
+ getLogWriter().info("testAllOpsWithFailover: Using authenticator: " + authenticator);
+ getLogWriter().info("testAllOpsWithFailover: Using accessor: " + accessor);
// Start servers with all required properties
- Properties serverProps = buildProperties(authenticator, accessor, false,
- extraAuthProps, extraAuthzProps);
+ Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
+
// Get ports for the servers
- Integer port1 = new Integer(AvailablePort
- .getRandomAvailablePort(AvailablePort.SOCKET));
- Integer port2 = new Integer(AvailablePort
- .getRandomAvailablePort(AvailablePort.SOCKET));
+ int port1 = getRandomAvailablePort(SOCKET);
+ int port2 = getRandomAvailablePort(SOCKET);
// Perform all the ops on the clients
List opBlock = new ArrayList();
for (int opNum = 0; opNum < unregisterOps.length; ++opNum) {
- // Start client with valid credentials as specified in
- // OperationWithAction
+
+ // Start client with valid credentials as specified in OperationWithAction
OperationWithAction currentOp = unregisterOps[opNum];
- if (currentOp.equals(OperationWithAction.OPBLOCK_END)
- || currentOp.equals(OperationWithAction.OPBLOCK_NO_FAILOVER)) {
- // End of current operation block; execute all the operations
- // on the servers with/without failover
+ if (currentOp.equals(OperationWithAction.OPBLOCK_END) || currentOp.equals(OperationWithAction.OPBLOCK_NO_FAILOVER)) {
+
+ // End of current operation block; execute all the operations on the servers with/without failover
if (opBlock.size() > 0) {
// Start the first server and execute the operation block
- server1.invoke(() -> ClientAuthorizationTestBase.createCacheServer(
- SecurityTestUtil.getLocatorPort(), port1, serverProps,
- javaProps ));
- server2.invoke(() -> SecurityTestUtil.closeCache());
- executeRIOpBlock(opBlock, port1, port2, authInit, extraAuthProps,
- extraAuthzProps, javaProps);
+ server1.invoke(() -> ClientAuthorizationTestBase.createCacheServer(getLocatorPort(), port1, serverProps, javaProps));
+ server2.invoke(() -> closeCache());
+
+ executeRIOpBlock(opBlock, port1, port2, authInit, extraAuthProps, extraAuthzProps, javaProps);
+
if (!currentOp.equals(OperationWithAction.OPBLOCK_NO_FAILOVER)) {
createServer2(javaProps, serverProps, port2);
- server1.invoke(() -> SecurityTestUtil.closeCache());
- executeRIOpBlock(opBlock, port1, port2, authInit, extraAuthProps,
- extraAuthzProps, javaProps);
+ server1.invoke(() -> closeCache());
+
+ executeRIOpBlock(opBlock, port1, port2, authInit, extraAuthProps, extraAuthzProps, javaProps);
}
opBlock.clear();
}
- }
- else {
+
+ } else {
currentOp.setOpNum(opNum);
opBlock.add(currentOp);
}
@@ -685,104 +392,255 @@ public class ClientAuthorizationDUnitTest extends ClientAuthorizationTestBase {
@Test
public void testAllOpsWithFailover() throws InterruptedException {
- IgnoredException.addIgnoredException("Read timed out");
+ addIgnoredException("Read timed out");
+ runOpsWithFailover(allOpsForAllOpsWithFailover(), "testAllOpsWithFailover");
+ }
+
+ private OperationWithAction[] unregisterOpsForTestUnregisterInterestWithFailover() {
+ return new OperationWithAction[] {
+ // Register interest in all KEYS using one key at a time
+ new OperationWithAction(OperationCode.REGISTER_INTEREST, OperationCode.UNREGISTER_INTEREST, 3, OpFlags.NONE, 4),
+ new OperationWithAction(OperationCode.REGISTER_INTEREST, 2),
+ // UPDATE and test with GET
+ new OperationWithAction(OperationCode.PUT),
+ new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN | OpFlags.LOCAL_OP, 4),
+
+ // Unregister interest in all KEYS using one key at a time
+ new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 3, OpFlags.USE_OLDCONN | OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 2, OpFlags.USE_OLDCONN, 4),
+ // UPDATE and test with GET for no updates
+ new OperationWithAction(OperationCode.PUT, 1, OpFlags.USE_OLDCONN | OpFlags.USE_NEWVAL, 4),
+ new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN | OpFlags.LOCAL_OP, 4),
+
+ OperationWithAction.OPBLOCK_END,
- OperationWithAction[] allOps = {
+ // Register interest in all KEYS using list
+ new OperationWithAction(OperationCode.REGISTER_INTEREST, OperationCode.UNREGISTER_INTEREST, 3, OpFlags.USE_LIST, 4),
+ new OperationWithAction(OperationCode.REGISTER_INTEREST, 1, OpFlags.USE_LIST, 4),
+ // UPDATE and test with GET
+ new OperationWithAction(OperationCode.PUT, 2),
+ new OperationWithAction(OperationCode.GET, 1, OpFlags.USE_OLDCONN | OpFlags.LOCAL_OP, 4),
+
+ // Unregister interest in all KEYS using list
+ new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 3, OpFlags.USE_OLDCONN | OpFlags.USE_LIST | OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 1, OpFlags.USE_OLDCONN | OpFlags.USE_LIST, 4),
+ // UPDATE and test with GET for no updates
+ new OperationWithAction(OperationCode.PUT, 2, OpFlags.USE_OLDCONN | OpFlags.USE_NEWVAL, 4),
+ new OperationWithAction(OperationCode.GET, 1, OpFlags.USE_OLDCONN | OpFlags.LOCAL_OP, 4),
+
+ OperationWithAction.OPBLOCK_END,
+
+ // Register interest in all KEYS using regular expression
+ new OperationWithAction(OperationCode.REGISTER_INTEREST, OperationCode.UNREGISTER_INTEREST, 3, OpFlags.USE_REGEX, 4),
+ new OperationWithAction(OperationCode.REGISTER_INTEREST, 2, OpFlags.USE_REGEX, 4),
+ // UPDATE and test with GET
+ new OperationWithAction(OperationCode.PUT),
+ new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN | OpFlags.LOCAL_OP, 4),
+
+ // Unregister interest in all KEYS using regular expression
+ new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 3, OpFlags.USE_OLDCONN | OpFlags.USE_REGEX | OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 2, OpFlags.USE_OLDCONN | OpFlags.USE_REGEX, 4),
+ // UPDATE and test with GET for no updates
+ new OperationWithAction(OperationCode.PUT, 1, OpFlags.USE_OLDCONN | OpFlags.USE_NEWVAL, 4),
+ new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN | OpFlags.LOCAL_OP, 4),
+
+ OperationWithAction.OPBLOCK_END
+ };
+ }
+
+ private OperationWithAction[] allOpsForAllOpsWithFailover() {
+ return new OperationWithAction[] {
// Test CREATE and verify with a GET
new OperationWithAction(OperationCode.PUT, 3, OpFlags.CHECK_NOTAUTHZ, 4),
new OperationWithAction(OperationCode.PUT),
- new OperationWithAction(OperationCode.GET, 3, OpFlags.CHECK_NOKEY
- | OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.GET, 3, OpFlags.CHECK_NOKEY | OpFlags.CHECK_NOTAUTHZ, 4),
new OperationWithAction(OperationCode.GET, 2, OpFlags.CHECK_NOKEY, 4),
- // OPBLOCK_END indicates end of an operation block; the above block of
- // three operations will be first executed on server1 and then on
- // server2 after failover
+ // OPBLOCK_END indicates end of an operation block; the above block of three operations will be first executed on server1 and then on server2 after failover
OperationWithAction.OPBLOCK_END,
// Test PUTALL and verify with GETs
- new OperationWithAction(OperationCode.PUTALL, 3, OpFlags.USE_NEWVAL
- | OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.PUTALL, 3, OpFlags.USE_NEWVAL | OpFlags.CHECK_NOTAUTHZ, 4),
new OperationWithAction(OperationCode.PUTALL, 1, OpFlags.USE_NEWVAL, 4),
- new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN
- | OpFlags.USE_NEWVAL, 4),
+ new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN | OpFlags.USE_NEWVAL, 4),
OperationWithAction.OPBLOCK_END,
-
+
// Test UPDATE and verify with a GET
- new OperationWithAction(OperationCode.PUT, 3, OpFlags.USE_NEWVAL
- | OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.PUT, 3, OpFlags.USE_NEWVAL | OpFlags.CHECK_NOTAUTHZ, 4),
new OperationWithAction(OperationCode.PUT, 1, OpFlags.USE_NEWVAL, 4),
- new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN
- | OpFlags.USE_NEWVAL, 4),
+ new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN | OpFlags.USE_NEWVAL, 4),
OperationWithAction.OPBLOCK_END,
// Test DESTROY and verify with a GET and that key should not exist
- new OperationWithAction(OperationCode.DESTROY, 3, OpFlags.USE_NEWVAL
- | OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.DESTROY, 3, OpFlags.USE_NEWVAL | OpFlags.CHECK_NOTAUTHZ, 4),
new OperationWithAction(OperationCode.DESTROY),
- new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN
- | OpFlags.CHECK_FAIL, 4), // bruce: added check_nokey because we now bring tombstones to the client in 8.0
+ new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN | OpFlags.CHECK_FAIL, 4), // bruce: added check_nokey because we now bring tombstones to the client in 8.0
// Repopulate the region
new OperationWithAction(OperationCode.PUT, 1, OpFlags.USE_NEWVAL, 4),
OperationWithAction.OPBLOCK_END,
// Check CONTAINS_KEY
- new OperationWithAction(OperationCode.CONTAINS_KEY, 3,
- OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.CONTAINS_KEY, 3, OpFlags.CHECK_NOTAUTHZ, 4),
new OperationWithAction(OperationCode.CONTAINS_KEY),
// Destroy the KEYS and check for failure in CONTAINS_KEY
new OperationWithAction(OperationCode.DESTROY, 2),
- new OperationWithAction(OperationCode.CONTAINS_KEY, 3,
- OpFlags.CHECK_FAIL | OpFlags.CHECK_NOTAUTHZ, 4),
- new OperationWithAction(OperationCode.CONTAINS_KEY, 1,
- OpFlags.USE_OLDCONN | OpFlags.CHECK_FAIL, 4),
+ new OperationWithAction(OperationCode.CONTAINS_KEY, 3, OpFlags.CHECK_FAIL | OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.CONTAINS_KEY, 1, OpFlags.USE_OLDCONN | OpFlags.CHECK_FAIL, 4),
// Repopulate the region
new OperationWithAction(OperationCode.PUT),
OperationWithAction.OPBLOCK_END,
// Check KEY_SET
- new OperationWithAction(OperationCode.KEY_SET, 3,
- OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.KEY_SET, 3, OpFlags.CHECK_NOTAUTHZ, 4),
new OperationWithAction(OperationCode.KEY_SET, 2),
OperationWithAction.OPBLOCK_END,
// Check QUERY
- new OperationWithAction(OperationCode.QUERY, 3, OpFlags.CHECK_NOTAUTHZ,
- 4),
+ new OperationWithAction(OperationCode.QUERY, 3, OpFlags.CHECK_NOTAUTHZ, 4),
new OperationWithAction(OperationCode.QUERY),
OperationWithAction.OPBLOCK_END,
// Register interest in all KEYS using one key at a time
- new OperationWithAction(OperationCode.REGISTER_INTEREST, 3,
- OpFlags.CHECK_NOTAUTHZ, 4),
+ new OperationWithAction(OperationCode.REGISTER_INTEREST, 3, OpFlags.CHECK_NOTAUTHZ, 4),
new OperationWithAction(OperationCode.REGISTER_INTEREST, 2),
// UPDATE and test with GET
new OperationWithAction(OperationCode.PUT),
- new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN
- | OpFlags.LOCAL_OP, 4),
+ new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN | OpFlags.LOCAL_OP, 4),
// Unregister interest in all KEYS using one key at a time
- new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 2,
- OpFlags.USE_OLDCONN, 4),
+ new OperationWithAction(OperationCode.UNREGISTER_INTEREST, 2, OpFlags.USE_OLDCONN, 4),
// UPDATE and test with GET for no updates
- new OperationWithAction(OperationCode.PUT, 1, OpFlags.USE_OLDCONN
- | OpFlags.USE_NEWVAL, 4),
- new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN
- | OpFlags.LOCAL_OP, 4),
+ new OperationWithAction(OperationCode.PUT, 1, OpFlags.USE_OLDCONN | OpFlags.USE_NEWVAL, 4),
+ new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_OLDCONN | OpFlags.LOCAL_OP, 4),
OperationWithAction.OPBLOCK_END,
// Test GET_ENTRY inside a TX, see #49951
- new OperationWithAction(OperationCode.GET, 2,
- OpFlags.USE_GET_ENTRY_IN_TX | OpFlags.CHECK_FAIL, 4),
+ new OperationWithAction(OperationCode.GET, 2, OpFlags.USE_GET_ENTRY_IN_TX | OpFlags.CHECK_FAIL, 4),
OperationWithAction.OPBLOCK_END };
+ }
+
+ private Properties getUserPassword(final String userName) {
+ Properties props = new Properties();
+ props.setProperty(UserPasswordAuthInit.USER_NAME, userName);
+ props.setProperty(UserPasswordAuthInit.PASSWORD, userName);
+ return props;
+ }
+
+ private void executeRIOpBlock(final List<OperationWithAction> opBlock, final int port1, final int port2, final String authInit, final Properties extraAuthProps, final Properties extraAuthzProps, final Properties javaProps) throws InterruptedException {
+ for (Iterator opIter = opBlock.iterator(); opIter.hasNext();) {
+ // Start client with valid credentials as specified in OperationWithAction
+ OperationWithAction currentOp = (OperationWithAction)opIter.next();
+ OperationCode opCode = currentOp.getOperationCode();
+ int opFlags = currentOp.getFlags();
+ int clientNum = currentOp.getClientNum();
+ VM clientVM = null;
+ boolean useThisVM = false;
+
+ switch (clientNum) {
+ case 1:
+ clientVM = client1;
+ break;
+ case 2:
+ clientVM = client2;
+ break;
+ case 3:
+ useThisVM = true;
+ break;
+ default:
+ fail("executeRIOpBlock: Unknown client number " + clientNum);
+ break;
+ }
+
+ getLogWriter().info( "executeRIOpBlock: performing operation number [" + currentOp.getOpNum() + "]: " + currentOp);
+ if ((opFlags & OpFlags.USE_OLDCONN) == 0) {
+ Properties opCredentials = null;
+ String currentRegionName = '/' + regionName;
+ if ((opFlags & OpFlags.USE_SUBREGION) > 0) {
+ currentRegionName += ('/' + subregionName);
+ }
+ String credentialsTypeStr;
+ OperationCode authOpCode = currentOp.getAuthzOperationCode();
+
+ if ((opFlags & OpFlags.CHECK_NOTAUTHZ) > 0 || (opFlags & OpFlags.USE_NOTAUTHZ) > 0 || !authOpCode.equals(opCode)) {
+ credentialsTypeStr = " unauthorized " + authOpCode;
+ if (authOpCode.isRegisterInterest()) {
+ opCredentials = getUserPassword("reader7");
+ } else if (authOpCode.isUnregisterInterest()) {
+ opCredentials = getUserPassword("reader6");
+ } else {
+ fail("executeRIOpBlock: cannot determine credentials for" + credentialsTypeStr);
+ }
+
+ } else {
+ credentialsTypeStr = " authorized " + authOpCode;
+ if (authOpCode.isRegisterInterest() || authOpCode.isUnregisterInterest()) {
+ opCredentials = getUserPassword("reader5");
+ } else if (authOpCode.isPut()) {
+ opCredentials = getUserPassword("writer1");
+ } else if (authOpCode.isGet()) {
+ opCredentials = getUserPassword("reader1");
+ } else {
+ fail("executeRIOpBlock: cannot determine credentials for" + credentialsTypeStr);
+ }
+ }
+
+ Properties clientProps = concatProperties(new Properties[] { opCredentials, extraAuthProps, extraAuthzProps });
+
+ // Start the client with valid credentials but allowed or disallowed to perform an operation
+ getLogWriter().info("executeRIOpBlock: For client" + clientNum + credentialsTypeStr + " credentials: " + opCredentials);
+ if (useThisVM) {
+ createCacheClientWithDynamicRegion(authInit, clientProps, javaProps, new int[] { port1, port2 }, 0, false, NO_EXCEPTION);
+ } else {
+ clientVM.invoke(() -> createCacheClient(authInit, clientProps, javaProps, new int[] { port1, port2 }, 0, false, NO_EXCEPTION));
+ }
+
+ }
+
+ int expectedResult;
+ if ((opFlags & OpFlags.CHECK_NOTAUTHZ) > 0) {
+ expectedResult = NOTAUTHZ_EXCEPTION;
+ } else if ((opFlags & OpFlags.CHECK_EXCEPTION) > 0) {
+ expectedResult = OTHER_EXCEPTION;
+ } else {
+ expectedResult = NO_EXCEPTION;
+ }
+
+ // Perform the operation from selected client
+ if (useThisVM) {
+ doOp(new Byte(opCode.toOrdinal()), currentOp.getIndices(), opFlags, expectedResult);
+
+ } else {
+ byte ordinal = opCode.toOrdinal();
+ int[] indices = currentOp.getIndices();
+ clientVM.invoke(() -> ClientAuthorizationTestBase.doOp(ordinal, indices, opFlags, expectedResult));
+ }
+ }
+ }
+
+ private void createClient2NoException(final Properties javaProps, final String authInit, final int port1, final int port2, final Properties getCredentials) {
+ client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, getCredentials, javaProps, port1, port2, 0, NO_EXCEPTION));
+ }
+
+ private void createClient1NoException(final Properties javaProps, final String authInit, final int port1, final int port2, final Properties createCredentials) {
+ client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, createCredentials, javaProps, port1, port2, 0, NO_EXCEPTION));
+ }
+
+ private int createServer2(final Properties javaProps, final Properties serverProps) {
+ return server2.invoke(() -> ClientAuthorizationTestBase.createCacheServer(getLocatorPort(), serverProps, javaProps));
+ }
+
+ private int createServer1(final Properties javaProps, final Properties serverProps) {
+ return server1.invoke(() -> ClientAuthorizationTestBase.createCacheServer(getLocatorPort(), serverProps, javaProps));
+ }
- runOpsWithFailover(allOps, "testAllOpsWithFailover");
+ private void createServer2(Properties javaProps, Properties serverProps, int port2) {
+ server2.invoke(() -> ClientAuthorizationTestBase.createCacheServer(getLocatorPort(), port2, serverProps, javaProps));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationTestBase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationTestBase.java b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationTestBase.java
index c67a823..0f32306 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationTestBase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthorizationTestBase.java
@@ -18,6 +18,7 @@
*/
package com.gemstone.gemfire.security;
+import static com.gemstone.gemfire.internal.AvailablePort.*;
import static com.gemstone.gemfire.security.SecurityTestUtil.*;
import static com.gemstone.gemfire.test.dunit.Assert.*;
import static com.gemstone.gemfire.test.dunit.Host.*;
@@ -53,7 +54,6 @@ import com.gemstone.gemfire.cache.query.QueryService;
import com.gemstone.gemfire.cache.query.SelectResults;
import com.gemstone.gemfire.cache.query.Struct;
import com.gemstone.gemfire.distributed.internal.DistributionConfig;
-import com.gemstone.gemfire.internal.AvailablePort;
import com.gemstone.gemfire.internal.AvailablePort.Keeper;
import com.gemstone.gemfire.internal.cache.AbstractRegionEntry;
import com.gemstone.gemfire.internal.cache.LocalRegion;
@@ -199,14 +199,14 @@ public class ClientAuthorizationTestBase extends JUnit4DistributedTestCase {
protected static Integer createCacheServer(int locatorPort, Properties authProps, Properties javaProps) {
if (locatorPort == 0) {
- locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+ locatorPort = getRandomAvailablePort(SOCKET);
}
return SecurityTestUtil.createCacheServer(authProps, javaProps, locatorPort, null, 0, true, NO_EXCEPTION);
}
protected static int createCacheServer(int locatorPort, int serverPort, Properties authProps, Properties javaProps) {
if (locatorPort == 0) {
- locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+ locatorPort = getRandomAvailablePort(SOCKET);
}
return SecurityTestUtil.createCacheServer(authProps, javaProps, locatorPort, null, serverPort, true, NO_EXCEPTION);
}
@@ -839,10 +839,10 @@ public class ClientAuthorizationTestBase extends JUnit4DistributedTestCase {
Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
// Get ports for the servers
- Keeper locator1PortKeeper = AvailablePort.getRandomAvailablePortKeeper(AvailablePort.SOCKET);
- Keeper locator2PortKeeper = AvailablePort.getRandomAvailablePortKeeper(AvailablePort.SOCKET);
- Keeper port1Keeper = AvailablePort.getRandomAvailablePortKeeper(AvailablePort.SOCKET);
- Keeper port2Keeper = AvailablePort.getRandomAvailablePortKeeper(AvailablePort.SOCKET);
+ Keeper locator1PortKeeper = getRandomAvailablePortKeeper(SOCKET);
+ Keeper locator2PortKeeper = getRandomAvailablePortKeeper(SOCKET);
+ Keeper port1Keeper = getRandomAvailablePortKeeper(SOCKET);
+ Keeper port2Keeper = getRandomAvailablePortKeeper(SOCKET);
int locator1Port = locator1PortKeeper.getPort();
int locator2Port = locator2PortKeeper.getPort();
int port1 = port1Keeper.getPort();
[4/4] incubator-geode git commit: Cleanup
Posted by kl...@apache.org.
Cleanup
Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/c5bc82d4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/c5bc82d4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/c5bc82d4
Branch: refs/heads/feature/GEODE-693
Commit: c5bc82d4854fff867925e1418c5bf9eef9c8fe11
Parents: 4f6a531
Author: Kirk Lund <kl...@apache.org>
Authored: Tue Mar 29 12:12:37 2016 -0700
Committer: Kirk Lund <kl...@apache.org>
Committed: Tue Mar 29 12:12:37 2016 -0700
----------------------------------------------------------------------
.../security/ClientAuthenticationDUnitTest.java | 28 +-
.../ClientAuthenticationPart2DUnitTest.java | 16 +-
.../security/ClientAuthenticationTestCase.java | 186 ++--
.../security/ClientAuthenticationUtils.java | 35 +-
.../security/ClientAuthorizationDUnitTest.java | 1034 ++++++++----------
.../security/ClientAuthorizationTestBase.java | 14 +-
.../security/ClientMultiUserAuthzDUnitTest.java | 424 ++++---
.../DeltaClientAuthorizationDUnitTest.java | 30 +-
.../DeltaClientPostAuthorizationDUnitTest.java | 37 +-
.../security/P2PAuthenticationDUnitTest.java | 57 +-
.../gemfire/security/SecurityTestUtil.java | 312 +++---
.../ClientAuthorizationTwoDUnitTest.java | 3 +-
.../security/ClientAuthzObjectModDUnitTest.java | 8 +-
.../ClientCQPostAuthorizationDUnitTest.java | 16 +-
.../ClientPostAuthorizationDUnitTest.java | 13 +-
.../gemfire/security/MultiuserAPIDUnitTest.java | 33 +-
.../MultiuserDurableCQAuthzDUnitTest.java | 114 +-
17 files changed, 1055 insertions(+), 1305 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationDUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationDUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationDUnitTest.java
index 1744c15..ea83a66 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationDUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationDUnitTest.java
@@ -18,13 +18,6 @@
*/
package com.gemstone.gemfire.security;
-import static com.gemstone.gemfire.security.SecurityTestUtil.*;
-import static com.gemstone.gemfire.test.dunit.Assert.*;
-
-import java.util.Properties;
-
-import com.gemstone.gemfire.cache.Region;
-import com.gemstone.gemfire.distributed.internal.DistributionConfig;
import com.gemstone.gemfire.test.junit.categories.DistributedTest;
import org.junit.Ignore;
import org.junit.Test;
@@ -42,53 +35,52 @@ public class ClientAuthenticationDUnitTest extends ClientAuthenticationTestCase
@Test
public void testValidCredentials() throws Exception {
- doTestValidCredentials(Boolean.FALSE);
+ doTestValidCredentials(false);
}
@Test
public void testNoCredentials() throws Exception {
- doTestNoCredentials(Boolean.FALSE);
+ doTestNoCredentials(false);
}
@Test
public void testInvalidCredentials() throws Exception {
- doTestInvalidCredentials(Boolean.FALSE);
+ doTestInvalidCredentials(false);
}
@Test
public void testInvalidAuthInit() throws Exception {
- doTestInvalidAuthInit(Boolean.FALSE);
+ doTestInvalidAuthInit(false);
}
@Test
public void testNoAuthInitWithCredentials() throws Exception {
- doTestNoAuthInitWithCredentials(Boolean.FALSE);
+ doTestNoAuthInitWithCredentials(false);
}
@Test
public void testInvalidAuthenticator() throws Exception {
- doTestInvalidAuthenticator(Boolean.FALSE);
+ doTestInvalidAuthenticator(false);
}
@Test
public void testNoAuthenticatorWithCredentials() throws Exception {
- doTestNoAuthenticatorWithCredentials(Boolean.FALSE);
+ doTestNoAuthenticatorWithCredentials(false);
}
@Test
public void testCredentialsWithFailover() throws Exception {
- doTestCredentialsWithFailover(Boolean.FALSE);
+ doTestCredentialsWithFailover(false);
}
@Test
public void testCredentialsForNotifications() throws Exception {
- doTestCredentialsForNotifications(Boolean.FALSE);
+ doTestCredentialsForNotifications(false);
}
@Ignore("Disabled for unknown reason")
@Test
public void testValidCredentialsForMultipleUsers() throws Exception {
- doTestValidCredentials(Boolean.TRUE);
+ doTestValidCredentials(true);
}
-
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationPart2DUnitTest.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationPart2DUnitTest.java b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationPart2DUnitTest.java
index 540632a..b633865 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationPart2DUnitTest.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationPart2DUnitTest.java
@@ -32,43 +32,43 @@ public class ClientAuthenticationPart2DUnitTest extends ClientAuthenticationTest
@Test
public void testNoCredentialsForMultipleUsers() throws Exception {
- doTestNoCredentials(Boolean.TRUE);
+ doTestNoCredentials(true);
}
@Test
public void testInvalidCredentialsForMultipleUsers() throws Exception {
- doTestInvalidCredentials(Boolean.TRUE);
+ doTestInvalidCredentials(true);
}
@Test
public void testInvalidAuthInitForMultipleUsers() throws Exception {
- doTestInvalidAuthInit(Boolean.TRUE);
+ doTestInvalidAuthInit(true);
}
@Test
public void testNoAuthInitWithCredentialsForMultipleUsers() throws Exception {
- doTestNoAuthInitWithCredentials(Boolean.TRUE);
+ doTestNoAuthInitWithCredentials(true);
}
@Test
public void testInvalidAuthenitcatorForMultipleUsers() throws Exception {
- doTestInvalidAuthenticator(Boolean.TRUE);
+ doTestInvalidAuthenticator(true);
}
@Test
public void testNoAuthenticatorWithCredentialsForMultipleUsers() throws Exception {
- doTestNoAuthenticatorWithCredentials(Boolean.TRUE);
+ doTestNoAuthenticatorWithCredentials(true);
}
@Ignore("Disabled for unknown reason")
@Test
public void testCredentialsWithFailoverForMultipleUsers() throws Exception {
- doTestCredentialsWithFailover(Boolean.TRUE);
+ doTestCredentialsWithFailover(true);
}
@Ignore("Disabled for unknown reason")
@Test
public void testCredentialsForNotificationsForMultipleUsers() throws Exception {
- doTestCredentialsForNotifications(Boolean.TRUE);
+ doTestCredentialsForNotifications(true);
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationTestCase.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationTestCase.java b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationTestCase.java
index d308769..3c1ab1d 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationTestCase.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationTestCase.java
@@ -16,6 +16,8 @@
*/
package com.gemstone.gemfire.security;
+import static com.gemstone.gemfire.internal.AvailablePort.*;
+import static com.gemstone.gemfire.security.ClientAuthenticationUtils.*;
import static com.gemstone.gemfire.security.SecurityTestUtil.*;
import static com.gemstone.gemfire.test.dunit.IgnoredException.*;
import static com.gemstone.gemfire.test.dunit.LogWriterUtils.*;
@@ -26,7 +28,6 @@ import java.util.Properties;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLHandshakeException;
-import com.gemstone.gemfire.internal.AvailablePort;
import com.gemstone.gemfire.security.generator.CredentialGenerator;
import com.gemstone.gemfire.security.generator.DummyCredentialGenerator;
import com.gemstone.gemfire.test.dunit.Host;
@@ -72,7 +73,7 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
client2.invoke(() -> registerExpectedExceptions(clientIgnoredExceptions));
}
- protected void doTestValidCredentials(boolean multiUser) throws Exception {
+ protected void doTestValidCredentials(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
@@ -84,11 +85,12 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
getLogWriter().info("testValidCredentials: Using authinit: " + authInit);
// Start the servers
- Integer locPort1 = getLocatorPort();
- Integer locPort2 = getLocatorPort();
+ int locPort1 = getLocatorPort();
+ int locPort2 = getLocatorPort();
String locString = getLocatorString();
- Integer port1 = server1.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort1, locString, authenticator, extraProps, javaProps));
- Integer port2 = server2.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort2, locString, authenticator, extraProps, javaProps));
+
+ int port1 = server1.invoke(() -> createCacheServer(locPort1, locString, authenticator, extraProps, javaProps));
+ int port2 = server2.invoke(() -> createCacheServer(locPort2, locString, authenticator, extraProps, javaProps));
// Start the clients with valid credentials
Properties credentials1 = gen.getValidCredentials(1);
@@ -117,7 +119,7 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
}
}
- protected void doTestNoCredentials(boolean multiUser) throws Exception {
+ protected void doTestNoCredentials(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
@@ -129,11 +131,12 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
getLogWriter().info("testNoCredentials: Using authinit: " + authInit);
// Start the servers
- Integer locPort1 = getLocatorPort();
- Integer locPort2 = getLocatorPort();
+ int locPort1 = getLocatorPort();
+ int locPort2 = getLocatorPort();
String locString = getLocatorString();
- Integer port1 = createServer1(extraProps, javaProps, authenticator, locPort1, locString);
- Integer port2 = server2.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort2, locString, authenticator, extraProps, javaProps));
+
+ int port1 = createServer1(extraProps, javaProps, authenticator, locPort1, locString);
+ int port2 = server2.invoke(() -> createCacheServer(locPort2, locString, authenticator, extraProps, javaProps));
// Start first client with valid credentials
Properties credentials1 = gen.getValidCredentials(1);
@@ -151,15 +154,15 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
// For SSL the exception may not come since the server can close socket
// before handshake message is sent from client. However exception
// should come in any region operations.
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, null, null, port1, port2, 0, multiUser, NO_EXCEPTION));
+ client2.invoke(() -> createCacheClient(null, null, null, port1, port2, 0, multiUser, NO_EXCEPTION));
client2.invoke(() -> doPuts(2, OTHER_EXCEPTION));
} else {
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, null, null, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
+ client2.invoke(() -> createCacheClient(null, null, null, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
}
}
- protected void doTestInvalidCredentials(boolean multiUser) throws Exception {
+ protected void doTestInvalidCredentials(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
@@ -171,11 +174,12 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
getLogWriter().info("testInvalidCredentials: Using authinit: " + authInit);
// Start the servers
- Integer locPort1 = getLocatorPort();
- Integer locPort2 = getLocatorPort();
+ int locPort1 = getLocatorPort();
+ int locPort2 = getLocatorPort();
String locString = getLocatorString();
- Integer port1 = createServer1(extraProps, javaProps, authenticator, locPort1, locString);
- Integer port2 = server2.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort2, locString, authenticator, extraProps, javaProps));
+
+ int port1 = createServer1(extraProps, javaProps, authenticator, locPort1, locString);
+ int port2 = server2.invoke(() -> createCacheServer(locPort2, locString, authenticator, extraProps, javaProps));
// Start first client with valid credentials
Properties credentials1 = gen.getValidCredentials(1);
@@ -194,10 +198,10 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
Properties javaProps2 = gen.getJavaProperties();
getLogWriter().info("testInvalidCredentials: For second client credentials: " + credentials2 + " : " + javaProps2);
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, credentials2, javaProps2, port1, port2, 0, multiUser, AUTHFAIL_EXCEPTION));
+ client2.invoke(() -> createCacheClient(authInit, credentials2, javaProps2, port1, port2, 0, multiUser, AUTHFAIL_EXCEPTION));
}
- protected void doTestInvalidAuthInit(boolean multiUser) throws Exception {
+ protected void doTestInvalidAuthInit(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
final Properties javaProps = gen.getJavaProperties();
@@ -207,17 +211,17 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
getLogWriter().info("testInvalidAuthInit: Using authenticator: " + authenticator);
// Start the server
- Integer locPort1 = getLocatorPort();
+ int locPort1 = getLocatorPort();
String locString = getLocatorString();
- Integer port1 = createServer1(extraProps, javaProps, authenticator, locPort1, locString);
+ int port1 = createServer1(extraProps, javaProps, authenticator, locPort1, locString);
Properties credentials = gen.getValidCredentials(1);
-
getLogWriter().info("testInvalidAuthInit: For first client credentials: " + credentials + " : " + javaProps);
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient("com.gemstone.none", credentials, javaProps, new int[] { port1 }, 0, multiUser, AUTHREQ_EXCEPTION));
+
+ client1.invoke(() -> createCacheClient("com.gemstone.none", credentials, javaProps, new int[] { port1 }, 0, false, multiUser, true, AUTHREQ_EXCEPTION));
}
- protected void doTestNoAuthInitWithCredentials(boolean multiUser) throws Exception {
+ protected void doTestNoAuthInitWithCredentials(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
@@ -227,11 +231,12 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
getLogWriter().info("testNoAuthInitWithCredentials: Using authenticator: " + authenticator);
// Start the servers
- Integer locPort1 = getLocatorPort();
- Integer locPort2 = getLocatorPort();
+ int locPort1 = getLocatorPort();
+ int locPort2 = getLocatorPort();
String locString = getLocatorString();
- Integer port1 = createServer1(extraProps, javaProps, authenticator, locPort1, locString);
- Integer port2 = server2.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort2, locString, authenticator, extraProps, javaProps));
+
+ int port1 = createServer1(extraProps, javaProps, authenticator, locPort1, locString);
+ int port2 = server2.invoke(() -> createCacheServer(locPort2, locString, authenticator, extraProps, javaProps));
// Start the clients with valid credentials
Properties credentials1 = gen.getValidCredentials(1);
@@ -242,17 +247,21 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
Properties javaProps2 = gen.getJavaProperties();
getLogWriter().info("testNoAuthInitWithCredentials: For second client credentials: " + credentials2 + " : " + javaProps2);
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, credentials1, javaProps1, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, credentials2, javaProps2, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
+ client1.invoke(() -> createCacheClient(null, credentials1, javaProps1, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
+ client2.invoke(() -> createCacheClient(null, credentials2, javaProps2, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
client2.invoke(() -> closeCache());
// Now also try with invalid credentials
Properties credentials3 = gen.getInvalidCredentials(5);
Properties javaProps3 = gen.getJavaProperties();
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, credentials3, javaProps3, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
+
+ client2.invoke(() -> createCacheClient(null, credentials3, javaProps3, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
}
- protected void doTestInvalidAuthenticator(boolean multiUser) throws Exception {
+ /**
+ * NOTE: "final boolean multiUser" is unused
+ */
+ protected void doTestInvalidAuthenticator(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
@@ -262,26 +271,28 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
getLogWriter().info("testInvalidAuthenticator: Using authinit: " + authInit);
// Start the server with invalid authenticator
- Integer locPort1 = getLocatorPort();
+ int locPort1 = getLocatorPort();
String locString = getLocatorString();
- Integer port1 = server1.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort1, locString, "com.gemstone.gemfire.none", extraProps, javaProps));
+
+ int port1 = server1.invoke(() -> createCacheServer(locPort1, locString, "com.gemstone.gemfire.none", extraProps, javaProps));
// Trying to create the region on client should throw a security exception
Properties credentials2 = gen.getValidCredentials(1);
Properties javaProps2 = gen.getJavaProperties();
getLogWriter().info("testInvalidAuthenticator: For first client credentials: " + credentials2 + " : " + javaProps2);
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, credentials2, javaProps2, port1, 0, AUTHFAIL_EXCEPTION));
+ client1.invoke(() -> createCacheClient(authInit, credentials2, javaProps2, port1, 0, AUTHFAIL_EXCEPTION));
client1.invoke(() -> closeCache());
// Also test with invalid credentials
Properties credentials3 = gen.getInvalidCredentials(1);
Properties javaProps3 = gen.getJavaProperties();
getLogWriter().info("testInvalidAuthenticator: For first client credentials: " + credentials3 + " : " + javaProps3);
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, credentials3, javaProps3, port1, 0, AUTHFAIL_EXCEPTION));
+
+ client1.invoke(() -> createCacheClient(authInit, credentials3, javaProps3, port1, 0, AUTHFAIL_EXCEPTION));
}
- protected void doTestNoAuthenticatorWithCredentials(boolean multiUser) throws Exception {
+ protected void doTestNoAuthenticatorWithCredentials(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
@@ -292,11 +303,12 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
getLogWriter().info("testNoAuthenticatorWithCredentials: Using authinit: " + authInit);
// Start the servers with no authenticator
- Integer locPort1 = getLocatorPort();
- Integer locPort2 = getLocatorPort();
+ int locPort1 = getLocatorPort();
+ int locPort2 = getLocatorPort();
String locString = getLocatorString();
- Integer port1 = server1.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort1, locString, null, extraProps, javaProps));
- Integer port2 = server2.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort2, locString, null, extraProps, javaProps));
+
+ int port1 = server1.invoke(() -> createCacheServer(locPort1, locString, null, extraProps, javaProps));
+ int port2 = server2.invoke(() -> createCacheServer(locPort2, locString, null, extraProps, javaProps));
// Clients should connect successfully and work properly with
// valid/invalid credentials when none are required on the server side
@@ -317,7 +329,7 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
client2.invoke(() -> doGets(2));
}
- protected void doTestCredentialsWithFailover(boolean multiUser) throws Exception {
+ protected void doTestCredentialsWithFailover(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
@@ -329,13 +341,15 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
getLogWriter().info("testCredentialsWithFailover: Using authinit: " + authInit);
// Start the first server
- Integer locPort1 = getLocatorPort();
- Integer locPort2 = getLocatorPort();
+ int locPort1 = getLocatorPort();
+ int locPort2 = getLocatorPort();
String locString = getLocatorString();
- Integer port1 = server1.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort1, locString, authenticator, extraProps, javaProps));
+
+ int port1 = server1.invoke(() -> createCacheServer(locPort1, locString, authenticator, extraProps, javaProps));
+
// Get a port for second server but do not start it
// This forces the clients to connect to the first server
- Integer port2 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+ int port2 = getRandomAvailablePort(SOCKET);
// Start the clients with valid credentials
Properties credentials1 = gen.getValidCredentials(5);
@@ -354,7 +368,7 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
client2.invoke(() -> doGets(2));
// start the second one and stop the first server to force a failover
- server2.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort2, locString, port2, authenticator, extraProps, javaProps));
+ server2.invoke(() -> createCacheServer(locPort2, locString, port2, authenticator, extraProps, javaProps));
server1.invoke(() -> closeCache());
// Perform some create/update operations from client1
@@ -368,11 +382,11 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
// For SSL the exception may not come since the server can close socket
// before handshake message is sent from client. However exception
// should come in any region operations.
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, null, null, port1, port2, 0, multiUser, NOFORCE_AUTHREQ_EXCEPTION));
+ client2.invoke(() -> createCacheClient(null, null, null, port1, port2, 0, multiUser, NOFORCE_AUTHREQ_EXCEPTION));
client2.invoke(() -> doPuts(2, OTHER_EXCEPTION));
} else {
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, null, null, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
+ client2.invoke(() -> createCacheClient(null, null, null, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
}
// Now try to connect client1 with invalid credentials
@@ -381,7 +395,7 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
Properties javaProps3 = gen.getJavaProperties();
getLogWriter().info("testCredentialsWithFailover: For first client invalid credentials: " + credentials3 + " : " + javaProps3);
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, credentials3, javaProps3, port1, port2, 0, multiUser, AUTHFAIL_EXCEPTION));
+ client1.invoke(() -> createCacheClient(authInit, credentials3, javaProps3, port1, port2, 0, multiUser, AUTHFAIL_EXCEPTION));
if (multiUser) {
client1.invoke(() -> doProxyCacheClose());
@@ -391,7 +405,7 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
}
}
- protected void doTestCredentialsForNotifications(boolean multiUser) throws Exception {
+ protected void doTestCredentialsForNotifications(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
@@ -403,13 +417,15 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
getLogWriter().info("testCredentialsForNotifications: Using authinit: " + authInit);
// Start the first server
- Integer locPort1 = getLocatorPort();
- Integer locPort2 = getLocatorPort();
+ int locPort1 = getLocatorPort();
+ int locPort2 = getLocatorPort();
String locString = getLocatorString();
- Integer port1 = server1.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort1, locString, authenticator, extraProps, javaProps));
+
+ int port1 = server1.invoke(() -> createCacheServer(locPort1, locString, authenticator, extraProps, javaProps));
+
// Get a port for second server but do not start it
// This forces the clients to connect to the first server
- Integer port2 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
+ int port2 = getRandomAvailablePort(SOCKET);
// Start the clients with valid credentials
Properties credentials1 = gen.getValidCredentials(3);
@@ -427,7 +443,7 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
createClient2NoException(multiUser, authInit, port1, port2, credentials2, javaProps2, zeroConns);
// Register interest on all keys on second client
- client2.invoke(() -> ClientAuthenticationUtils.registerAllInterest());
+ client2.invoke(() -> registerAllInterest());
// Perform some put operations from client1
client1.invoke(() -> doPuts(2));
@@ -436,7 +452,7 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
client2.invoke(() -> doLocalGets(2));
// start the second one and stop the first server to force a failover
- server2.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort2, locString, port2, authenticator, extraProps, javaProps));
+ server2.invoke(() -> createCacheServer(locPort2, locString, port2, authenticator, extraProps, javaProps));
server1.invoke(() -> closeCache());
// Wait for failover to complete
@@ -449,17 +465,17 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
// Try to connect client1 with no credentials
// Verify that the creation of region throws security exception
- server1.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort1, locString, port1, authenticator, extraProps, javaProps));
+ server1.invoke(() -> createCacheServer(locPort1, locString, port1, authenticator, extraProps, javaProps));
if (gen.classCode().equals(CredentialGenerator.ClassCode.SSL)) {
// For SSL the exception may not come since the server can close socket
// before handshake message is sent from client. However exception
// should come in any region operations.
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, null, null, port1, port2, zeroConns, multiUser, NOFORCE_AUTHREQ_EXCEPTION));
+ client1.invoke(() -> createCacheClient(null, null, null, port1, port2, zeroConns, multiUser, NOFORCE_AUTHREQ_EXCEPTION));
client1.invoke(() -> doPuts(2, OTHER_EXCEPTION));
} else {
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, null, null, port1, port2, zeroConns, multiUser, AUTHREQ_EXCEPTION));
+ client1.invoke(() -> createCacheClient(null, null, null, port1, port2, zeroConns, multiUser, AUTHREQ_EXCEPTION));
}
// Now try to connect client2 with invalid credentials
@@ -473,15 +489,15 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
// Now try to connect client2 with invalid auth-init method
// Trying to create the region on client with valid credentials should
// throw a security exception
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient("com.gemstone.none", credentials1, javaProps1, port1, port2, zeroConns, multiUser, AUTHREQ_EXCEPTION));
+ client2.invoke(() -> createCacheClient("com.gemstone.none", credentials1, javaProps1, port1, port2, zeroConns, multiUser, AUTHREQ_EXCEPTION));
// Now start the servers with invalid authenticator method.
// Skip this test for a scheme which does not have an authInit in the
// first place (e.g. SSL) since that will fail with AuthReqEx before
// authenticator is even invoked.
if (authInit != null && authInit.length() > 0) {
- server1.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort1, locString, port1, "com.gemstone.gemfire.none", extraProps, javaProps));
- server2.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort2, locString, port2, "com.gemstone.gemfire.none", extraProps, javaProps));
+ server1.invoke(() -> createCacheServer(locPort1, locString, port1, "com.gemstone.gemfire.none", extraProps, javaProps));
+ server2.invoke(() -> createCacheServer(locPort2, locString, port2, "com.gemstone.gemfire.none", extraProps, javaProps));
createClient2WithException(multiUser, authInit, port1, port2, credentials1, javaProps1, zeroConns);
createClient1WithException(multiUser, authInit, port1, port2, credentials2, javaProps2, zeroConns);
@@ -494,9 +510,9 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
// Skip this test for a scheme which does not have an authInit in the
// first place (e.g. SSL).
if (authInit != null && authInit.length() > 0) {
- server1.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort1, locString, port1, authenticator, extraProps, javaProps));
- server2.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort2, locString, port2, authenticator, extraProps, javaProps));
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, credentials1, javaProps1, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
+ server1.invoke(() -> createCacheServer(locPort1, locString, port1, authenticator, extraProps, javaProps));
+ server2.invoke(() -> createCacheServer(locPort2, locString, port2, authenticator, extraProps, javaProps));
+ client1.invoke(() -> createCacheClient(null, credentials1, javaProps1, port1, port2, 0, multiUser, AUTHREQ_EXCEPTION));
createClient2AuthReqException(multiUser, port1, port2, credentials2, javaProps2, zeroConns);
createClient2AuthReqException(multiUser, port1, port2, credentials2, javaProps2, zeroConns);
@@ -510,14 +526,14 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
// If the scheme does not have an authenticator in the first place (e.g.
// SSL) then skip it since this test is useless.
if (authenticator != null && authenticator.length() > 0) {
- server1.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort1, locString, port1, null, extraProps, javaProps));
- server2.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort2, locString, port2, null, extraProps, javaProps));
+ server1.invoke(() -> createCacheServer(locPort1, locString, port1, null, extraProps, javaProps));
+ server2.invoke(() -> createCacheServer(locPort2, locString, port2, null, extraProps, javaProps));
createClient1NoException(multiUser, authInit, port1, port2, credentials1, javaProps1);
createClient2NoException(multiUser, authInit, port1, port2, credentials2, javaProps2, zeroConns);
// Register interest on all keys on second client
- client2.invoke(() -> ClientAuthenticationUtils.registerAllInterest());
+ client2.invoke(() -> registerAllInterest());
// Perform some put operations from client1
client1.invoke(() -> doPuts(4));
@@ -530,7 +546,7 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
createClient2NoException(multiUser, authInit, port1, port2, credentials1, javaProps1, zeroConns);
// Register interest on all keys on second client
- client2.invoke(() -> ClientAuthenticationUtils.registerAllInterest());
+ client2.invoke(() -> registerAllInterest());
// Perform some put operations from client1
client1.invoke(() -> doNPuts(4));
@@ -543,32 +559,32 @@ public abstract class ClientAuthenticationTestCase extends JUnit4DistributedTest
}
}
- private Integer createServer1(Properties extraProps, Properties javaProps, String authenticator, int locPort1, String locString) {
- return server1.invoke(() -> ClientAuthenticationUtils.createCacheServer(locPort1, locString, authenticator, extraProps, javaProps));
+ private int createServer1(final Properties extraProps, final Properties javaProps, final String authenticator, final int locPort1, final String locString) {
+ return server1.invoke(() -> createCacheServer(locPort1, locString, authenticator, extraProps, javaProps));
}
- private void createClient1NoException(boolean multiUser, String authInit, int port1, int port2, Properties credentials2, Properties javaProps2) {
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, credentials2, javaProps2, port1, port2, 0, multiUser, NO_EXCEPTION));
+ private void createClient1NoException(final boolean multiUser, final String authInit, final int port1, final int port2, final Properties credentials2, final Properties javaProps2) {
+ client1.invoke(() -> createCacheClient(authInit, credentials2, javaProps2, port1, port2, 0, multiUser, NO_EXCEPTION));
}
- private void createClient2AuthReqException(boolean multiUser, int port1, int port2, Properties credentials2, Properties javaProps2, int zeroConns) {
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(null, credentials2, javaProps2, port1, port2, zeroConns, multiUser, AUTHREQ_EXCEPTION));
+ private void createClient2AuthReqException(final boolean multiUser, final int port1, final int port2, final Properties credentials2, final Properties javaProps2, final int zeroConns) {
+ client2.invoke(() -> createCacheClient(null, credentials2, javaProps2, port1, port2, zeroConns, multiUser, AUTHREQ_EXCEPTION));
}
- private void createClient1WithException(boolean multiUser, String authInit, int port1, int port2, Properties credentials2, Properties javaProps2, int zeroConns) {
- client1.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, credentials2, javaProps2, port1, port2, zeroConns, multiUser, AUTHFAIL_EXCEPTION));
+ private void createClient1WithException(final boolean multiUser, final String authInit, final int port1, final int port2, final Properties credentials2, final Properties javaProps2, final int zeroConns) {
+ client1.invoke(() -> createCacheClient(authInit, credentials2, javaProps2, port1, port2, zeroConns, multiUser, AUTHFAIL_EXCEPTION));
}
- private void createClient2WithException(boolean multiUser, String authInit, int port1, int port2, Properties credentials2, Properties javaProps2, int zeroConns) {
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, credentials2, javaProps2, port1, port2, zeroConns, multiUser, AUTHFAIL_EXCEPTION));
+ private void createClient2WithException(final boolean multiUser, final String authInit, final int port1, final int port2, final Properties credentials2, final Properties javaProps2, final int zeroConns) {
+ client2.invoke(() -> createCacheClient(authInit, credentials2, javaProps2, port1, port2, zeroConns, multiUser, AUTHFAIL_EXCEPTION));
}
- private void createClient2NoException(boolean multiUser, String authInit, int port1, int port2, Properties credentials2, Properties javaProps2, int zeroConns) {
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, credentials2, javaProps2, port1, port2, zeroConns, multiUser, NO_EXCEPTION));
+ private void createClient2NoException(final boolean multiUser, final String authInit, final int port1, final int port2, final Properties credentials2, final Properties javaProps2, final int zeroConns) {
+ client2.invoke(() -> createCacheClient(authInit, credentials2, javaProps2, port1, port2, zeroConns, multiUser, NO_EXCEPTION));
}
- private void createClientsNoException(boolean multiUser, String authInit, int port1, int port2, Properties credentials1, Properties javaProps1, Properties credentials2, Properties javaProps2) {
+ private void createClientsNoException(final boolean multiUser, final String authInit, final int port1, final int port2, final Properties credentials1, final Properties javaProps1, final Properties credentials2, final Properties javaProps2) {
createClient1NoException(multiUser, authInit, port1, port2, credentials1, javaProps1);
- client2.invoke(() -> ClientAuthenticationUtils.createCacheClient(authInit, credentials2, javaProps2, port1, port2, 0, multiUser, NO_EXCEPTION));
+ client2.invoke(() -> createCacheClient(authInit, credentials2, javaProps2, port1, port2, 0, multiUser, NO_EXCEPTION));
}
}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/c5bc82d4/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationUtils.java
----------------------------------------------------------------------
diff --git a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationUtils.java b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationUtils.java
index 09cc2d5..459ab0c 100644
--- a/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationUtils.java
+++ b/geode-core/src/test/java/com/gemstone/gemfire/security/ClientAuthenticationUtils.java
@@ -27,67 +27,66 @@ import com.gemstone.gemfire.distributed.internal.DistributionConfig;
/**
* Extracted from ClientAuthenticationDUnitTest
*/
-public class ClientAuthenticationUtils {
+public abstract class ClientAuthenticationUtils {
protected ClientAuthenticationUtils() {
}
- public static Integer createCacheServer(int dsPort, String locatorString, String authenticator, Properties extraProps, Properties javaProps) {
+ protected static Integer createCacheServer(int dsPort, String locatorString, String authenticator, Properties extraProps, Properties javaProps) {
Properties authProps;
if (extraProps == null) {
authProps = new Properties();
} else {
- authProps = (Properties)extraProps;
+ authProps = extraProps;
}
if (authenticator != null) {
- authProps.setProperty(DistributionConfig.SECURITY_CLIENT_AUTHENTICATOR_NAME, authenticator.toString());
+ authProps.setProperty(DistributionConfig.SECURITY_CLIENT_AUTHENTICATOR_NAME, authenticator);
}
- return SecurityTestUtil.createCacheServer(authProps, javaProps, dsPort, (String)locatorString, 0, NO_EXCEPTION);
+ return SecurityTestUtil.createCacheServer(authProps, javaProps, dsPort, locatorString, 0, NO_EXCEPTION);
}
- public static void createCacheServer(int dsPort, String locatorString, int serverPort, String authenticator, Properties extraProps, Properties javaProps) {
+ protected static void createCacheServer(int dsPort, String locatorString, int serverPort, String authenticator, Properties extraProps, Properties javaProps) {
Properties authProps;
if (extraProps == null) {
authProps = new Properties();
} else {
- authProps = (Properties)extraProps;
+ authProps = extraProps;
}
if (authenticator != null) {
- authProps.setProperty(DistributionConfig.SECURITY_CLIENT_AUTHENTICATOR_NAME, authenticator.toString());
+ authProps.setProperty(DistributionConfig.SECURITY_CLIENT_AUTHENTICATOR_NAME, authenticator);
}
SecurityTestUtil.createCacheServer(authProps, javaProps, dsPort, locatorString, serverPort, NO_EXCEPTION);
}
- public static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int[] ports, int numConnections, boolean multiUserMode, boolean subscriptionEnabled, int expectedResult) {
-
+ protected static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int[] ports, int numConnections, boolean multiUserMode, boolean subscriptionEnabled, int expectedResult) {
SecurityTestUtil.createCacheClient(authInit, authProps, javaProps, ports, numConnections, false, multiUserMode, subscriptionEnabled, expectedResult);
}
- public static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int[] ports, int numConnections, boolean multiUserMode, int expectedResult) {
- createCacheClient(authInit, (Properties)authProps, (Properties)javaProps, ports, numConnections, multiUserMode, true, expectedResult);
+ protected static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int[] ports, int numConnections, boolean multiUserMode, int expectedResult) {
+ createCacheClient(authInit, authProps, javaProps, ports, numConnections, multiUserMode, true, expectedResult);
}
- public static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int port1, int numConnections, int expectedResult) {
+ protected static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int port1, int numConnections, int expectedResult) {
createCacheClient(authInit, authProps, javaProps, new int[] { port1 }, numConnections, Boolean.FALSE, Boolean.TRUE, expectedResult);
}
- public static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int port1, int port2, int numConnections, int expectedResult) {
+ protected static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int port1, int port2, int numConnections, int expectedResult) {
createCacheClient(authInit, authProps, javaProps, port1, port2, numConnections, Boolean.FALSE, expectedResult);
}
- public static void createCacheClient(String authInit, Properties authProps, Properties javaProps, Integer port1, Integer port2, int numConnections, boolean multiUserMode, int expectedResult) {
+ protected static void createCacheClient(String authInit, Properties authProps, Properties javaProps, Integer port1, Integer port2, int numConnections, boolean multiUserMode, int expectedResult) {
createCacheClient(authInit, authProps, javaProps, port1, port2, numConnections, multiUserMode, Boolean.TRUE, expectedResult);
}
- public static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int port1, int port2, int numConnections, boolean multiUserMode, boolean subscriptionEnabled, int expectedResult) {
+ protected static void createCacheClient(String authInit, Properties authProps, Properties javaProps, int port1, int port2, int numConnections, boolean multiUserMode, boolean subscriptionEnabled, int expectedResult) {
createCacheClient(authInit, authProps, javaProps, new int[] { port1, port2 }, numConnections, multiUserMode, subscriptionEnabled, expectedResult);
}
- public static void registerAllInterest() {
- Region region = SecurityTestUtil.getCache().getRegion(SecurityTestUtil.REGION_NAME);
+ protected static void registerAllInterest() {
+ Region region = getCache().getRegion(REGION_NAME);
assertNotNull(region);
region.registerInterestRegex(".*");
}