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