Search in sources :

Example 46 with ChaiProvider

use of com.novell.ldapchai.provider.ChaiProvider in project ldapchai by ldapchai.

the class ChaiTester method testClosedProvider.

public void testClosedProvider() throws Exception {
    final ChaiConfiguration testConfig = new ChaiConfiguration(TestHelper.bindURL, TestHelper.bindDN, TestHelper.bindPW);
    testConfig.setSetting(ChaiSetting.PROMISCUOUS_SSL, "true");
    testConfig.setSetting(ChaiSetting.WATCHDOG_ENABLE, "true");
    testConfig.setSetting(ChaiSetting.STATISTICS_ENABLE, "true");
    testConfig.setSetting(ChaiSetting.FAILOVER_ENABLE, "true");
    final ChaiProvider testProvider = ChaiProviderFactory.createProvider(testConfig);
    final ChaiEntry testContainer = TestHelper.createTestContainer(testProvider);
    final ChaiUser testUser = TestHelper.createNewTestUser(testContainer);
    TestHelper.doBasicNonDestructiveUserTest(testUser);
    testProvider.close();
    {
        boolean gotError = false;
        try {
            TestHelper.doBasicNonDestructiveUserTest(testUser);
        } catch (IllegalStateException e) {
            gotError = true;
        }
        Assert.assertTrue(gotError);
    }
    // all should be able to be called on a closed provider.
    testProvider.close();
    testProvider.getProviderStatistics();
}
Also used : ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiUser(com.novell.ldapchai.ChaiUser) ChaiEntry(com.novell.ldapchai.ChaiEntry) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration)

Example 47 with ChaiProvider

use of com.novell.ldapchai.provider.ChaiProvider in project ldapchai by ldapchai.

the class ChaiTester method testChaiResponseSet.

public void testChaiResponseSet() throws Exception {
    final ChaiEntry testContainer = TestHelper.createTestContainer();
    final ChaiUser testUser;
    final ChaiConfiguration chaiConfig = new ChaiConfiguration("ldaps://ldaphost:636", "cn=admin,ou=ou,o=o", "password");
    {
        // create provider and test user.
        chaiConfig.setSetting(ChaiSetting.PROMISCUOUS_SSL, "true");
        final ChaiProvider provider = ChaiProviderFactory.createProvider(chaiConfig);
        testUser = ChaiUtility.createUser("cn=responseTestUser," + testContainer.getEntryDN(), "sn", provider);
    }
    // create challenges/responses
    final Map<Challenge, String> crMap;
    {
        final Map<Challenge, String> tempMap = new HashMap<Challenge, String>();
        tempMap.put(new ChaiChallenge(true, "c1", 5, 200, true), "response1");
        tempMap.put(new ChaiChallenge(true, "c2", 5, 200, true), "response2");
        tempMap.put(new ChaiChallenge(false, "c3", 5, 200, true), "response3");
        tempMap.put(new ChaiChallenge(false, "c4", 5, 200, true), "response4");
        crMap = Collections.unmodifiableMap(tempMap);
    }
    // write responses to user entry
    {
        final ChaiResponseSet responseSet = ChaiCrFactory.newChaiResponseSet(crMap, null, 0, chaiConfig, null);
        ChaiCrFactory.writeChaiResponseSet(responseSet, testUser);
    }
    // read responses from user entry
    final ResponseSet retreivedSet = ChaiCrFactory.readChaiResponseSet(testUser);
    Assert.assertTrue("error testing chai responses", retreivedSet.test(crMap));
    {
        final Map<Challenge, String> testMap = new HashMap<Challenge, String>(crMap);
        testMap.put(new ChaiChallenge(true, "c2", 5, 200, true), "response3");
        Assert.assertFalse("error testing chai responses, false positive", retreivedSet.test(testMap));
    }
    {
        final Map<Challenge, String> testMap = new HashMap<Challenge, String>(crMap);
        testMap.put(new ChaiChallenge(true, "c2", 50, 200, true), "response2");
        try {
            final ChaiResponseSet responseSet = ChaiCrFactory.newChaiResponseSet(testMap, null, 0, chaiConfig, null);
            ChaiCrFactory.writeChaiResponseSet(responseSet, testUser);
            Assert.fail("did not throw expected IllegalArgumentException due to response length being to short");
        } catch (ChaiValidationException e) {
        /* test should throw exception */
        }
    }
    {
        final ResponseSet testRs = ChaiCrFactory.newChaiResponseSet(crMap, null, 1, chaiConfig, null);
        final ChallengeSet testCs = new ChaiChallengeSet(crMap.keySet(), 1, null, null);
        Assert.assertTrue("meetsChallengeSetRequirements failed positive test", testRs.meetsChallengeSetRequirements(testCs));
    }
    {
        final Map<Challenge, String> testMap = new HashMap<Challenge, String>();
        testMap.put(new ChaiChallenge(true, "c1", 5, 200, true), "response1");
        testMap.put(new ChaiChallenge(true, "c2", 5, 200, true), "response2");
        final ResponseSet testRs = ChaiCrFactory.newChaiResponseSet(testMap, null, 1, chaiConfig, null);
        final ChallengeSet testCs = new ChaiChallengeSet(crMap.keySet(), 2, null, null);
        try {
            testRs.meetsChallengeSetRequirements(testCs);
            Assert.fail("meetsChallengeSetRequirements failed positive test");
        } catch (ChaiValidationException e) {
        /* test should throw exception */
        }
    }
}
Also used : ChaiEntry(com.novell.ldapchai.ChaiEntry) NmasResponseSet(com.novell.ldapchai.impl.edir.NmasResponseSet) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration) ChaiValidationException(com.novell.ldapchai.exception.ChaiValidationException) ChaiUser(com.novell.ldapchai.ChaiUser) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider)

