use of com.zimbra.soap.account.type.HABGroupMember 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.soap.account.type.HABGroupMember in project zm-mailbox by Zimbra.
the class LdapProvisioning method getHABGroupMemberDetails.
/**
* get members of static group and member details
* @param group
* @return
*/
public List<HABGroupMember> getHABGroupMemberDetails(Group group) {
final List<HABGroupMember> members = Lists.newArrayList();
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.REPLICA, LdapUsage.GET_GROUP_MEMBER);
String[] memberEmails = null;
DistributionList dl = get(DistributionListBy.id, group.getId());
memberEmails = dl.getMultiAttr(Provisioning.A_zimbraMailForwardingAddress);
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]));
for (String memberEmail : memberEmails) {
Account memberAcc = null;
try {
memberAcc = get(AccountBy.name, memberEmail);
} catch (ServiceException e) {
ZimbraLog.account.debug("not a direct member of hab group %s", memberEmail, e);
}
if (memberAcc != null) {
HABGroupMember habMember = new HABGroupMember(memberEmail);
for (String key : habMemberAttrMap.keySet()) {
if (Provisioning.A_zimbraMailAlias.equals(habMemberAttrMap.get(key))) {
String[] aliases = memberAcc.getAliases();
for (String alias : aliases) {
habMember.addAttr(new NamedValue(key, alias));
}
} else {
String val = memberAcc.getAttr(habMemberAttrMap.get(key));
if (StringUtils.isNotEmpty(val)) {
habMember.addAttr(new NamedValue(key, val));
}
}
}
int seniorityIndex = memberAcc.getHABSeniorityIndex();
if (seniorityIndex == -1) {
seniorityIndex = 0;
}
habMember.setSeniorityIndex(seniorityIndex);
members.add(habMember);
}
}
Collections.sort(members, new SortBySeniorityIndexThenName());
} catch (ServiceException e) {
ZimbraLog.account.debug("unable to get hab group members", e);
} finally {
LdapClient.closeContext(zlc);
}
return members;
}
use of com.zimbra.soap.account.type.HABGroupMember in project zm-mailbox by Zimbra.
the class LdapProvisioning method getHABGroupMembers.
@Override
public List<HABGroupMember> getHABGroupMembers(Group group) throws ServiceException {
List<HABGroupMember> members = null;
if (group.isHABGroup()) {
if (group instanceof DynamicGroup) {
DynamicGroup dynGroup = getDynamicGroup(Key.DistributionListBy.name, group.getName(), null, Boolean.FALSE);
members = getHABDynamicGroupMemberDetails(dynGroup);
} else {
members = getHABGroupMemberDetails(group);
}
}
return members;
}
Aggregations