public static void closeDirectoryContext(InitialDirContext initialDirContext) {
   try {
     initialDirContext.close();
   } catch (NamingException e) {
     LOGGER.warn("Could not close InitialDirContext correctly!", e);
   }
 }
Пример #2
0
  public void testBasic() throws Exception {
    LdapFactoryHelper helper = (LdapFactoryHelper) lookup(LdapFactoryHelper.ROLE);

    PersonLdapFactory.setHelper(helper);

    InitialDirContext context = apacheDs.getAdminContext();

    context.addToEnvironment(Context.OBJECT_FACTORIES, PersonLdapFactory.class.getName());
    context.addToEnvironment(Context.STATE_FACTORIES, PersonLdapFactory.class.getName());

    LdapName name = new LdapName("uid=trygvis,dc=test");

    // ----------------------------------------------------------------------
    //
    // ----------------------------------------------------------------------

    try {
      context.unbind(name);
    } catch (NamingException e) {
      // ignore
    }

    Person person = new Person();
    person.setName("Trygve");

    context.bind(name, person);

    Object o = context.lookup(name);

    assertEquals(Person.class, o.getClass());
    person = (Person) o;
    assertEquals("Trygve", person.getName());
    assertEquals(null, person.getDescription());

    context.close();
  }