Example 48 with ChaiProvider

use of com.novell.ldapchai.provider.ChaiProvider in project ldapchai by ldapchai.

the class FailOverTester method testMultiServerFailover.

public void testMultiServerFailover() throws Exception {
    TestHelper.configureLogging();
    final InetSocketAddress destinationAddress = figureDestSocketAddress();
    final TcpProxy proxy1 = new TcpProxy(basePort + 1, destinationAddress);
    final TcpProxy proxy2 = new TcpProxy(basePort + 2, destinationAddress);
    final TcpProxy proxy3 = new TcpProxy(basePort + 3, destinationAddress);
    proxy2.start();
    final ChaiConfiguration testConfig = makeChaiConfig(figureUrlForProxy(proxy1, proxy2, proxy3));
    final ChaiProvider testProvider = ChaiProviderFactory.createProvider(testConfig);
    final ChaiEntry testContainer = TestHelper.createTestContainer(testProvider);
    final ChaiUser testUser = TestHelper.createNewTestUser(testContainer);
    TestHelper.doBasicNonDestructiveUserTest(testUser);
    proxy2.stop();
    TestHelper.pause(1000);
    {
        // test to make sure we get unavailable error
        boolean gotError = false;
        try {
            TestHelper.doBasicNonDestructiveUserTest(testUser);
        } catch (ChaiUnavailableException e) {
            System.out.println("got expected unavailable error: " + e.getMessage());
            gotError = true;
        }
        Assert.assertTrue(gotError);
    }
    proxy1.start();
    TestHelper.pause(1000);
    TestHelper.doBasicNonDestructiveUserTest(testUser);
    proxy1.stop();
    proxy3.start();
    TestHelper.pause(1000);
    TestHelper.doBasicNonDestructiveUserTest(testUser);
}
Also used : ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiUser(com.novell.ldapchai.ChaiUser) InetSocketAddress(java.net.InetSocketAddress) ChaiEntry(com.novell.ldapchai.ChaiEntry) TcpProxy(com.novell.ldapchai.tests.util.TcpProxy) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration)

