Search in sources :

Example 1 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.

the class LdapProvisioning method deleteDistributionList.

private void deleteDistributionList(LdapDistributionList dl) throws ServiceException {
    String zimbraId = dl.getId();
    // make a copy of all addrs of this DL, after the delete all aliases on this dl
    // object will be gone, but we need to remove them from the allgroups cache after the DL is deleted
    Set<String> addrs = new HashSet<String>(dl.getMultiAttrSet(Provisioning.A_mail));
    // remove the DL from all DLs
    // this doesn't throw any exceptions
    removeAddressFromAllDistributionLists(dl.getName());
    // delete all aliases of the DL
    String[] aliases = dl.getAliases();
    if (aliases != null) {
        String dlName = dl.getName();
        for (int i = 0; i < aliases.length; i++) {
            // this "alias" if it is the primary name, the entire entry will be deleted anyway.
            if (!dlName.equalsIgnoreCase(aliases[i])) {
                // this also removes each alias from any DLs
                removeAlias(dl, aliases[i]);
            }
        }
    }
    // delete all grants granted to the DL
    try {
        RightCommand.revokeAllRights(this, GranteeType.GT_GROUP, zimbraId);
    } catch (ServiceException e) {
        // eat the exception and continue
        ZimbraLog.account.warn("cannot revoke grants", e);
    }
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_DISTRIBUTIONLIST);
        zlc.deleteEntry(dl.getDN());
        groupCache.remove(dl);
        allDLs.removeGroup(addrs);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to purge distribution list: " + zimbraId, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
    PermissionCache.invalidateCache();
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) HashSet(java.util.HashSet)

Example 2 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.

the class LdapProvisioning method getHABDynamicGroupMemberDetails.

/**
 * get members of dynamic group and member details
 * @param group
 * @return
 */
