@After
 public void closeAppContext() {
   if (appCtx != null) {
     appCtx.close();
     appCtx = null;
   }
 }
 @Test
 public void inetOrgContextMapperIsSupported() {
   setContext(
       "<ldap-server id='someServer' ldif='classpath:test-server.ldif'/>"
           + "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' user-details-class='inetOrgPerson'/>");
   UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
   UserDetails ben = uds.loadUserByUsername("ben");
   assertTrue(ben instanceof InetOrgPerson);
 }
  @Test
  public void rolePrefixIsSupported() throws Exception {
    setContext(
        "<ldap-user-service id='ldapUDS' "
            + "     user-search-filter='(uid={0})' "
            + "     group-search-filter='member={0}' role-prefix='PREFIX_'/>"
            + "<ldap-user-service id='ldapUDSNoPrefix' "
            + "     user-search-filter='(uid={0})' "
            + "     group-search-filter='member={0}' role-prefix='none'/><ldap-server ldif='classpath:test-server.ldif'/>");

    UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
    UserDetails ben = uds.loadUserByUsername("ben");
    assertTrue(
        AuthorityUtils.authorityListToSet(ben.getAuthorities()).contains("PREFIX_DEVELOPERS"));

    uds = (UserDetailsService) appCtx.getBean("ldapUDSNoPrefix");
    ben = uds.loadUserByUsername("ben");
    assertTrue(AuthorityUtils.authorityListToSet(ben.getAuthorities()).contains("DEVELOPERS"));
  }
  @Test
  public void userServiceReturnsExpectedData() throws Exception {
    setContext(
        "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' group-search-filter='member={0}' /><ldap-server ldif='classpath:test-server.ldif'/>");

    UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
    UserDetails ben = uds.loadUserByUsername("ben");

    Set<String> authorities = AuthorityUtils.authorityListToSet(ben.getAuthorities());
    assertEquals(3, authorities.size());
    assertTrue(authorities.contains("ROLE_DEVELOPERS"));
  }
  @Test
  public void differentUserSearchBaseWorksAsExpected() throws Exception {
    setContext(
        "<ldap-user-service id='ldapUDS' "
            + "       user-search-base='ou=otherpeople' "
            + "       user-search-filter='(cn={0})' "
            + "       group-search-filter='member={0}' /><ldap-server ldif='classpath:test-server.ldif'/>");

    UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
    UserDetails joe = uds.loadUserByUsername("Joe Smeth");

    assertEquals("Joe Smeth", joe.getUsername());
  }
 @After
 public void closeAppContext() {
   if (appContext != null) {
     appContext.close();
   }
 }