Example 49 with ChaiProvider

use of com.novell.ldapchai.provider.ChaiProvider in project ldapchai by ldapchai.

the class TestHelper method getProvider.

public static ChaiProvider getProvider() throws Exception {
    if (cachedProvider == null) {
        final ChaiProvider newProvider;
        try {
            final ChaiConfiguration chaiConfig = new ChaiConfiguration(TestHelper.bindURL, TestHelper.bindDN, TestHelper.bindPW);
            chaiConfig.setSetting(ChaiSetting.PROVIDER_IMPLEMENTATION, testProviderImpl);
            chaiConfig.setSetting(ChaiSetting.PROMISCUOUS_SSL, "true");
            // chaiConfig.setSetting(ChaiSetting.WATCHDOG_ENABLE, "false");
            // chaiConfig.setSetting(ChaiSetting.FAILOVER_ENABLE, "false");
            newProvider = ChaiProviderFactory.createProvider(chaiConfig);
        } catch (ChaiException e) {
            throw new Exception("Cannot connect to test ldap directory", e);
        }
        // test for test container
        try {
            newProvider.readStringAttribute(TestHelper.testContainer, "objectClass");
        } catch (Exception e) {
            throw new Exception("Cannot connect to test ldap directory, missing test container", e);
        }
        cachedProvider = newProvider;
    }
    return cachedProvider;
}
Also used : ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiException(com.novell.ldapchai.exception.ChaiException) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration) ChaiException(com.novell.ldapchai.exception.ChaiException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException)

Example 50 with ChaiProvider

use of com.novell.ldapchai.provider.ChaiProvider in project ldapchai by ldapchai.

the class WatchdogTester method testWatchdogBasic.

public void testWatchdogBasic() throws Exception {
    final ChaiEntry testContainer = TestHelper.createTestContainer();
    final long idleTime = 5 * 1000;
    final ChaiConfiguration chaiConfig = new ChaiConfiguration(TestHelper.bindURL, TestHelper.bindDN, TestHelper.bindPW);
    chaiConfig.setSetting(ChaiSetting.WATCHDOG_ENABLE, "true");
    chaiConfig.setSetting(ChaiSetting.PROMISCUOUS_SSL, "true");
    chaiConfig.setSetting(ChaiSetting.WATCHDOG_IDLE_TIMEOUT, String.valueOf(idleTime));
    final ChaiProvider provider = ChaiProviderFactory.createProvider(chaiConfig);
    // do initial read
    String cnValue = provider.readStringAttribute(testContainer.getEntryDN(), "ou");
    System.out.println("cnValue = " + cnValue);
    TestHelper.pause((long) (idleTime * 1.5));
    cnValue = provider.readStringAttribute(testContainer.getEntryDN(), "ou");
    System.out.println("cnValue = " + cnValue);
}
Also used : ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiEntry(com.novell.ldapchai.ChaiEntry) ChaiConfiguration(com.novell.ldapchai.provider.ChaiConfiguration)

Aggregations

ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)51 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)19 ChaiUser (com.novell.ldapchai.ChaiUser)18 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)18 ChaiConfiguration (com.novell.ldapchai.provider.ChaiConfiguration)16 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)15 ErrorInformation (password.pwm.error.ErrorInformation)15 ChaiEntry (com.novell.ldapchai.ChaiEntry)13 ChaiException (com.novell.ldapchai.exception.ChaiException)10 ArrayList (java.util.ArrayList)10 PwmOperationalException (password.pwm.error.PwmOperationalException)10 UserIdentity (password.pwm.bean.UserIdentity)9 LdapProfile (password.pwm.config.profile.LdapProfile)8 PasswordData (password.pwm.util.PasswordData)8 HashSet (java.util.HashSet)7 List (java.util.List)6 ChaiProviderFactory (com.novell.ldapchai.provider.ChaiProviderFactory)5 Instant (java.time.Instant)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5