Example usage for javax.naming.directory SearchControls OBJECT_SCOPE

List of usage examples for javax.naming.directory SearchControls OBJECT_SCOPE

Introduction

In this page you can find the example usage for javax.naming.directory SearchControls OBJECT_SCOPE.

Prototype

int OBJECT_SCOPE

To view the source code for javax.naming.directory SearchControls OBJECT_SCOPE.

Click Source Link

Document

Search the named object.

Usage

From source file:org.sipfoundry.sipxconfig.bulk.ldap.LdapManagerImpl.java

/**
 * Connects to LDAP to retrieve the namingContexts attribute from root. Good
 * way to verify if LDAP is accessible. Command line anologue is:
 *
 * ldapsearch -x -b '' -s base '(objectclass=*)' namingContexts
 *
 * @param attrNames/*from  w  w  w.  jav a  2 s  . c  o m*/
 *            TODO
 *
 * @return namingContext value - can be used as the search base for user if
 *         nothing more specific is provided
 * @throws NamingException
 */
private Map<String, String> retrieveDefaultSearchBase(LdapConnectionParams params, String[] attrNames)
        throws NamingException {

    SearchControls cons = new SearchControls();

    cons.setReturningAttributes(attrNames);
    cons.setSearchScope(SearchControls.OBJECT_SCOPE);
    cons.setTimeLimit(30000);

    List<Map<String, String>> results = m_templateFactory.getLdapTemplate(params).search("", FILTER_ALL_CLASSES,
            cons, new AttributesToValues(attrNames), NULL_PROCESSOR);
    // only interested in the first result
    if (results.size() > 0) {
        return results.get(0);
    }
    return null;
}

From source file:org.springframework.ldap.config.LdapTemplateNamespaceHandlerTest.java

@Test
public void verifyParseWithCustomValues() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            "/ldap-namespace-config-values.xml");
    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    LdapTemplate ldapTemplate = ctx.getBean(LdapTemplate.class);
    DirContextAuthenticationStrategy authenticationStrategy = ctx
            .getBean(DirContextAuthenticationStrategy.class);

    assertThat(outerContextSource).isNotNull();
    assertThat(ldapTemplate).isNotNull();

    assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();
    ContextSource contextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();

    assertThat(LdapUtils.newLdapName("dc=261consulting,dc=com"))
            .isEqualTo(getInternalState(contextSource, "base"));
    assertThat("uid=admin").isEqualTo(getInternalState(contextSource, "userDn"));
    assertThat("apassword").isEqualTo(getInternalState(contextSource, "password"));
    assertThat(new String[] { "ldap://localhost:389" })
            .isEqualTo((Object[]) getInternalState(contextSource, "urls"));
    assertThat(Boolean.TRUE).isEqualTo(getInternalState(contextSource, "pooled"));
    assertThat(Boolean.FALSE).isEqualTo(getInternalState(contextSource, "anonymousReadOnly"));
    assertThat("follow").isEqualTo(getInternalState(contextSource, "referral"));
    assertThat(authenticationStrategy).isSameAs(getInternalState(contextSource, "authenticationStrategy"));

    assertThat(outerContextSource).isSameAs(getInternalState(ldapTemplate, "contextSource"));
    assertThat(Boolean.TRUE).isEqualTo(getInternalState(ldapTemplate, "ignorePartialResultException"));
    assertThat(Boolean.TRUE).isEqualTo(getInternalState(ldapTemplate, "ignoreNameNotFoundException"));
    assertThat(100).isEqualTo(getInternalState(ldapTemplate, "defaultCountLimit"));
    assertThat(200).isEqualTo(getInternalState(ldapTemplate, "defaultTimeLimit"));
    assertThat(SearchControls.OBJECT_SCOPE).isEqualTo(getInternalState(ldapTemplate, "defaultSearchScope"));
}

From source file:org.springframework.ldap.pool.validation.DefaultDirContextValidator.java

/**
 * Create the default validator, creates {@link SearchControls} with search scope <code>OBJECT_SCOPE</code>,
 * a countLimit of 1, returningAttributes of objectclass and timeLimit of 500.
 * The default base is an empty string and the default filter is objectclass=*
 *///  w  w w  . j a  va2s . c  om
public DefaultDirContextValidator() {
    this(SearchControls.OBJECT_SCOPE);
}