Example usage for javax.naming.ldap LdapReferralException getMessage

List of usage examples for javax.naming.ldap LdapReferralException getMessage

Introduction

In this page you can find the example usage for javax.naming.ldap LdapReferralException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:eu.uqasar.util.ldap.LdapManager.java

private int countLdapEntities(int maximum, final String baseDN, final String preferredFilter)
        throws NamingException {
    if (maximum <= 0) {
        return 0;
    }//w  w w .j ava2 s  .  c  o m
    int count = 0;
    NamingEnumeration<SearchResult> results = searchLDAP(baseDN, preferredFilter);
    while (results.hasMoreElements() && count < maximum) {
        try {
            results.next();
            count++;
        } catch (LdapReferralException ex) {
            logger.warn(ex.getMessage(), ex);
        }
    }
    return count;
}

From source file:eu.uqasar.util.ldap.LdapManager.java

public List<LdapUser> getUsersFromGroup(int maximum, LdapGroup group) throws NamingException {
    List<LdapUser> users = new ArrayList<>();
    final String mapping = settings.getGroupMemberMapping();
    javax.naming.directory.Attribute members = group.getMappedAttribute(mapping);
    if (members == null) {
        return users;
    }//  w w w .  ja va 2 s  . co  m
    NamingEnumeration<?> results = members.getAll();
    while (results.hasMoreElements() && users.size() < maximum) {
        try {
            final String userDN = (String) results.next();
            LdapUser user = getUserByDNAndFilter(userDN, settings.getUserFilter());
            if (user != null) {
                users.add(user);
            }
        } catch (LdapReferralException ex) {
            logger.warn(ex.getMessage(), ex);
        }
    }
    Collections.sort(users, new LdapUserComparator());
    return users;
}

From source file:eu.uqasar.util.ldap.LdapManager.java

private <T extends LdapEntity> List<T> getLdapEntities(int maximum, final String baseDN,
        final String preferredFilter, Class<T> clazz, Comparator<T> comparator) throws NamingException {
    if (maximum <= 0) {
        return Collections.emptyList();
    }/* ww w.  j a va 2 s  .co  m*/
    List<T> entities = new ArrayList<>();
    NamingEnumeration<SearchResult> results = searchLDAP(baseDN, preferredFilter);
    while (results.hasMoreElements() && entities.size() < maximum) {
        try {
            SearchResult group = results.next();
            Constructor<T> constructor = clazz.getConstructor(Attributes.class, LdapSettings.class);
            T entity = constructor.newInstance(group.getAttributes(), settings);
            entities.add(entity);
        } catch (LdapReferralException ex) {
            logger.warn(ex.getMessage(), ex);
        } catch (NoSuchMethodException | SecurityException | InstantiationException | IllegalAccessException
                | IllegalArgumentException | InvocationTargetException ex) {
            logger.error(ex.getMessage(), ex);
        }
    }
    Collections.sort(entities, comparator);
    return entities;
}