Search in sources :

Example 81 with ZLdapContext

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

the class LdapProvisioning method searchDynamicGroupMembers.

/*
     * returns all internal and external member addresses of the DynamicGroup
     */
private List<String> searchDynamicGroupMembers(DynamicGroup group) throws ServiceException {
    if (group.isMembershipDefinedByCustomURL()) {
        throw ServiceException.INVALID_REQUEST("cannot search members to dynamic group with custom memberURL", null);
    }
    final List<String> members = Lists.newArrayList();
    ZLdapContext zlc = null;
    try {
        // always use master to search for dynamic group members
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.SEARCH);
        // search internal members
        searchDynamicGroupInternalMemberDeliveryAddresses(zlc, group.getId(), members);
        // add external members
        LdapDynamicGroup.StaticUnit staticUnit = ((LdapDynamicGroup) group).getStaticUnit();
        // need to refresh, the StaticUnit instance updated by add/remove
        // dynamic group members may be the cached instance.
        refreshEntry(staticUnit, zlc);
        for (String extAddr : staticUnit.getMembers()) {
            members.add(extAddr);
        }
    } catch (ServiceException e) {
        ZimbraLog.account.warn("unable to search dynamic group members", e);
    } finally {
        LdapClient.closeContext(zlc);
    }
    return members;
}
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) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)

Example 82 with ZLdapContext

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

the class LdapProvisioning method reload.

@Override
public void reload(Entry e, boolean master) throws ServiceException {
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.get(master), LdapUsage.GET_ENTRY);
        refreshEntry(e, zlc);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext)

Example 83 with ZLdapContext

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

the class LdapProvisioning method deleteZimlet.

@Override
public void deleteZimlet(String name) throws ServiceException {
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_ZIMLET);
        LdapZimlet zimlet = (LdapZimlet) getZimlet(name, zlc, true);
        if (zimlet != null) {
            zimletCache.remove(zimlet);
            zlc.deleteEntry(zimlet.getDN());
        }
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to delete zimlet: " + name, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
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) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet)

Example 84 with ZLdapContext

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

the class LdapProvisioning method renameIdentity.

private void renameIdentity(LdapEntry entry, LdapIdentity identity, String newIdentityName) throws ServiceException {
    if (identity.getName().equalsIgnoreCase(ProvisioningConstants.DEFAULT_IDENTITY_NAME))
        throw ServiceException.INVALID_REQUEST("can't rename default identity", null);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.RENAME_IDENTITY);
        String newDn = getIdentityDn(entry, newIdentityName);
        zlc.renameEntry(identity.getDN(), newDn);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to rename identity: " + newIdentityName, e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
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)

Example 85 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, boolean cascadeDelete) throws ServiceException {
    // check if cascadeDelete is true. If it's true, delete all subgroups.
    if (dl.isHABGroup()) {
        if (cascadeDelete) {
            Set<String> members = dl.getAllMembersSet();
            for (String member : members) {
                LdapDistributionList subDl = (LdapDistributionList) getDistributionListByNameInternal(member);
                if (subDl != null && subDl.isHABGroup()) {
                    deleteDistributionList(subDl, cascadeDelete);
                } else {
                    DynamicGroup dg = getDynamicGroupBasic(DistributionListBy.name, member, LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_DYNAMICGROUP));
                    if (dg != null && dg.isHABGroup()) {
                        deleteDynamicGroup((LdapDynamicGroup) dg);
                    }
                }
            }
        } else {
            if (dl.getAllMembers().length > 0) {
                throw ServiceException.INVALID_REQUEST("Can not delete hab group when members are present in group.", null);
            }
        }
    }
    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 all groups 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 : DynamicGroup(com.zimbra.cs.account.DynamicGroup) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) 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) LdapDistributionList(com.zimbra.cs.account.ldap.entry.LdapDistributionList) HashSet(java.util.HashSet)

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