use of org.apache.geode.security.generator.CredentialGenerator in project geode by apache.
the class ClientAuthorizationTestCase method runOpsWithFailOver.
protected void runOpsWithFailOver(final OperationWithAction[] opCodes, final String testName) throws InterruptedException {
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();
TestAuthzCredentialGenerator tgen = new TestAuthzCredentialGenerator(gen);
System.out.println(testName + ": Using authinit: " + authInit);
System.out.println(testName + ": Using authenticator: " + authenticator);
System.out.println(testName + ": Using accessor: " + accessor);
// Start servers with all required properties
Properties serverProps = buildProperties(authenticator, accessor, false, extraAuthProps, extraAuthzProps);
// Get ports for the servers
List<Keeper> randomAvailableTCPPortKeepers = AvailablePortHelper.getRandomAvailableTCPPortKeepers(4);
Keeper locator1PortKeeper = randomAvailableTCPPortKeepers.get(0);
Keeper locator2PortKeeper = randomAvailableTCPPortKeepers.get(1);
Keeper port1Keeper = randomAvailableTCPPortKeepers.get(2);
Keeper port2Keeper = randomAvailableTCPPortKeepers.get(3);
int locator1Port = locator1PortKeeper.getPort();
int locator2Port = locator2PortKeeper.getPort();
int port1 = port1Keeper.getPort();
int port2 = port2Keeper.getPort();
// Perform all the ops on the clients
List opBlock = new ArrayList();
Random rnd = new Random();
for (int opNum = 0; opNum < opCodes.length; ++opNum) {
// Start client with valid credentials as specified in OperationWithAction
OperationWithAction currentOp = opCodes[opNum];
if (currentOp.equals(OperationWithAction.OPBLOCK_END) || currentOp.equals(OperationWithAction.OPBLOCK_NO_FAILOVER)) {
// failover
if (opBlock.size() > 0) {
locator1PortKeeper.release();
port1Keeper.release();
// Start the first server and execute the operation block
server1.invoke("createCacheServer", () -> ClientAuthorizationTestCase.createCacheServer(locator1Port, port1, serverProps, javaProps));
server2.invoke("closeCache", () -> 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
locator2PortKeeper.release();
port2Keeper.release();
server2.invoke("createCacheServer", () -> ClientAuthorizationTestCase.createCacheServer(locator2Port, port2, serverProps, javaProps));
server1.invoke("closeCache", () -> closeCache());
executeOpBlock(opBlock, port1, port2, authInit, extraAuthProps, extraAuthzProps, tgen, rnd);
}
opBlock.clear();
}
} else {
currentOp.setOpNum(opNum);
opBlock.add(currentOp);
}
}
}
use of org.apache.geode.security.generator.CredentialGenerator in project geode by apache.
the class ClientAuthorizationDUnitTest method testPutAllWithSecurity.
@Test
public void testPutAllWithSecurity() {
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("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);
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();
getLogWriter().info("testPutAllWithSecurity: For first client credentials: " + createCredentials);
createClient1NoException(javaProps, authInit, port1, port2, createCredentials);
// Perform some put all operations from client1
client1.invoke(() -> doPutAllP());
}
use of org.apache.geode.security.generator.CredentialGenerator in project geode by apache.
the class ClientAuthorizationTestCase method getDummyGeneratorCombos.
protected List<AuthzCredentialGenerator> getDummyGeneratorCombos() {
List<AuthzCredentialGenerator> generators = new ArrayList<>();
Iterator authzCodeIter = AuthzCredentialGenerator.ClassCode.getAll().iterator();
while (authzCodeIter.hasNext()) {
ClassCode authzClassCode = (ClassCode) authzCodeIter.next();
AuthzCredentialGenerator authzGen = AuthzCredentialGenerator.create(authzClassCode);
if (authzGen != null) {
CredentialGenerator cGen = new DummyCredentialGenerator();
cGen.init();
if (authzGen.init(cGen)) {
generators.add(authzGen);
}
}
}
assertTrue(generators.size() > 0);
return generators;
}
use of org.apache.geode.security.generator.CredentialGenerator in project geode by apache.
the class ClientAuthenticationTestCase method doTestInvalidCredentials.
protected void doTestInvalidCredentials(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
String authenticator = gen.getAuthenticator();
String authInit = gen.getAuthInit();
getLogWriter().info("testInvalidCredentials: Using scheme: " + gen.classCode());
getLogWriter().info("testInvalidCredentials: Using authenticator: " + authenticator);
getLogWriter().info("testInvalidCredentials: Using authinit: " + authInit);
// Start the servers
int locPort1 = getLocatorPort();
int locPort2 = getLocatorPort();
String locString = getAndClearLocatorString();
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);
Properties javaProps1 = gen.getJavaProperties();
getLogWriter().info("testInvalidCredentials: For first client credentials: " + credentials1 + " : " + javaProps1);
createClient1NoException(multiUser, authInit, port1, port2, credentials1, javaProps1);
// Perform some put operations from client1
client1.invoke(() -> doPuts(2));
client1.invoke(() -> verifySizeOnServer(2));
client1.invoke(() -> verifyIsEmptyOnServer(false));
// Start second client with invalid credentials
// Trying to create the region on client2 should throw a security
// exception
Properties credentials2 = gen.getInvalidCredentials(1);
Properties javaProps2 = gen.getJavaProperties();
getLogWriter().info("testInvalidCredentials: For second client credentials: " + credentials2 + " : " + javaProps2);
client2.invoke(() -> createCacheClient(authInit, credentials2, javaProps2, port1, port2, 0, multiUser, AUTHFAIL_EXCEPTION));
}
use of org.apache.geode.security.generator.CredentialGenerator in project geode by apache.
the class ClientAuthenticationTestCase method doTestNoAuthenticatorWithCredentials.
protected void doTestNoAuthenticatorWithCredentials(final boolean multiUser) throws Exception {
CredentialGenerator gen = new DummyCredentialGenerator();
Properties extraProps = gen.getSystemProperties();
Properties javaProps = gen.getJavaProperties();
String authenticator = gen.getAuthenticator();
String authInit = gen.getAuthInit();
getLogWriter().info("testNoAuthenticatorWithCredentials: Using scheme: " + gen.classCode());
getLogWriter().info("testNoAuthenticatorWithCredentials: Using authinit: " + authInit);
// Start the servers with no authenticator
int locPort1 = getLocatorPort();
int locPort2 = getLocatorPort();
String locString = getAndClearLocatorString();
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
Properties credentials1 = gen.getValidCredentials(3);
Properties javaProps1 = gen.getJavaProperties();
getLogWriter().info("testNoAuthenticatorWithCredentials: For first client credentials: " + credentials1 + " : " + javaProps1);
Properties credentials2 = gen.getInvalidCredentials(5);
Properties javaProps2 = gen.getJavaProperties();
getLogWriter().info("testNoAuthenticatorWithCredentials: For second client credentials: " + credentials2 + " : " + javaProps2);
createClientsNoException(multiUser, authInit, port1, port2, credentials1, javaProps1, credentials2, javaProps2);
// Perform some put operations from client1
client1.invoke(() -> doPuts(2));
// Verify that the puts succeeded
client2.invoke(() -> doGets(2));
}
Aggregations