public List<HABGroupMember> getHABDynamicGroupMemberDetails(Group group) {
    final List<HABGroupMember> members = Lists.newArrayList();
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.REPLICA, LdapUsage.GET_GROUP_MEMBER);
        String[] memberDNs = group.getMultiAttr(Provisioning.A_member);
        String[] memberAttrMap = getConfig().getMultiAttr(Provisioning.A_zimbraHABMemberLdapAttrMap);
        Map<String, String> habMemberAttrMap = Arrays.stream(memberAttrMap).collect(Collectors.toMap(e -> e.split("=")[0], e -> e.split("=")[1]));
        List<String> ldapAttrList = new ArrayList<String>(habMemberAttrMap.values());
        ldapAttrList.add(Provisioning.A_objectClass);
        ldapAttrList.add(Provisioning.A_mail);
        ldapAttrList.add(Provisioning.A_zimbraMailDeliveryAddress);
        ldapAttrList.add(Provisioning.A_zimbraHABSeniorityIndex);
        final String[] attrsToGet = ldapAttrList.toArray(new String[] {});
        for (String memberDN : memberDNs) {
            ZAttributes memberAttrs = zlc.getAttributes(memberDN, attrsToGet);
            boolean isHABGroup = memberAttrs.hasAttributeValue(Provisioning.A_objectClass, AttributeClass.OC_zimbraHabGroup);
            if (!isHABGroup) {
                HABGroupMember habMember = new HABGroupMember(memberAttrs.getAttrString(Provisioning.A_mail));
                for (String key : habMemberAttrMap.keySet()) {
                    if (Provisioning.A_zimbraMailAlias.equals(habMemberAttrMap.get(key))) {
                        String[] aliases = memberAttrs.getMultiAttrString(habMemberAttrMap.get(key));
                        for (String alias : aliases) {
                            habMember.addAttr(new NamedValue(key, alias));
                        }
                    } else {
                        String val = memberAttrs.getAttrString(habMemberAttrMap.get(key));
                        if (StringUtils.isNotEmpty(val)) {
                            habMember.addAttr(new NamedValue(key, val));
                        }
                    }
                }
                String seniorityIndex = memberAttrs.getAttrString(Provisioning.A_zimbraHABSeniorityIndex);
                if (seniorityIndex == null) {
                    seniorityIndex = "0";
                }
                habMember.setSeniorityIndex(Integer.parseInt(seniorityIndex));
                members.add(habMember);
            }
        }
        Collections.sort(members, new SortBySeniorityIndexThenName());
    } catch (ServiceException e) {
        ZimbraLog.account.debug("unable to get hab dynamic group members", e);
    } finally {
        LdapClient.closeContext(zlc);
    }
    return members;
}
Also used : LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) StringUtils(org.apache.commons.lang.StringUtils) PermissionCache(com.zimbra.cs.account.accesscontrol.PermissionCache) AccountUtil(com.zimbra.cs.util.AccountUtil) LdapGlobalGrant(com.zimbra.cs.account.ldap.entry.LdapGlobalGrant) LdapShareLocator(com.zimbra.cs.account.ldap.entry.LdapShareLocator) EntryCacheDataKey(com.zimbra.cs.account.EntryCacheDataKey) SetUtil(com.zimbra.common.util.SetUtil) TODO(com.zimbra.cs.ldap.LdapTODO.TODO) Map(java.util.Map) LdapUtil(com.zimbra.cs.ldap.LdapUtil) LdapAlwaysOnCluster(com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster) ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) IDNUtil(com.zimbra.cs.account.IDNUtil) AttributeMigration(com.zimbra.cs.ephemeral.migrate.AttributeMigration) Signature(com.zimbra.cs.account.Signature) TargetType(com.zimbra.cs.account.accesscontrol.TargetType) ZimbraLog(com.zimbra.common.util.ZimbraLog) MailTarget(com.zimbra.cs.account.MailTarget) IAccountCache(com.zimbra.cs.account.cache.IAccountCache) StringUtil(com.zimbra.common.util.StringUtil) Folder(com.zimbra.cs.mailbox.Folder) Key(com.zimbra.common.account.Key) LdapUCService(com.zimbra.cs.account.ldap.entry.LdapUCService) AccountServiceException(com.zimbra.cs.account.AccountServiceException) EphemeralLocation(com.zimbra.cs.ephemeral.EphemeralLocation) MimeTypeInfo(com.zimbra.cs.mime.MimeTypeInfo) SearchDirectoryOptions(com.zimbra.cs.account.SearchDirectoryOptions) Strings(com.google.common.base.Strings) Constants(com.zimbra.common.util.Constants) Lists(com.google.common.collect.Lists) ZimletException(com.zimbra.cs.zimlet.ZimletException) Group(com.zimbra.cs.account.Group) LdapAlias(com.zimbra.cs.account.ldap.entry.LdapAlias) LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) GetFromDomainCacheOption(com.zimbra.cs.account.cache.DomainCache.GetFromDomainCacheOption) IOException(java.io.IOException) ZSearchControls(com.zimbra.cs.ldap.ZSearchControls) LdapDateUtil(com.zimbra.cs.ldap.LdapDateUtil) LdapInvalidSearchFilterException(com.zimbra.cs.ldap.LdapException.LdapInvalidSearchFilterException) TreeMap(java.util.TreeMap) StopIteratingException(com.zimbra.cs.ldap.SearchLdapOptions.StopIteratingException) RightModifier(com.zimbra.cs.account.accesscontrol.RightModifier) AttributeConverter(com.zimbra.cs.ephemeral.migrate.AttributeConverter) Account(com.zimbra.cs.account.Account) GranteeType(com.zimbra.cs.account.accesscontrol.GranteeType) IAttributes(com.zimbra.cs.ldap.IAttributes) Config(com.zimbra.cs.account.Config) Date(java.util.Date) Random(java.util.Random) Cos(com.zimbra.cs.account.Cos) GalSyncToken(com.zimbra.cs.gal.GalSyncToken) Zimlet(com.zimbra.cs.account.Zimlet) NamedEntry(com.zimbra.cs.account.NamedEntry) GalUtil(com.zimbra.cs.account.gal.GalUtil) ZimletUtil(com.zimbra.cs.zimlet.ZimletUtil) EphemeralKey(com.zimbra.cs.ephemeral.EphemeralKey) DataSourceManager(com.zimbra.cs.datasource.DataSourceManager) INamedEntryCache(com.zimbra.cs.account.cache.INamedEntryCache) Element(com.zimbra.common.soap.Element) Argument(com.zimbra.common.service.ServiceException.Argument) LogFactory(com.zimbra.common.util.LogFactory) LdapIdentity(com.zimbra.cs.account.ldap.entry.LdapIdentity) LdapInvalidAttrValueException(com.zimbra.cs.ldap.LdapException.LdapInvalidAttrValueException) Collection(java.util.Collection) ZLdapFilterFactory(com.zimbra.cs.ldap.ZLdapFilterFactory) Mailbox(com.zimbra.cs.mailbox.Mailbox) Collectors(java.util.stream.Collectors) LC(com.zimbra.common.localconfig.LC) PostCreateAccountListener(com.zimbra.cs.account.ProvisioningExt.PostCreateAccountListener) DataKey(com.zimbra.cs.account.callback.CallbackContext.DataKey) GalSearchType(com.zimbra.soap.type.GalSearchType) Pair(com.zimbra.common.util.Pair) InMemoryLdapServer(com.zimbra.cs.ldap.unboundid.InMemoryLdapServer) LdapMimeType(com.zimbra.cs.account.ldap.entry.LdapMimeType) ShareLocator(com.zimbra.cs.account.ShareLocator) GalSearchControl(com.zimbra.cs.gal.GalSearchControl) AttributeManager(com.zimbra.cs.account.AttributeManager) GuestAccount(com.zimbra.cs.account.GuestAccount) ObjectType(com.zimbra.cs.account.SearchDirectoryOptions.ObjectType) EphemeralInput(com.zimbra.cs.ephemeral.EphemeralInput) AdminConstants(com.zimbra.common.soap.AdminConstants) GalSearchResultCallback(com.zimbra.cs.gal.GalSearchResultCallback) GalParams(com.zimbra.cs.account.gal.GalParams) AddressListInfo(com.zimbra.soap.account.type.AddressListInfo) LdapSignature(com.zimbra.cs.account.ldap.entry.LdapSignature) EffectiveRights(com.zimbra.cs.account.accesscontrol.RightCommand.EffectiveRights) Hex(org.apache.commons.codec.binary.Hex) Stack(java.util.Stack) NamedValue(com.zimbra.soap.type.NamedValue) HashSet(java.util.HashSet) FilterId(com.zimbra.cs.ldap.ZLdapFilterFactory.FilterId) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) LdapContextNotEmptyException(com.zimbra.cs.ldap.LdapException.LdapContextNotEmptyException) LdapConfig(com.zimbra.cs.account.ldap.entry.LdapConfig) GroupedEntry(com.zimbra.cs.account.GroupedEntry) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) CountObjectsType(com.zimbra.soap.admin.type.CountObjectsType) IncludeType(com.zimbra.cs.account.SearchAccountsOptions.IncludeType) ZAttributes(com.zimbra.cs.ldap.ZAttributes) LdapConstants(com.zimbra.cs.ldap.LdapConstants) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) EphemeralStore(com.zimbra.cs.ephemeral.EphemeralStore) DomainCache(com.zimbra.cs.account.cache.DomainCache) MailboxManager(com.zimbra.cs.mailbox.MailboxManager) ProvisioningExt(com.zimbra.cs.account.ProvisioningExt) LdapAccount(com.zimbra.cs.account.ldap.entry.LdapAccount) TargetBy(com.zimbra.soap.type.TargetBy) CodeConstants(com.zimbra.common.account.ForgetPasswordEnums.CodeConstants) GlobalGrant(com.zimbra.cs.account.GlobalGrant) ZSearchScope(com.zimbra.cs.ldap.ZSearchScope) AliasedEntry(com.zimbra.cs.account.AliasedEntry) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) AccessManager(com.zimbra.cs.account.AccessManager) ResetPasswordUtil(com.zimbra.cs.service.util.ResetPasswordUtil) Comparator(java.util.Comparator) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry) IDomainCache(com.zimbra.cs.account.cache.IDomainCache) Arrays(java.util.Arrays) LdapCalendarResource(com.zimbra.cs.account.ldap.entry.LdapCalendarResource) PreAuthKey(com.zimbra.cs.account.PreAuthKey) HABGroupMember(com.zimbra.soap.account.type.HABGroupMember) SecureRandom(java.security.SecureRandom) DistributionListBy(com.zimbra.common.account.Key.DistributionListBy) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) IMimeTypeCache(com.zimbra.cs.account.cache.IMimeTypeCache) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) DynamicGroup(com.zimbra.cs.account.DynamicGroup) AuthMech(com.zimbra.cs.account.auth.AuthMechanism.AuthMech) PrintWriter(java.io.PrintWriter) LdapDomain(com.zimbra.cs.account.ldap.entry.LdapDomain) AuthContext(com.zimbra.cs.account.auth.AuthContext) LdapEntryLocation(com.zimbra.cs.ephemeral.LdapEntryLocation) Set(java.util.Set) GalContact(com.zimbra.cs.account.GalContact) DataSourceType(com.zimbra.soap.admin.type.DataSourceType) SearchLdapVisitor(com.zimbra.cs.ldap.SearchLdapOptions.SearchLdapVisitor) DataSource(com.zimbra.cs.account.DataSource) LdapServerType(com.zimbra.cs.ldap.LdapServerType) ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) ZLdapSchema(com.zimbra.cs.ldap.ZLdapSchema) UCService(com.zimbra.cs.account.UCService) SortBySeniorityIndexThenName(com.zimbra.cs.service.util.SortBySeniorityIndexThenName) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions) ServiceException(com.zimbra.common.service.ServiceException) AttributeInfo(com.zimbra.cs.account.AttributeInfo) TreeSet(java.util.TreeSet) CheckBinary(com.zimbra.cs.ldap.IAttributes.CheckBinary) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry) ArrayList(java.util.ArrayList) PasswordUtil(com.zimbra.cs.account.auth.PasswordUtil) Krb5Principal(com.zimbra.cs.account.krb5.Krb5Principal) Right(com.zimbra.cs.account.accesscontrol.Right) UCServiceBy(com.zimbra.common.account.Key.UCServiceBy) Domain(com.zimbra.cs.account.Domain) EmailUtil(com.zimbra.common.util.EmailUtil) SystemUtil(com.zimbra.common.util.SystemUtil) LdapException(com.zimbra.cs.ldap.LdapException) LdapMultipleEntriesMatchedException(com.zimbra.cs.ldap.LdapException.LdapMultipleEntriesMatchedException) ExternalLdapConfig(com.zimbra.cs.ldap.LdapServerConfig.ExternalLdapConfig) AlwaysOnCluster(com.zimbra.cs.account.AlwaysOnCluster) GranteeBy(com.zimbra.soap.admin.type.GranteeSelector.GranteeBy) MakeObjectOpt(com.zimbra.cs.account.SearchDirectoryOptions.MakeObjectOpt) GalSearchConfig(com.zimbra.cs.gal.GalSearchConfig) Zimbra(com.zimbra.cs.util.Zimbra) ProvisioningConstants(com.zimbra.common.account.ProvisioningConstants) GalNamedFilter(com.zimbra.cs.account.gal.GalNamedFilter) Identity(com.zimbra.cs.account.Identity) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) CacheEntryType(com.zimbra.soap.admin.type.CacheEntryType) CacheAwareProvisioning(com.zimbra.cs.account.CacheAwareProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) LdapServer(com.zimbra.cs.account.ldap.entry.LdapServer) LdapEphemeralStore(com.zimbra.cs.ephemeral.LdapEphemeralStore) PatternSyntaxException(java.util.regex.PatternSyntaxException) XMPPComponent(com.zimbra.cs.account.XMPPComponent) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent) LdapSizeLimitExceededException(com.zimbra.cs.ldap.LdapException.LdapSizeLimitExceededException) LdapInvalidAttrNameException(com.zimbra.cs.ldap.LdapException.LdapInvalidAttrNameException) Sets(com.google.common.collect.Sets) AutoProvPrincipalBy(com.zimbra.soap.type.AutoProvPrincipalBy) List(java.util.List) Log(com.zimbra.common.util.Log) LdapUsage(com.zimbra.cs.ldap.LdapUsage) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) NameUtil(com.zimbra.cs.account.names.NameUtil) AccountBy(com.zimbra.common.account.Key.AccountBy) Entry(com.zimbra.cs.account.Entry) Pattern(java.util.regex.Pattern) EmailAddress(com.zimbra.cs.account.names.NameUtil.EmailAddress) SortOpt(com.zimbra.cs.account.SearchDirectoryOptions.SortOpt) GalSearchParams(com.zimbra.cs.gal.GalSearchParams) AuthMechanism(com.zimbra.cs.account.auth.AuthMechanism) HashMap(java.util.HashMap) LdapClient(com.zimbra.cs.ldap.LdapClient) Server(com.zimbra.cs.account.Server) CalendarResource(com.zimbra.cs.account.CalendarResource) RightCommand(com.zimbra.cs.account.accesscontrol.RightCommand) AddressList(com.zimbra.cs.account.AddressList) Alias(com.zimbra.cs.account.Alias) Iterator(java.util.Iterator) DistributionList(com.zimbra.cs.account.DistributionList) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) GalOp(com.zimbra.cs.account.gal.GalOp) Maps(com.google.common.collect.Maps) LdapDataSource(com.zimbra.cs.account.ldap.entry.LdapDataSource) L10nUtil(com.zimbra.common.util.L10nUtil) AttributeClass(com.zimbra.cs.account.AttributeClass) Collections(java.util.Collections) JWEUtil(com.zimbra.cs.service.util.JWEUtil) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) SortBySeniorityIndexThenName(com.zimbra.cs.service.util.SortBySeniorityIndexThenName) ArrayList(java.util.ArrayList) NamedValue(com.zimbra.soap.type.NamedValue) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZAttributes(com.zimbra.cs.ldap.ZAttributes) HABGroupMember(com.zimbra.soap.account.type.HABGroupMember)

