use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method getDynamicGroupByQuery.
private DynamicGroup getDynamicGroupByQuery(ZLdapFilter filter, ZLdapContext initZlc, boolean basicAttrsOnly) throws ServiceException {
try {
String[] returnAttrs = basicAttrsOnly ? BASIC_DYNAMIC_GROUP_ATTRS : null;
ZSearchResultEntry sr = helper.searchForEntry(mDIT.mailBranchBaseDN(), filter, initZlc, false, returnAttrs);
if (sr != null) {
return makeDynamicGroup(initZlc, sr.getDN(), sr.getAttributes());
}
} catch (LdapMultipleEntriesMatchedException e) {
throw AccountServiceException.MULTIPLE_ENTRIES_MATCHED("getDynamicGroupByQuery", e);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup group via query: " + filter.toFilterString() + " message:" + e.getMessage(), e);
}
return null;
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method getDNforAccountById.
public String getDNforAccountById(String zimbraId, ZLdapContext zlc, boolean loadFromMaster) {
if (zimbraId == null) {
return null;
}
ZLdapFilter filter = filterFactory.accountById(zimbraId);
try {
String[] retAttrs = new String[] { Provisioning.A_zimbraId };
/* Just 1 attr to save bandwidth */
ZSearchResultEntry sr;
sr = getSearchResultForAccountByQuery(mDIT.mailBranchBaseDN(), filter, zlc, loadFromMaster, retAttrs);
// search again under the admin base if not found and admin base is not under mail base
if (sr == null && !mDIT.isUnder(mDIT.mailBranchBaseDN(), mDIT.adminBaseDN())) {
sr = getSearchResultForAccountByQuery(mDIT.adminBaseDN(), filter, zlc, loadFromMaster, retAttrs);
}
if (sr != null) {
return sr.getDN();
}
} catch (ServiceException e) {
ZimbraLog.search.debug("unable to lookup DN for account via query: %s", filter.toFilterString(), e);
}
return null;
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method renameUCService.
@Override
public void renameUCService(String zimbraId, String newName) throws ServiceException {
LdapUCService ucService = (LdapUCService) getUCServiceById(zimbraId, null, false);
if (ucService == null) {
throw AccountServiceException.NO_SUCH_UC_SERVICE(zimbraId);
}
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.RENAME_UCSERVICE);
String newDn = mDIT.ucServiceNameToDN(newName);
zlc.renameEntry(ucService.getDN(), newDn);
ucServiceCache.remove(ucService);
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.UC_SERVICE_EXISTS(newName);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to rename ucservice: " + zimbraId, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.common.service.ServiceException 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.common.service.ServiceException in project zm-mailbox by Zimbra.
the class BUG_18277 method getAllDomainOrGlobalAdmins.
private void getAllDomainOrGlobalAdmins(Set<String> domainAdminIds, Set<String> globalAdminIds) throws ServiceException {
LdapDIT dit = prov.getDIT();
String[] returnAttrs = new String[] { Provisioning.A_objectClass, Provisioning.A_zimbraId, Provisioning.A_zimbraIsAdminAccount, Provisioning.A_zimbraIsDomainAdminAccount, Provisioning.A_zimbraIsDelegatedAdminAccount };
String configBranchBaseDn = dit.configBranchBaseDN();
String base = dit.mailBranchBaseDN();
String query = "(&(objectclass=zimbraAccount)(|(zimbraIsDomainAdminAccount=TRUE)(zimbraIsAdminAccount=TRUE)))";
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.UPGRADE);
Bug18277Visitor visitor = new Bug18277Visitor(this, configBranchBaseDn, domainAdminIds, globalAdminIds);
SearchLdapOptions searchOpts = new SearchLdapOptions(base, getFilter(query), returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
zlc.searchPaged(searchOpts);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to list all objects", e);
} finally {
LdapClient.closeContext(zlc);
}
}
Aggregations