use of com.novell.ldapchai.ChaiGroup 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());
}
}
Aggregations