Example 3 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.

the class LdapProvisioning method createZimlet.

@Override
public Zimlet createZimlet(String name, Map<String, Object> zimletAttrs) throws ServiceException {
    name = name.toLowerCase().trim();
    CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
    AttributeManager.getInstance().preModify(zimletAttrs, null, callbackContext, true);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_ZIMLET);
        String hasKeyword = LdapConstants.LDAP_FALSE;
        if (zimletAttrs.containsKey(A_zimbraZimletKeyword)) {
            hasKeyword = ProvisioningConstants.TRUE;
        }
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.mapToAttrs(zimletAttrs);
        entry.setAttr(A_objectClass, "zimbraZimletEntry");
        entry.setAttr(A_zimbraZimletEnabled, ProvisioningConstants.FALSE);
        entry.setAttr(A_zimbraZimletIndexingEnabled, hasKeyword);
        entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
        String dn = mDIT.zimletNameToDN(name);
        entry.setDN(dn);
        zlc.createEntry(entry);
        Zimlet zimlet = lookupZimlet(name, zlc);
        AttributeManager.getInstance().postModify(zimletAttrs, zimlet, callbackContext);
        return zimlet;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.ZIMLET_EXISTS(name);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to create zimlet: " + name, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) Zimlet(com.zimbra.cs.account.Zimlet) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) LdapException(com.zimbra.cs.ldap.LdapException) Date(java.util.Date)

