Search in sources :

Example 6 with CredentialGenerator

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);
        }
    }
}
Also used : Random(java.util.Random) ArrayList(java.util.ArrayList) AuthzCredentialGenerator(org.apache.geode.security.generator.AuthzCredentialGenerator) XmlAuthzCredentialGenerator(org.apache.geode.security.generator.XmlAuthzCredentialGenerator) ArrayList(java.util.ArrayList) List(java.util.List) DummyCredentialGenerator(org.apache.geode.security.generator.DummyCredentialGenerator) AuthzCredentialGenerator(org.apache.geode.security.generator.AuthzCredentialGenerator) XmlAuthzCredentialGenerator(org.apache.geode.security.generator.XmlAuthzCredentialGenerator) CredentialGenerator(org.apache.geode.security.generator.CredentialGenerator) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties)

Example 7 with CredentialGenerator

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());
}
Also used : AuthzCredentialGenerator(org.apache.geode.security.generator.AuthzCredentialGenerator) XmlAuthzCredentialGenerator(org.apache.geode.security.generator.XmlAuthzCredentialGenerator) AuthzCredentialGenerator(org.apache.geode.security.generator.AuthzCredentialGenerator) DummyCredentialGenerator(org.apache.geode.security.generator.DummyCredentialGenerator) XmlAuthzCredentialGenerator(org.apache.geode.security.generator.XmlAuthzCredentialGenerator) CredentialGenerator(org.apache.geode.security.generator.CredentialGenerator) Properties(java.util.Properties) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 8 with CredentialGenerator

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;
}
Also used : ClassCode(org.apache.geode.security.generator.AuthzCredentialGenerator.ClassCode) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) AuthzCredentialGenerator(org.apache.geode.security.generator.AuthzCredentialGenerator) XmlAuthzCredentialGenerator(org.apache.geode.security.generator.XmlAuthzCredentialGenerator) DummyCredentialGenerator(org.apache.geode.security.generator.DummyCredentialGenerator) AuthzCredentialGenerator(org.apache.geode.security.generator.AuthzCredentialGenerator) XmlAuthzCredentialGenerator(org.apache.geode.security.generator.XmlAuthzCredentialGenerator) CredentialGenerator(org.apache.geode.security.generator.CredentialGenerator) DummyCredentialGenerator(org.apache.geode.security.generator.DummyCredentialGenerator)

Example 9 with CredentialGenerator

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));
}
Also used : DummyCredentialGenerator(org.apache.geode.security.generator.DummyCredentialGenerator) CredentialGenerator(org.apache.geode.security.generator.CredentialGenerator) Properties(java.util.Properties) DummyCredentialGenerator(org.apache.geode.security.generator.DummyCredentialGenerator)

Example 10 with CredentialGenerator

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));
}
Also used : DummyCredentialGenerator(org.apache.geode.security.generator.DummyCredentialGenerator) CredentialGenerator(org.apache.geode.security.generator.CredentialGenerator) Properties(java.util.Properties) DummyCredentialGenerator(org.apache.geode.security.generator.DummyCredentialGenerator)

Aggregations

CredentialGenerator (org.apache.geode.security.generator.CredentialGenerator)39 Properties (java.util.Properties)37 DummyCredentialGenerator (org.apache.geode.security.generator.DummyCredentialGenerator)29 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)23 Test (org.junit.Test)23 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)21 AuthzCredentialGenerator (org.apache.geode.security.generator.AuthzCredentialGenerator)20 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)12 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)11 XmlAuthzCredentialGenerator (org.apache.geode.security.generator.XmlAuthzCredentialGenerator)10 ArrayList (java.util.ArrayList)7 Random (java.util.Random)7 OperationCode (org.apache.geode.cache.operations.OperationContext.OperationCode)7 LdapUserCredentialGenerator (org.apache.geode.security.generator.LdapUserCredentialGenerator)7 Category (org.junit.experimental.categories.Category)6 List (java.util.List)5 SecurityTestUtils (org.apache.geode.security.SecurityTestUtils)4 VM (org.apache.geode.test.dunit.VM)4 Host (org.apache.geode.test.dunit.Host)2 Iterator (java.util.Iterator)1