use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method getAttrsInOCs.
@Override
public void getAttrsInOCs(String[] ocs, Set<String> attrsInOCs) throws ServiceException {
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.GET_SCHEMA);
ZLdapSchema schema = zlc.getSchema();
for (String oc : ocs) {
try {
ZLdapSchema.ZObjectClassDefinition ocSchema = schema.getObjectClass(oc);
if (ocSchema != null) {
List<String> optAttrs = ocSchema.getOptionalAttributes();
for (String attr : optAttrs) {
attrsInOCs.add(attr);
}
List<String> reqAttrs = ocSchema.getRequiredAttributes();
for (String attr : reqAttrs) {
attrsInOCs.add(attr);
}
}
} catch (ServiceException e) {
ZimbraLog.account.debug("unable to lookup attributes for objectclass: " + oc, e);
}
}
} catch (ServiceException e) {
ZimbraLog.account.warn("unable to get LDAP schema", e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method createShareLocator.
@Override
public ShareLocator createShareLocator(String id, Map<String, Object> attrs) throws ServiceException {
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_SHARELOCATOR);
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(attrs);
Set<String> ocs = LdapObjectClass.getShareLocatorObjectClasses(this);
entry.addAttr(A_objectClass, ocs);
entry.setAttr(A_cn, id);
String dn = mDIT.shareLocatorIdToDN(id);
entry.setDN(dn);
zlc.createEntry(entry);
ShareLocator shloc = getShareLocatorById(id, zlc, true);
AttributeManager.getInstance().postModify(attrs, shloc, callbackContext);
return shloc;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.SHARE_LOCATOR_EXISTS(id);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to create share locator: " + id, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method getGroupByQuery.
private Group getGroupByQuery(ZLdapFilter filter, ZLdapContext initZlc, boolean basicAttrsOnly, boolean loadFromMaster) throws ServiceException {
try {
String[] returnAttrs = basicAttrsOnly ? BASIC_GROUP_ATTRS : null;
ZSearchResultEntry sr = helper.searchForEntry(mDIT.mailBranchBaseDN(), filter, initZlc, loadFromMaster, returnAttrs);
if (sr != null) {
ZAttributes attrs = sr.getAttributes();
List<String> objectclass = attrs.getMultiAttrStringAsList(Provisioning.A_objectClass, CheckBinary.NOCHECK);
if (objectclass.contains(AttributeClass.OC_zimbraDistributionList)) {
return makeDistributionList(sr.getDN(), attrs, basicAttrsOnly);
} else if (objectclass.contains(AttributeClass.OC_zimbraGroup)) {
return makeDynamicGroup(initZlc, sr.getDN(), attrs);
}
}
} catch (LdapMultipleEntriesMatchedException e) {
throw AccountServiceException.MULTIPLE_ENTRIES_MATCHED("getGroupByQuery", 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 getUCServiceByName.
private UCService getUCServiceByName(String name, boolean nocache) throws ServiceException {
if (!nocache) {
UCService s = ucServiceCache.getByName(name);
if (s != null) {
return s;
}
}
try {
String dn = mDIT.ucServiceNameToDN(name);
ZAttributes attrs = helper.getAttributes(LdapUsage.GET_UCSERVICE, dn);
LdapUCService s = new LdapUCService(dn, attrs, this);
ucServiceCache.put(s);
return s;
} catch (LdapEntryNotFoundException e) {
return null;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup ucservice by name: " + name + " message: " + e.getMessage(), e);
}
}
use of com.zimbra.common.service.ServiceException in project zm-mailbox by Zimbra.
the class LdapProvisioning method deleteDomain.
private void deleteDomain(String zimbraId, boolean deleteDomainAliases) throws ServiceException {
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_DOMAIN);
Domain domain = getDomainById(zimbraId, zlc);
if (domain == null) {
throw AccountServiceException.NO_SUCH_DOMAIN(zimbraId);
}
if (deleteDomainAliases) {
List<String> aliasDomainIds = null;
if (domain.isLocal()) {
aliasDomainIds = getEmptyAliasDomainIds(zlc, domain, true);
}
// delete all alias domains if any
if (aliasDomainIds != null) {
for (String aliasDomainId : aliasDomainIds) {
deleteDomainInternal(zlc, aliasDomainId);
}
}
}
// delete the domain;
deleteDomainInternal(zlc, zimbraId);
} catch (ServiceException e) {
throw e;
} finally {
LdapClient.closeContext(zlc);
}
}
Aggregations