Search in sources :

Example 31 with ChaiException

use of com.novell.ldapchai.exception.ChaiException in project ldapchai by ldapchai.

the class ReadUserData method main.

public static void main(final String[] args) {
    String ldapURL = "ldap://ldaphost:389";
    String ldapBindDN = "cn=admin,ou=ou,o=o";
    String ldapBindPW = "password";
    if (args.length == 3) {
        ldapURL = args[0];
        ldapBindDN = args[1];
        ldapBindPW = args[2];
    }
    try {
        // create provider factory
        final ChaiProviderFactory chaiProviderFactory = ChaiProviderFactory.newProviderFactory();
        // create a provider using the standard JNDI factory.
        ChaiProvider chaiProvider = chaiProviderFactory.newProvider(ldapURL, ldapBindDN, ldapBindPW);
        ChaiUser user = chaiProvider.getEntryFactory().newChaiUser(ldapBindDN);
        // read the value of the bindDN's cn attribute, and print it to stdout.
        Map<String, String> allUserAttributes = user.readStringAttributes(null);
        System.out.println("UserDN: " + user.getEntryDN());
        // Output each of the user's attributes, and one value for each attribute:
        for (String key : allUserAttributes.keySet()) {
            String value = allUserAttributes.get(key);
            System.out.println(key + ": " + value);
        }
        // Detect the user's password and output the debug string
        ChaiPasswordPolicy pwdPolicy = user.getPasswordPolicy();
        System.out.println("PasswordPolicy = " + pwdPolicy);
        System.out.println("PasswordModificationDate = " + user.readPasswordModificationDate());
        System.out.println("PasswordExpirationDate = " + user.readPasswordExpirationDate());
        System.out.println("PasswordExpired = " + user.isPasswordExpired());
        System.out.println("PasswordLocked = " + user.isPasswordLocked());
        // Read the user's group membership, and output each group DN.
        System.out.println(user.getEntryDN() + " groups: ");
        for (ChaiGroup group : user.getGroups()) {
            System.out.println(group.getEntryDN());
        }
        System.out.println("");
    } catch (ChaiException e) {
        System.out.println("LDAP error: " + e.getMessage());
    }
}
Also used : ChaiPasswordPolicy(com.novell.ldapchai.ChaiPasswordPolicy) ChaiProvider(com.novell.ldapchai.provider.ChaiProvider) ChaiUser(com.novell.ldapchai.ChaiUser) ChaiProviderFactory(com.novell.ldapchai.provider.ChaiProviderFactory) ChaiGroup(com.novell.ldapchai.ChaiGroup) ChaiException(com.novell.ldapchai.exception.ChaiException)

Example 32 with ChaiException

use of com.novell.ldapchai.exception.ChaiException in project ldapchai by ldapchai.

the class FailOverWrapper method failOverInvoke.

private Object failOverInvoke(final Method m, final Object[] args) throws ChaiException {
    int attempts = 0;
    final int maxAttempts = settings.getMaxRetries();
    while (attempts < maxAttempts) {
        // Check to make sure we haven't been closed while looping.
        if (closed || rotationMachine == null) {
            LOGGER.debug("close detected while inside retry loop, throwing ChaiUnavailableException");
            throw new ChaiUnavailableException("FailOverWrapper closed while retrying connection", ChaiError.COMMUNICATION);
        }
        // fetch the current active provider from the machine.  If unable to reach
        // any ldap servers, this will throw ChaiUnavailable right here.
        final ChaiProvider currentProvider;
        try {
            currentProvider = rotationMachine.getCurrentProvider();
        } catch (NullPointerException e) {
            LOGGER.debug("RotationMachine unavailable");
            throw new ChaiUnavailableException("RotationMachine unavailable while retrying connection", ChaiError.COMMUNICATION);
        }
        try {
            return AbstractWrapper.invoker(currentProvider, m, args);
        } catch (Exception e) {
            if (settings.errorIsRetryable(e) && !closed) {
                rotationMachine.reportBrokenProvider(currentProvider, e);
            } else {
                throw AbstractProvider.convertInvocationExceptionToChaiException(e);
            }
        }
        attempts++;
    }
    throw new ChaiUnavailableException("unable to reach any configured server, maximum retries exceeded", ChaiError.COMMUNICATION);
}
Also used : ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ChaiException(com.novell.ldapchai.exception.ChaiException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException)

Example 33 with ChaiException

use of com.novell.ldapchai.exception.ChaiException 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)

Aggregations

ChaiException (com.novell.ldapchai.exception.ChaiException)33 ErrorInformation (password.pwm.error.ErrorInformation)18 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)16 ChaiUser (com.novell.ldapchai.ChaiUser)15 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)9 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)6 UserIdentity (password.pwm.bean.UserIdentity)6 PwmOperationalException (password.pwm.error.PwmOperationalException)6 Instant (java.time.Instant)5 ChaiResponseSet (com.novell.ldapchai.cr.ChaiResponseSet)4 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)4 ArrayList (java.util.ArrayList)4 FormConfiguration (password.pwm.config.value.data.FormConfiguration)4 PasswordData (password.pwm.util.PasswordData)4 ResponseSet (com.novell.ldapchai.cr.ResponseSet)3 List (java.util.List)3 Map (java.util.Map)3 PwmApplication (password.pwm.PwmApplication)3 ChallengeSet (com.novell.ldapchai.cr.ChallengeSet)2 NmasResponseSet (com.novell.ldapchai.impl.edir.NmasResponseSet)2