use of com.zimbra.cs.account.ldap.LdapProv in project zm-mailbox by Zimbra.
the class TestLdap method deleteAllNonDefaultCoses.
private static void deleteAllNonDefaultCoses() throws Exception {
LdapDIT dit = ((LdapProv) Provisioning.getInstance()).getDIT();
String cosBaseDN = dit.cosBaseDN();
Set<String> defaultCosDN = new HashSet<String>();
defaultCosDN.add(dit.cosNametoDN(Provisioning.DEFAULT_COS_NAME));
defaultCosDN.add(dit.cosNametoDN(Provisioning.DEFAULT_EXTERNAL_COS_NAME));
deleteAllChildrenUnderDN(cosBaseDN, defaultCosDN);
}
use of com.zimbra.cs.account.ldap.LdapProv in project zm-mailbox by Zimbra.
the class TestObjectClass method getMostSpecificOC.
@Test
public void getMostSpecificOC() throws Exception {
LdapProv ldapProv = (LdapProv) prov;
assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "zimbraAccount", "organizationalPerson", "person" }, "inetOrgPerson"));
assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "inetOrgPerson" }, "organizationalPerson"));
assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "organizationalPerson", "inetOrgPerson" }, "person"));
assertEquals("bbb", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "inetOrgPerson" }, "bbb"));
assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "aaa" }, "inetOrgPerson"));
assertEquals("inetOrgPerson", LdapObjectClassHierarchy.getMostSpecificOC(ldapProv, new String[] { "person", "inetOrgPerson" }, "organizationalPerson"));
}
use of com.zimbra.cs.account.ldap.LdapProv in project zm-mailbox by Zimbra.
the class ProvUtil method lookupAccount.
private Account lookupAccount(String key, boolean mustFind, boolean applyDefault) throws ServiceException {
Account account;
if (applyDefault == true || (prov instanceof LdapProv)) {
account = prov.getAccount(key);
} else {
/*
* oops, do not apply default, and we are SoapProvisioning
*
* This a bit awkward because the applyDefault is controlled at the Entry.getAttrs, not at the provisioning
* interface. But for SOAP, this needs to be passed to the get(AccountBy) method so it can set the flag in
* SOAP. We do not want to add a provisioning method for this. Instead, we make it a SOAPProvisioning only
* method.
*/
SoapProvisioning soapProv = (SoapProvisioning) prov;
account = soapProv.getAccount(key, applyDefault);
}
if (mustFind && account == null) {
throw AccountServiceException.NO_SUCH_ACCOUNT(key);
} else {
return account;
}
}
use of com.zimbra.cs.account.ldap.LdapProv in project zm-mailbox by Zimbra.
the class ProvUtil method doSearchAccounts.
private void doSearchAccounts(String[] args) throws ServiceException, ArgException {
boolean verbose = false;
int i = 1;
if (args[i].equals("-v")) {
verbose = true;
i++;
if (args.length < i - 1) {
usage();
return;
}
}
if (args.length < i + 1) {
usage();
return;
}
String query = args[i];
Map<String, Object> attrs = getMap(args, i + 1);
String limitStr = (String) attrs.get("limit");
int limit = limitStr == null ? Integer.MAX_VALUE : Integer.parseInt(limitStr);
String offsetStr = (String) attrs.get("offset");
int offset = offsetStr == null ? 0 : Integer.parseInt(offsetStr);
String sortBy = (String) attrs.get("sortBy");
String sortAscending = (String) attrs.get("sortAscending");
boolean isSortAscending = (sortAscending != null) ? "1".equalsIgnoreCase(sortAscending) : true;
String[] attrsToGet = null;
String typesStr = (String) attrs.get("types");
if (typesStr == null) {
typesStr = SearchDirectoryOptions.ObjectType.accounts.name() + "," + SearchDirectoryOptions.ObjectType.aliases.name() + "," + SearchDirectoryOptions.ObjectType.distributionlists.name() + "," + SearchDirectoryOptions.ObjectType.dynamicgroups.name() + "," + SearchDirectoryOptions.ObjectType.resources.name();
}
String domainStr = (String) attrs.get("domain");
SearchDirectoryOptions searchOpts = new SearchDirectoryOptions(attrsToGet);
if (domainStr != null) {
Domain d = lookupDomain(domainStr, prov);
searchOpts.setDomain(d);
}
searchOpts.setTypes(typesStr);
searchOpts.setSortOpt(isSortAscending ? SortOpt.SORT_ASCENDING : SortOpt.SORT_DESCENDING);
searchOpts.setSortAttr(sortBy);
// if LdapClient is not initialized(the case for SoapProvisioning), FilterId
// is not initialized. Use null for SoapProvisioning, it will be set to
// FilterId.ADMIN_SEARCH in SearchDirectory soap handler.
FilterId filterId = (prov instanceof LdapProv) ? FilterId.ADMIN_SEARCH : null;
searchOpts.setFilterString(filterId, query);
// query must be already RFC 2254 escaped
searchOpts.setConvertIDNToAscii(true);
List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
for (int j = offset; j < offset + limit && j < accounts.size(); j++) {
NamedEntry account = accounts.get(j);
if (verbose) {
if (account instanceof Account) {
dumpAccount((Account) account, true, null);
} else if (account instanceof Alias) {
dumpAlias((Alias) account);
} else if (account instanceof DistributionList) {
dumpGroup((DistributionList) account, null);
} else if (account instanceof Domain) {
dumpDomain((Domain) account, null);
}
} else {
console.println(account.getName());
}
}
}
use of com.zimbra.cs.account.ldap.LdapProv in project zm-mailbox by Zimbra.
the class ForeignPrincipal method preModify.
@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
if (entry == null || context.isCreate()) {
return;
}
if (!(entry instanceof Account))
return;
Provisioning prov = Provisioning.getInstance();
if (!(prov instanceof LdapProv))
return;
Account acct = (Account) entry;
((LdapProv) prov).removeFromCache(acct);
}
Aggregations