Example 4 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.

the class LdapProvisioning method createUCService.

@Override
public UCService createUCService(String name, Map<String, Object> attrs) throws ServiceException {
    name = name.toLowerCase().trim();
    CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
    AttributeManager.getInstance().preModify(attrs, null, callbackContext, true);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_UCSERVICE);
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.mapToAttrs(attrs);
        Set<String> ocs = LdapObjectClass.getUCServiceObjectClasses(this);
        entry.addAttr(A_objectClass, ocs);
        String zimbraIdStr = LdapUtil.generateUUID();
        entry.setAttr(A_zimbraId, zimbraIdStr);
        entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
        entry.setAttr(A_cn, name);
        String dn = mDIT.ucServiceNameToDN(name);
        entry.setDN(dn);
        zlc.createEntry(entry);
        UCService ucService = getUCServiceById(zimbraIdStr, zlc, true);
        AttributeManager.getInstance().postModify(attrs, ucService, callbackContext);
        return ucService;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.SERVER_EXISTS(name);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to create ucservice: " + name, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) LdapUCService(com.zimbra.cs.account.ldap.entry.LdapUCService) UCService(com.zimbra.cs.account.UCService) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) LdapException(com.zimbra.cs.ldap.LdapException) Date(java.util.Date)

Example 5 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext in project zm-mailbox by Zimbra.

