コード例 #1
0
  public void search() throws Exception {
    String base = "cn=servers,cn=zimbra";
    String filter = "(objectClass=zimbraServer)";
    String returnAttrs[] = new String[] {"objectClass", "cn"};

    ZLdapFilter zFilter =
        ZLdapFilterFactory.getInstance().fromFilterString(FilterId.ZMCONFIGD, filter);

    ZSearchControls searchControls =
        ZSearchControls.createSearchControls(
            ZSearchScope.SEARCH_SCOPE_SUBTREE, ZSearchControls.SIZE_UNLIMITED, returnAttrs);

    GenericLdapConfig ldapConfig = getLdapConfig();

    ZLdapContext zlc = null;
    try {
      zlc = LdapClient.getContext(ldapConfig, LdapUsage.SEARCH);

      ZSearchResultEnumeration ne = zlc.searchDir(base, zFilter, searchControls);
      while (ne.hasMore()) {
        ZSearchResultEntry entry = ne.next();

        String dn = entry.getDN();

        ZAttributes attrs = entry.getAttributes();
        String cn = attrs.getAttrString("cn");
        String[] objectClasses = attrs.getMultiAttrString("objectClass");

        System.out.println("dn = " + dn);
        System.out.println("cn = " + cn);
        for (String objectClass : objectClasses) {
          System.out.println("objetClass = " + objectClass);
        }
      }
      ne.close();

    } catch (LdapSizeLimitExceededException e) {
      e.printStackTrace();
      throw e;
    } finally {
      // Note: this is important!!
      LdapClient.closeContext(zlc);
    }
  }
コード例 #2
0
ファイル: ExternalGroup.java プロジェクト: huu0510/z-pec
  private static ExternalGroup searchGroup(
      DomainBy domainBy, String extGroupGrantee, boolean asAdmin) throws ServiceException {
    LdapProv prov = LdapProv.getInst();

    ExternalGroupInfo extGrpInfo = ExternalGroupInfo.parse(extGroupGrantee);
    String zimbraDomain = extGrpInfo.getZimbraDmain();
    String extGroupName = extGrpInfo.getExternalGroupName();

    Domain domain = prov.get(domainBy, zimbraDomain);
    if (domain == null) {
      throw AccountServiceException.NO_SUCH_DOMAIN(zimbraDomain);
    }

    String searchBase = domain.getExternalGroupLdapSearchBase();
    String filterTemplate = domain.getExternalGroupLdapSearchFilter();

    if (searchBase == null) {
      searchBase = LdapConstants.DN_ROOT_DSE;
    }
    String searchFilter = LdapUtil.computeDn(extGroupName, filterTemplate);

    GroupHandler groupHandler = getGroupHandler(domain);

    ZLdapContext zlc = null;
    try {
      zlc = groupHandler.getExternalDelegatedAdminGroupsLdapContext(domain, asAdmin);

      ZSearchResultEntry entry =
          prov.getHelper()
              .searchForEntry(
                  searchBase, FilterId.EXTERNAL_GROUP, searchFilter, zlc, new String[] {"mail"});

      if (entry != null) {
        return makeExternalGroup(
            domain, groupHandler, extGroupName, entry.getDN(), entry.getAttributes());
      } else {
        return null;
      }
    } finally {
      LdapClient.closeContext(zlc);
    }
  }