private static ExternalGroup makeExternalGroup( Domain domain, GroupHandler groupHandler, String extGroupName, String dn, ZAttributes attrs) throws ServiceException { String id = ExternalGroupInfo.encode(domain.getId(), extGroupName); String name = ExternalGroupInfo.encode(domain.getName(), extGroupName); ExternalGroup extGroup = new ExternalGroup(dn, id, name, domain.getId(), attrs, groupHandler, LdapProv.getInst()); return extGroup; }
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); } }