org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LdapLoginManager.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
private void importUsers(LdapWorker w, EntryCursor cursor, Long domainId, boolean print) throws LdapException, CursorException, OmException, IOException {
	while (cursor.next()) {
		try {
			Entry e = cursor.get();
			User u = userDao.getByLogin(getLogin(w.config, e), Type.LDAP, domainId);
			u = w.getUser(e, u);
			if (print) {
				log.info("Going to import user: {}", u);
			} else {
				userDao.update(u, null);
				log.info("User {}, was imported", u);
			}
		} catch (CursorLdapReferralException cle) {
			log.warn(WARN_REFERRAL);
		}
	}
}
 
Example #2
Source File: LdapLoginManager.java    From openmeetings with Apache License 2.0 6 votes vote down vote up
private void fillGroups(Dn baseDn, String searchQ, List<Dn> groups) throws IOException, LdapException, CursorException {
	try (EntryCursor cursor = new EntryCursorImpl(conn.search(
			new SearchRequestImpl()
				.setBase(baseDn)
				.setFilter(searchQ)
				.setScope(SearchScope.SUBTREE)
				.addAttributes("*")
				.setDerefAliases(AliasDerefMode.DEREF_ALWAYS))))
	{
		while (cursor.next()) {
			try {
				Entry e = cursor.get();
				groups.add(e.getDn());
			} catch (CursorLdapReferralException cle) {
				log.warn(WARN_REFERRAL);
			}
		}
	}
}
 
Example #3
Source File: EntryCursorImpl.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Entry get() throws CursorException
{
    if ( !searchCursor.available() )
    {
        throw new InvalidCursorPositionException();
    }

    try
    {
        do
        {
            if ( response instanceof SearchResultEntry )
            {
                return ( ( SearchResultEntry ) response ).getEntry();
            }

            if ( response instanceof SearchResultReference )
            {
                throw new LdapReferralException( ( ( SearchResultReference ) response ).getReferral().getLdapUrls() );
            }
        }
        while ( next() && !( response instanceof SearchResultDone ) );
    }
    catch ( LdapReferralException lre )
    {
        throw new CursorLdapReferralException( lre );
    }
    catch ( Exception e )
    {
        throw new CursorException( e );
    }

    return null;
}
 
Example #4
Source File: LdapLoginManager.java    From openmeetings with Apache License 2.0 5 votes vote down vote up
private static Map.Entry<Dn, Entry> searchAndBind(LdapWorker w, String login, String passwd) throws LdapException, CursorException, OmException, IOException {
	Dn userDn = null;
	Entry entry = null;
	bindAdmin(w.conn, w.options);
	Dn baseDn = new Dn(w.options.searchBase);
	String searchQ = String.format(w.options.searchQuery, login);

	try (EntryCursor cursor = new EntryCursorImpl(w.conn.search(
			new SearchRequestImpl()
				.setBase(baseDn)
				.setFilter(searchQ)
				.setScope(w.options.scope)
				.addAttributes("*")
				.setDerefAliases(w.options.derefMode))))
	{
		while (cursor.next()) {
			try {
				Entry e = cursor.get();
				if (userDn != null) {
					log.error("more than 1 user found in LDAP");
					throw UNKNOWN;
				}
				userDn = e.getDn();
				if (w.options.useAdminForAttrs) {
					entry = e;
				}
			} catch (CursorLdapReferralException cle) {
				log.warn(WARN_REFERRAL);
			}
		}
	}
	if (userDn == null) {
		log.error("NONE users found in LDAP");
		throw BAD_CREDENTIALS;
	}
	w.conn.bind(userDn, passwd);
	return new AbstractMap.SimpleEntry<>(userDn, entry);
}