Exemplo n.º 1
0
  @Test
  public void testMyLdifFileWasLoaded() throws Exception {
    LdapTemplate t = new LdapTemplate();
    LdapContextSource s = new LdapContextSource();
    s.setPassword(LdapConfiguration.DEFAULT_PASSWORD);
    s.setUserDn(LdapConfiguration.DEFAULT_BIND_DN);
    s.setUrl(String.format("ldap://*****:*****@SuppressWarnings("unchecked")
    List<String> dns =
        t.search(
            "",
            filter.encode(),
            new ContextMapper() {
              public Object mapFromContext(Object ctx) {
                DirContextAdapter context = (DirContextAdapter) ctx;
                return context.getDn().toString();
              }
            });

    assertEquals(2, dns.size());
    assertTrue(dns.contains("dc=root"));
    assertTrue(dns.contains("dc=child,dc=root"));
  }
Exemplo n.º 2
0
  @Before
  public void setUp() throws Exception {
    lctxs = new LdapContextSource();
    lctxs.setBase(baseDn);
    lctxs.setUrl(ldapUrl);
    lctxs.setUserDn(bindDn);
    lctxs.setPassword(bindPassword);
    lctxs.afterPropertiesSet();
    ltmpl = new LdapTemplate();
    ltmpl.setContextSource(lctxs);
    ltmpl.afterPropertiesSet();

    // removing users
    try {
      ltmpl.unbind("ou=users", true);
    } catch (NamingException e) {
    }

    // removing roles
    try {
      ltmpl.unbind("ou=roles", true);
    } catch (NamingException e) {
    }

    // recreating ou=users
    try {
      DirContextOperations ctx = new DirContextAdapter("ou=users");
      ctx.addAttributeValue("objectClass", "top");
      ctx.addAttributeValue("objectClass", "organizationalUnit");
      ctx.addAttributeValue("ou", "users");
      ltmpl.bind(ctx);
    } catch (Exception e) {
    }
    ;

    // recreating ou=roles
    try {
      DirContextOperations ctx = new DirContextAdapter("ou=roles");
      ctx.addAttributeValue("objectClass", "top");
      ctx.addAttributeValue("objectClass", "organizationalUnit");
      ctx.addAttributeValue("ou", "roles");
      ltmpl.bind(ctx);
    } catch (Exception e) {
    }
    ;
  }