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;
}
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);
}
}
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);
}
}
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);
}
}
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();
}
Aggregations