use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvSearchDirectory method CMBSearchNonSystemResourceAccountsOnly.
@Test
public void CMBSearchNonSystemResourceAccountsOnly() throws Exception {
Account acct1 = createAccount(genAcctNameLocalPart("1"));
Map<String, Object> acct2Attrs = Maps.newHashMap();
acct2Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "TRUE");
Account acct2 = createAccount(genAcctNameLocalPart("2"), acct2Attrs);
Map<String, Object> acct3Attrs = Maps.newHashMap();
acct3Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "FALSE");
Account acct3 = createAccount(genAcctNameLocalPart("3"), acct3Attrs);
Map<String, Object> acct4Attrs = Maps.newHashMap();
acct4Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "FALSE");
acct4Attrs.put(Provisioning.A_zimbraIsSystemResource, "TRUE");
Account acct4 = createAccount(genAcctNameLocalPart("4"), acct4Attrs);
Map<String, Object> acct5Attrs = Maps.newHashMap();
acct5Attrs.put(Provisioning.A_zimbraExcludeFromCMBSearch, "FALSE");
acct5Attrs.put(Provisioning.A_zimbraIsSystemResource, "FALSE");
Account acct5 = createAccount(genAcctNameLocalPart("5"), acct5Attrs);
String[] returnAttrs = { Provisioning.A_displayName, Provisioning.A_zimbraId, Provisioning.A_uid, Provisioning.A_zimbraArchiveAccount, Provisioning.A_zimbraMailHost };
// use domain so our assertion will work, production code does not a domain
SearchAccountsOptions searchOpts = new SearchAccountsOptions(domain, returnAttrs);
searchOpts.setIncludeType(IncludeType.ACCOUNTS_ONLY);
searchOpts.setSortOpt(SortOpt.SORT_DESCENDING);
ZLdapFilter filter = ZLdapFilterFactory.getInstance().CMBSearchNonSystemResourceAccountsOnly();
searchOpts.setFilter(filter);
List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
Verify.verifyEquals(Lists.newArrayList(acct5, acct3, acct1), accounts, true);
deleteAccount(acct1);
deleteAccount(acct2);
deleteAccount(acct3);
deleteAccount(acct4);
deleteAccount(acct5);
/*
// legacy code and LDAP trace before refactoring
List<NamedEntry> accounts = prov.searchAccounts(
"(&(!(" + Provisioning.A_zimbraIsSystemResource + "=*))(|(!(" +
Provisioning.A_zimbraExcludeFromCMBSearch + "=*))(" +
Provisioning.A_zimbraExcludeFromCMBSearch + "=FALSE)))",
returnAttrs, null, false, Provisioning.searchDirectoryStringToMask("accounts"));
Oct 9 14:55:09 pshao-macbookpro-2 slapd[73952]: conn=1352 op=172 SRCH base="" scope=2 deref=0 filter="(&(&(!(zimbraIsSystemResource=*))(|(!(zimbraExcludeFromCMBSearch=*))(zimbraExcludeFromCMBSearch=FALSE)))(&(objectClass=zimbraAccount)(!(objectClass=zimbraCalendarResource))))"
Oct 9 14:55:09 pshao-macbookpro-2 slapd[73952]: conn=1352 op=172 SRCH attr=zimbraCOSId objectClass zimbraDomainName zimbraACE displayName zimbraId uid zimbraArchiveAccount zimbraMailHost
*/
/*
* LDAP trace after reactoring
*
Oct 9 16:18:04 pshao-macbookpro-2 slapd[73952]: conn=1381 op=127 SRCH base="ou=people,dc=com,dc=zimbra,dc=qa,dc=unittest,dc=testldapprovaccount" scope=2 deref=0 filter="(&(&(objectClass=zimbraAccount)(!(objectClass=zimbraCalendarResource)))(!(zimbraIsSystemResource=TRUE))(|(!(zimbraExcludeFromCMBSearch=*))(zimbraExcludeFromCMBSearch=FALSE)))"
Oct 9 16:18:04 pshao-macbookpro-2 slapd[73952]: conn=1381 op=127 SRCH attr=zimbraCOSId objectClass zimbraDomainName zimbraACE displayName zimbraId uid zimbraArchiveAccount zimbraMailHost
*/
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvRenameDomain method verifyMemberOf.
private void verifyMemberOf(int memberType, int dlTypes, int domainIdx) throws Exception {
for (int i = 0; i < NUM_OBJS(memberType); i++) {
String name = OBJ_NAME(memberType, i, domainIdx);
NamedEntry entry = getEntryByName(memberType, name);
assertNotNull(entry);
Set<String> expectedNames = new HashSet<String>();
for (int d = 0; d < NUM_DOMAINS; d++) {
int dIdx = DOMAIN_INDEX_AFTER_RENAME(d);
if ((dlTypes & OBJ_DL_NESTED) != 0) {
for (int dlIdx = 0; dlIdx < NUM_DLS_NESTED; dlIdx++) expectedNames.add(new Names.IDNName(NESTED_DL_NAME(dlIdx, dIdx)).aName());
}
if ((dlTypes & OBJ_DL_TOP) != 0) {
for (int dlIdx = 0; dlIdx < NUM_DLS_TOP; dlIdx++) expectedNames.add(new Names.IDNName(TOP_DL_NAME(dlIdx, dIdx)).aName());
}
// todo: DYNAMIC GROUP
}
HashMap<String, String> via = new HashMap<String, String>();
List lists;
if (memberType == OBJ_ACCT) {
lists = prov.getDistributionLists((Account) entry, false, via);
} else {
lists = prov.getDistributionLists((DistributionList) entry, false, via);
}
Set<String> actualNames = namedEntryListToNameSet(lists, UnicodeOrACE.ACE);
// dumpStrings(expectedNames);
// dumpStrings(actualNames);
Verify.verifyEquals(expectedNames, actualNames);
}
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestLdapProvRenameDomain method dumpNames.
private void dumpNames(String desc, List<NamedEntry> entries) {
System.out.println();
System.out.println("===== " + ((desc == null) ? "" : desc) + " =====");
for (NamedEntry entry : entries) System.out.println(entry.getName());
System.out.println();
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class CheckRights method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
List<RequestedTarget> requestedTargets = Lists.newArrayList();
for (Element eTarget : request.listElements(AccountConstants.E_TARGET)) {
TargetType targetType = TargetType.fromCode(eTarget.getAttribute(AccountConstants.A_TYPE));
TargetBy targetBy = TargetBy.fromString(eTarget.getAttribute(AccountConstants.A_BY));
String key = eTarget.getAttribute(AccountConstants.A_KEY);
Entry entry = findEntry(prov, targetType, targetBy, key);
RequestedTarget target = new RequestedTarget(entry, targetType, targetBy, key);
requestedTargets.add(target);
for (Element eRight : eTarget.listElements(AccountConstants.E_RIGHT)) {
// can only be user right, not admim rights
target.addRight(RightManager.getInstance().getUserRight(eRight.getText()));
}
if (target.getRights().size() == 0) {
throw ServiceException.INVALID_REQUEST("missing right for target: " + key, null);
}
}
Element response = zsc.createElement(AccountConstants.CHECK_RIGHTS_RESPONSE);
AccessManager accessMgr = AccessManager.getInstance();
for (RequestedTarget target : requestedTargets) {
Entry targetEntry = target.getTargetEntry();
Element eTarget = response.addElement(AccountConstants.E_TARGET);
eTarget.addAttribute(AccountConstants.A_TYPE, target.getTargetType().getCode());
eTarget.addAttribute(AccountConstants.A_BY, target.getTargetBy().name());
eTarget.addAttribute(AccountConstants.A_KEY, target.getTargetKey());
boolean combinedResult = true;
for (UserRight right : target.getRights()) {
boolean allow = accessMgr.canDo(zsc.getAuthToken(), targetEntry, right, false);
if (allow && DiscoverRights.isDelegatedSendRight(right) && TargetBy.name == target.getTargetBy()) {
allow = AccountUtil.isAllowedSendAddress((NamedEntry) targetEntry, target.getTargetKey());
}
eTarget.addElement(AccountConstants.E_RIGHT).addAttribute(AccountConstants.A_ALLOW, allow).setText(right.getName());
combinedResult = combinedResult & allow;
}
eTarget.addAttribute(AccountConstants.A_ALLOW, combinedResult);
}
return response;
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class DiscoverRights method discoverRights.
public static void discoverRights(Account account, Set<Right> rights, Element eParent, boolean onMaster) throws ServiceException {
AccessManager accessMgr = AccessManager.getInstance();
Map<Right, Set<Entry>> discoveredRights = accessMgr.discoverUserRights(account, rights, onMaster);
Locale locale = account.getLocale();
for (Map.Entry<Right, Set<Entry>> targetsForRight : discoveredRights.entrySet()) {
Right right = targetsForRight.getKey();
Set<Entry> targets = targetsForRight.getValue();
List<Entry> sortedTargets = Entry.sortByDisplayName(targets, locale);
boolean isDelegatedSendRight = isDelegatedSendRight(right);
Element eTargets = eParent.addElement(AccountConstants.E_TARGETS);
eTargets.addAttribute(AccountConstants.A_RIGHT, right.getName());
for (Entry target : sortedTargets) {
TargetType targetType = TargetType.getTargetType(target);
Element eTarget = eTargets.addElement(AccountConstants.E_TARGET);
eTarget.addAttribute(AccountConstants.A_TYPE, targetType.getCode());
if (isDelegatedSendRight) {
if (target instanceof Account || target instanceof Group) {
String[] addrs = AccountUtil.getAllowedSendAddresses((NamedEntry) target);
NamedEntry entry = (NamedEntry) target;
for (String addr : addrs) {
Element eEmail = eTarget.addElement(AccountConstants.E_EMAIL);
eEmail.addAttribute(AccountConstants.A_ADDR, addr);
}
if (target instanceof Account) {
eTarget.addAttribute(AccountConstants.A_DISPLAY, ((Account) entry).getDisplayName());
} else if (target instanceof Group) {
eTarget.addAttribute(AccountConstants.A_DISPLAY, ((Group) entry).getDisplayName());
}
} else {
throw ServiceException.FAILURE("internal error, target for " + " delegated send rights must be account or group", null);
}
} else {
if (target instanceof NamedEntry) {
NamedEntry entry = (NamedEntry) target;
eTarget.addAttribute(AccountConstants.A_ID, entry.getId());
eTarget.addAttribute(AccountConstants.A_NAME, entry.getName());
if (target instanceof Account) {
eTarget.addAttribute(AccountConstants.A_DISPLAY, ((Account) entry).getDisplayName());
} else if (target instanceof Group) {
eTarget.addAttribute(AccountConstants.A_DISPLAY, ((Group) entry).getDisplayName());
}
} else {
eTarget.addAttribute(AccountConstants.A_NAME, target.getLabel());
}
}
}
}
}
Aggregations