@SuppressWarnings("unchecked")
  @Override
  public List<Person> searchForPersons(String keyword) {
    String filter =
        "(&(samAccountType=805306368)(|(sn="
            + keyword
            + "*)(givenname="
            + keyword
            + "*)(mail="
            + keyword
            + "*)))";

    logger.debug("filter:" + filter);

    List<Person> persons =
        (List<Person>) ldapTemplate.search("", filter, new PersonAttributesMapper());

    persons.remove(null);
    if (logger.isTraceEnabled()) {
      for (Person p : persons) {
        if (p != null) {
          logger.trace("username: "******"; sap:" + p.getSap());
        }
      }
    }
    return persons;
  }
  @Test
  public void testSearch_Plain() {
    CountNameClassPairCallbackHandler handler = new CountNameClassPairCallbackHandler();

    tested.search(base, "(objectclass=person)", handler);
    assertThat(handler.getNoOfRows()).isEqualTo(5);
  }
Example #3
0
  @SuppressWarnings("unchecked")
  protected void addMemberOf(Fixture fixture, LdapTemplate template, String user)
      throws NamingException {
    List<String> dns =
        template.search(
            "",
            fixture.config.usernameFilter(user).encode(),
            new ContextMapper() {
              public Object mapFromContext(Object arg0) {
                DirContextAdapter ctx = (DirContextAdapter) arg0;
                return ctx.getNameInNamespace();
              }
            });
    assertEquals(dns.toString(), 1, dns.size());

    DistinguishedName name = new DistinguishedName(dns.get(0));
    DistinguishedName root =
        new DistinguishedName(
            template.getContextSource().getReadOnlyContext().getNameInNamespace());

    // Build a relative name
    for (int i = 0; i < root.size(); i++) {
      name.removeFirst();
    }

    DirContextOperations context = template.lookupContext(name);
    context.setAttributeValues("memberOf", new Object[] {"foo"});
    template.modifyAttributes(context);
  }
