/** * Executes an ldap search. * * @param conn to search with * @param sr to read properties from * @return ldap search queue * @throws LDAPException if an error occurs */ protected LDAPSearchQueue search(final LDAPConnection conn, final SearchRequest sr) throws LDAPException { final LDAPSearchConstraints constraints = getLDAPSearchConstraints(sr); final LDAPControl[] lc = config.getControlProcessor().processRequestControls(sr.getControls()); if (lc != null) { constraints.setControls(lc); } return conn.search( sr.getBaseDn(), getSearchScope(sr.getSearchScope()), sr.getSearchFilter() != null ? sr.getSearchFilter().format() : null, getReturnAttributes(sr), sr.getTypesOnly(), (LDAPSearchQueue) null, constraints); }
/** * Returns an ldap search constraints object configured with the supplied search request. * * @param sr search request containing configuration to create search constraints * @return ldap search constraints */ protected LDAPSearchConstraints getLDAPSearchConstraints(final SearchRequest sr) { LDAPSearchConstraints constraints = connection.getSearchConstraints(); if (constraints == null) { constraints = new LDAPSearchConstraints(); } constraints.setServerTimeLimit(Long.valueOf(sr.getTimeLimit()).intValue()); constraints.setMaxResults(Long.valueOf(sr.getSizeLimit()).intValue()); if (sr.getDerefAliases() != null) { if (sr.getDerefAliases() == DerefAliases.ALWAYS) { constraints.setDereference(LDAPSearchConstraints.DEREF_ALWAYS); } else if (sr.getDerefAliases() == DerefAliases.FINDING) { constraints.setDereference(LDAPSearchConstraints.DEREF_FINDING); } else if (sr.getDerefAliases() == DerefAliases.NEVER) { constraints.setDereference(LDAPSearchConstraints.DEREF_NEVER); } else if (sr.getDerefAliases() == DerefAliases.SEARCHING) { constraints.setDereference(LDAPSearchConstraints.DEREF_SEARCHING); } } constraints.setReferralFollowing(sr.getFollowReferrals()); return constraints; }
/** * Checks the bean injection. * * @throws Exception * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ public void afterPropertiesSet() throws Exception { Assert.notNull( this.parametersProvider, "The property parametersProvider in the class " + this.getClass().getName() + " can't be null."); Assert.notNull( this.connectionManager, "The property connectionManager in the class " + this.getClass().getName() + " can't be null."); ldapParameters = (PersonsParametersSection) parametersProvider.getPersonsParametersSection(); uidAttributeArray = new String[] {ldapParameters.getLdapUidAttribute()}; connection = connectionManager.connect(); constraints = new LDAPSearchConstraints(); constraints.setMaxResults(0); }