the class LdapProvisioning method dlIsInDynamicHABGroup.

public boolean dlIsInDynamicHABGroup(DynamicGroup group, List<String> dlsToCheck) {
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.REPLICA, LdapUsage.GET_GROUP_MEMBER);
        String[] memberDNs = group.getMultiAttr(Provisioning.A_member);
        final String[] attrsToGet = new String[] { Provisioning.A_mail, Provisioning.A_zimbraMailAlias };
        for (String memberDN : memberDNs) {
            ZAttributes memberAttrs = zlc.getAttributes(memberDN, attrsToGet);
            if (memberAttrs != null && dlsToCheck != null) {
                for (String dlToCheck : dlsToCheck) {
                    if (memberAttrs.hasAttributeValue(Provisioning.A_mail, dlToCheck) || memberAttrs.hasAttributeValue(Provisioning.A_zimbraMailAlias, dlToCheck)) {
                        return Boolean.TRUE;
                    }
                }
            }
        }
    } catch (ServiceException e) {
        ZimbraLog.account.warn("unable to get dynamic group members", e);
    } finally {
        LdapClient.closeContext(zlc);
    }
    return Boolean.FALSE;
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZAttributes(com.zimbra.cs.ldap.ZAttributes)

Aggregations

ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)126 ServiceException (com.zimbra.common.service.ServiceException)65 AccountServiceException (com.zimbra.cs.account.AccountServiceException)62 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)60 LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)23 LdapException (com.zimbra.cs.ldap.LdapException)22 ZMutableEntry (com.zimbra.cs.ldap.ZMutableEntry)21 Domain (com.zimbra.cs.account.Domain)19 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)18 CallbackContext (com.zimbra.cs.account.callback.CallbackContext)16 Date (java.util.Date)16 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)14 HashMap (java.util.HashMap)14 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)13 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)12 Account (com.zimbra.cs.account.Account)11 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)11 ZAttributes (com.zimbra.cs.ldap.ZAttributes)10 HashSet (java.util.HashSet)10 GuestAccount (com.zimbra.cs.account.GuestAccount)9