Example #4
0
 public List<ContactAcctDTO> findMailContactAcct(String contactCN) {
   AndFilter andFilter = new AndFilter();
   andFilter.and(new EqualsFilter("cn", contactCN));
   andFilter.and(new EqualsFilter("cn", "Mail.Location"));
   return ldapTemplate.search(
       "cn=" + contactCN, andFilter.encode(), new ContactAcctAttributeMapper());
 }
  /**
   * 등록된 부서의 상세정보를 조회한다.
   *
   * @param vo 부서 Vo
   * @return deptManageVO 부서 Vo
   * @param bannerVO
   */
  public UcorgVO selectDeptManage(UcorgVO vo) throws Exception {
    final ContainerCriteria criteria = query().where("objectclass").is("ucorg2");

    @SuppressWarnings("unchecked")
    Map<String, Object> introspected = new BeanMap(vo);

    for (String key : introspected.keySet()) {
      if (key.equals("dn")
          || key.equals("class")
          || introspected.get(key) == null
          || introspected.get(key).equals("")) continue;

      ContainerCriteria c = query().where(key).is(String.valueOf(introspected.get(key)));
      criteria.and(c);
    }

    List<Object> list = null;
    try {
      list = ldapTemplate.search(criteria, new ObjectMapper<UcorgVO>(UcorgVO.class));
    } catch (Exception e) {
      e.printStackTrace();
    }

    return (UcorgVO) list.get(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"));
  }
  /**
   * ouCode를 활용하여 하위 부서를 조
   *
   * @param ouCode
   * @return
   * @throws Exception
   */
  public List<Object> selectDeptManageSubListByOuCode(String ouCode) throws Exception {
    ContainerCriteria criteria =
        query().where("objectclass").is("ucorg2").and("parentoucode").is(ouCode);

    List<Object> list = ldapTemplate.search(criteria, new ObjectMapper<UcorgVO>(UcorgVO.class));

    return list;
  }
Example #8
0
 @Override
 public List<String> getAllPersonNames() {
   return ldapTemplate.search(
       query().attributes("cn").where("objectclass").is("person"),
       new AttributesMapper<String>() {
         public String mapFromAttributes(Attributes attrs) throws NamingException {
           return attrs.get("cn").get().toString();
         }
       });
 }
 @Override
 public Person getLdapPersonOnlyBySAP(String sap) {
   Person p = null;
   String filter = "(employeenumber=" + sap + ")";
   List<?> persons = ldapTemplate.search("", filter, new PersonAttributesMapperForLdapOnly());
   if (!persons.isEmpty()) {
     p = (Person) persons.get(0);
   }
   return p;
 }
Example #10
0
  /**
   * Return a specific certification for a particular contact.
   *
   * @param contactCN
   * @param acctCN
   * @return
   */
  public List<ContactCertDTO> findContactCert(String contactCN, String certCN) {

    // Create filter
    AndFilter andFilter = new AndFilter();
    andFilter.and(new EqualsFilter("objectclass", "document"));
    andFilter.and(new EqualsFilter("cn", certCN));

    return ldapTemplate.search(
        "cn=" + contactCN, andFilter.encode(), new ContactCertAttributeMapper());
  }
Example #11
0
 /**
  * Outil de recherche de contact, celui-ci renvoit tous les contacts.
  *
  * @param param : critère demandé.
  * @return : Liste du critère demandé de tous les utilisateurs.
  */
 @Override
 public List findAll(final String param) {
   String base = Settings.getString(Settings.SYSTEM.section, Settings.SYSTEM.base_user);
   return ldapTemplate.search(
       base,
       "(objectClass=Person)",
       new AttributesMapper() {
         public Object mapFromAttributes(Attributes attrs) throws NamingException {
           return attrs.get("sn").get();
         }
       });
 }
  @Test
  public void testStartsUpWithMyEntries() throws Exception {
    LdapTemplate t =
        ldapTemplate(
            LdapConfiguration.DEFAULT_BIND_DN,
            LdapConfiguration.DEFAULT_PASSWORD,
            LdapConfiguration.DEFAULT_PORT);

    final List<String> dns = t.search("", OU_PRESENT, DN_MAPPER);

    assertThat("My OU should have been returned", dns, hasItems("ou=Groups,dc=root"));
  }
Example #13
0
  /**
   * DN의 하위부서 목록을 조회
   *
   * @param dn 조회할 객체의 Distinguished Name
   * @return
   * @throws Exception
   */
  public List<Object> selectDeptManageSubList(String dn) throws Exception {
    List<Object> ucorgList = null;
    String filter = "objectclass=ucorg2";

    try {
      ucorgList =
          ldapTemplate.search(
              dn, filter, SearchControls.ONELEVEL_SCOPE, new ObjectMapper<UcorgVO>(UcorgVO.class));
    } catch (NameNotFoundException e) {
    }

    return ucorgList;
  }
  @Override
  public Person getPersonByUsername(String username) {

    Person p = null;

    String filter = "(samaccountname=" + username + ")";
    try {
      List<?> persons = ldapTemplate.search("", filter, new PersonAttributesMapper());
      if (!persons.isEmpty()) {

        p = (Person) persons.get(0);
      }
    } catch (Exception ex) {

    }

    if (p == null) {
      logger.error(username + " user not find");
    }

    return p;
  }
Example #15
0
  /**
   * Find a specific set of contacts.
   *
   * @param lookup ie. "cn=myuser.identity,st=CA"
   * @return
   */
  public List<ContactDTO> findContact(String lookup) {
    StringTokenizer st = new StringTokenizer(lookup, ",=");

    // Create filter for person objects
    AndFilter andFilter = new AndFilter();
    andFilter.and(new EqualsFilter("objectclass", "person"));

    // Go through lookup string and add filters
    while (st.hasMoreTokens()) {
      String attr = null;
      String value = null;

      attr = st.nextToken();
      if (st.hasMoreTokens()) {
        value = st.nextToken();
      }

      if ((attr != null) && (value != null)) {
        andFilter.and(new EqualsFilter(attr, value));
      }
    }

    return ldapTemplate.search("", andFilter.encode(), new ContactAttributeMapper());
  }
Example #16
0
 /**
  * Return all contacts.
  *
  * @return
  */
 public List<ContactDTO> findAllContacts() {
   return ldapTemplate.search("", "(objectclass=person)", new ContactAttributeMapper());
 }
Example #17
0
 /**
  * Return all certifications for a particular contact.
  *
  * @param contactCN
  * @return
  */
 public List<ContactCertDTO> findAllContactCerts(String contactCN) {
   return ldapTemplate.search(
       "cn=" + contactCN, "(objectclass=document)", new ContactCertAttributeMapper());
 }
Example #18
0
 /**
  * Return all accounts for a particular contact.
  *
  * @param contactCN
  * @return
  */
 public List<ContactAcctDTO> findAllContactAccts(String contactCN) {
   return ldapTemplate.search(
       "cn=" + contactCN, "(objectclass=kmr-account)", new ContactAcctAttributeMapper());
 }
Example #19
0
 @Override
 public List<Person> findAll() {
   return ldapTemplate.search(query().where("objectclass").is("person"), PERSON_CONTEXT_MAPPER);
 }