Search in sources :

Example 1 with ChaiGroup

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

Aggregations

ChaiGroup (com.novell.ldapchai.ChaiGroup)1 ChaiPasswordPolicy (com.novell.ldapchai.ChaiPasswordPolicy)1 ChaiUser (com.novell.ldapchai.ChaiUser)1 ChaiException (com.novell.ldapchai.exception.ChaiException)1 ChaiProvider (com.novell.ldapchai.provider.ChaiProvider)1 ChaiProviderFactory (com.novell.ldapchai.provider.ChaiProviderFactory)1