use of com.zimbra.cs.ldap.LdapException in project zm-mailbox by Zimbra.
the class LdapProvisioning method createDistributionList.
private DistributionList createDistributionList(String listAddress, Map<String, Object> listAttrs, Account creator) throws ServiceException {
SpecialAttrs specialAttrs = mDIT.handleSpecialAttrs(listAttrs);
String baseDn = specialAttrs.getLdapBaseDn();
listAddress = listAddress.toLowerCase().trim();
String[] parts = listAddress.split("@");
if (parts.length != 2)
throw ServiceException.INVALID_REQUEST("must be valid list address: " + listAddress, null);
String localPart = parts[0];
String domain = parts[1];
domain = IDNUtil.toAsciiDomainName(domain);
listAddress = localPart + "@" + domain;
validEmailAddress(listAddress);
CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
callbackContext.setCreatingEntryName(listAddress);
AttributeManager.getInstance().preModify(listAttrs, null, callbackContext, true);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_DISTRIBUTIONLIST);
Domain d = getDomainByAsciiName(domain, zlc);
if (d == null)
throw AccountServiceException.NO_SUCH_DOMAIN(domain);
if (!d.isLocal()) {
throw ServiceException.INVALID_REQUEST("domain type must be local", null);
}
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(listAttrs);
Set<String> ocs = LdapObjectClass.getDistributionListObjectClasses(this);
entry.addAttr(A_objectClass, ocs);
String zimbraIdStr = LdapUtil.generateUUID();
entry.setAttr(A_zimbraId, zimbraIdStr);
entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
entry.setAttr(A_mail, listAddress);
// unlike accounts (which have a zimbraMailDeliveryAddress for the primary,
// and zimbraMailAliases only for aliases), DLs use zibraMailAlias for both.
// Postfix uses these two attributes to route mail, and zimbraMailDeliveryAddress
// indicates that something has a physical mailbox, which DLs don't.
entry.setAttr(A_zimbraMailAlias, listAddress);
// by default a distribution list is always created enabled
if (!entry.hasAttribute(Provisioning.A_zimbraMailStatus)) {
entry.setAttr(A_zimbraMailStatus, MAIL_STATUS_ENABLED);
}
String displayName = entry.getAttrString(Provisioning.A_displayName);
if (displayName != null) {
entry.setAttr(A_cn, displayName);
}
entry.setAttr(A_uid, localPart);
setGroupHomeServer(entry, creator);
String dn = mDIT.distributionListDNCreate(baseDn, entry.getAttributes(), localPart, domain);
entry.setDN(dn);
zlc.createEntry(entry);
DistributionList dlist = getDLBasic(DistributionListBy.id, zimbraIdStr, zlc);
if (dlist != null) {
AttributeManager.getInstance().postModify(listAttrs, dlist, callbackContext);
removeExternalAddrsFromAllDynamicGroups(dlist.getAllAddrsSet(), zlc);
allDLs.addGroup(dlist);
} else {
throw ServiceException.FAILURE("unable to get distribution list after creating LDAP entry: " + listAddress, null);
}
return dlist;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.DISTRIBUTION_LIST_EXISTS(listAddress);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to create distribution list: " + listAddress, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.ldap.LdapException 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.cs.ldap.LdapException 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.cs.ldap.LdapException in project zm-mailbox by Zimbra.
the class UBIDLdapContext method init.
public static synchronized void init(boolean alwaysUseMaster) throws LdapException {
assert (!initialized);
if (initialized) {
return;
}
initialized = true;
try {
masterConfig = new ZimbraLdapConfig(LdapServerType.MASTER);
masterConnPool = LdapConnectionPool.createConnectionPool(LdapConnectionPool.CP_ZIMBRA_MASTER, masterConfig);
} catch (LdapException e) {
ZimbraLog.ldap.info("master is down, falling back to replica...");
replicaConfig = new ZimbraLdapConfig(LdapServerType.REPLICA);
replicaConnPool = LdapConnectionPool.createConnectionPool(LdapConnectionPool.CP_ZIMBRA_REPLICA, replicaConfig);
masterConfig = replicaConfig;
masterConnPool = replicaConnPool;
ZimbraLog.ldap.info("using replica");
}
if (alwaysUseMaster) {
replicaConfig = masterConfig;
replicaConnPool = masterConnPool;
} else {
if (replicaConfig == null) {
replicaConfig = new ZimbraLdapConfig(LdapServerType.REPLICA);
}
if (replicaConnPool == null) {
replicaConnPool = LdapConnectionPool.createConnectionPool(LdapConnectionPool.CP_ZIMBRA_REPLICA, replicaConfig);
}
}
}
use of com.zimbra.cs.ldap.LdapException in project zm-mailbox by Zimbra.
the class LdapProvisioning method createIdentity.
private Identity createIdentity(Account account, String identityName, Map<String, Object> identityAttrs, boolean restoring) throws ServiceException {
removeAttrIgnoreCase("objectclass", identityAttrs);
validateIdentityAttrs(identityAttrs);
LdapEntry ldapEntry = (LdapEntry) (account instanceof LdapEntry ? account : getAccountById(account.getId()));
if (ldapEntry == null)
throw AccountServiceException.NO_SUCH_ACCOUNT(account.getName());
if (identityName.equalsIgnoreCase(ProvisioningConstants.DEFAULT_IDENTITY_NAME))
throw AccountServiceException.IDENTITY_EXISTS(identityName);
List<Identity> existing = getAllIdentities(account);
if (existing.size() >= account.getLongAttr(A_zimbraIdentityMaxNumEntries, 20))
throw AccountServiceException.TOO_MANY_IDENTITIES();
account.setCachedData(IDENTITY_LIST_CACHE_KEY, null);
boolean checkImmutable = !restoring;
CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
AttributeManager.getInstance().preModify(identityAttrs, null, callbackContext, checkImmutable);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_IDENTITY);
String dn = getIdentityDn(ldapEntry, identityName);
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.setDN(dn);
entry.mapToAttrs(identityAttrs);
entry.setAttr(A_objectClass, "zimbraIdentity");
if (!entry.hasAttribute(A_zimbraPrefIdentityId)) {
String identityId = LdapUtil.generateUUID();
entry.setAttr(A_zimbraPrefIdentityId, identityId);
}
entry.setAttr(Provisioning.A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
zlc.createEntry(entry);
Identity identity = getIdentityByName(ldapEntry, identityName, zlc);
AttributeManager.getInstance().postModify(identityAttrs, identity, callbackContext);
return identity;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.IDENTITY_EXISTS(identityName);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to create identity " + identityName, e);
} finally {
LdapClient.closeContext(zlc);
}
}
Aggregations