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());
}
}
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);
}
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;
}
Aggregations