use of com.zimbra.cs.account.callback.CallbackContext in project zm-mailbox by Zimbra.
the class LdapProvisioning method copyCos.
private Cos copyCos(String srcCosId, String destCosName, Map<String, Object> cosAttrs) throws ServiceException {
destCosName = destCosName.toLowerCase().trim();
Cos srcCos = getCosById(srcCosId, null);
if (srcCos == null)
throw AccountServiceException.NO_SUCH_COS(srcCosId);
// bug 67716, use a case insensitive map because provided attr names may not be
// the canonical name and that will cause multiple entries in the map
Map<String, Object> allAttrs = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER);
allAttrs.putAll(srcCos.getAttrs());
allAttrs.remove(Provisioning.A_objectClass);
allAttrs.remove(Provisioning.A_zimbraId);
allAttrs.remove(Provisioning.A_zimbraCreateTimestamp);
allAttrs.remove(Provisioning.A_zimbraACE);
allAttrs.remove(Provisioning.A_cn);
allAttrs.remove(Provisioning.A_description);
if (cosAttrs != null) {
for (Map.Entry<String, Object> e : cosAttrs.entrySet()) {
String attr = e.getKey();
Object value = e.getValue();
if (value instanceof String && Strings.isNullOrEmpty((String) value)) {
allAttrs.remove(attr);
} else {
allAttrs.put(attr, value);
}
}
}
CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
//get rid of deprecated attrs
Map<String, Object> allNewAttrs = new HashMap<String, Object>(allAttrs);
for (String attr : allAttrs.keySet()) {
AttributeInfo info = AttributeManager.getInstance().getAttributeInfo(attr);
if (info != null && info.isDeprecated()) {
allNewAttrs.remove(attr);
}
}
allAttrs = allNewAttrs;
AttributeManager.getInstance().preModify(allAttrs, null, callbackContext, true);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_COS);
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(allAttrs);
Set<String> ocs = LdapObjectClass.getCosObjectClasses(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_cn, destCosName);
String dn = mDIT.cosNametoDN(destCosName);
entry.setDN(dn);
zlc.createEntry(entry);
Cos cos = getCosById(zimbraIdStr, zlc);
AttributeManager.getInstance().postModify(allAttrs, cos, callbackContext);
return cos;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.COS_EXISTS(destCosName);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to create cos: " + destCosName, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.account.callback.CallbackContext in project zm-mailbox by Zimbra.
the class LdapProvisioning method createCalendarResource.
@Override
public CalendarResource createCalendarResource(String emailAddress, String password, Map<String, Object> calResAttrs) throws ServiceException {
emailAddress = emailAddress.toLowerCase().trim();
calResAttrs.put(Provisioning.A_zimbraAccountCalendarUserType, AccountCalendarUserType.RESOURCE.toString());
SpecialAttrs specialAttrs = mDIT.handleSpecialAttrs(calResAttrs);
CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
Set<String> ocs = LdapObjectClass.getCalendarResourceObjectClasses(this);
Account acct = createAccount(emailAddress, password, calResAttrs, specialAttrs, ocs.toArray(new String[0]), false, null);
LdapCalendarResource resource = (LdapCalendarResource) getCalendarResourceById(acct.getId(), true);
AttributeManager.getInstance().postModify(calResAttrs, resource, callbackContext);
return resource;
}
use of com.zimbra.cs.account.callback.CallbackContext in project zm-mailbox by Zimbra.
the class LdapProvisioning method createDomain.
@Override
public Domain createDomain(String name, Map<String, Object> domainAttrs) throws ServiceException {
name = name.toLowerCase().trim();
name = IDNUtil.toAsciiDomainName(name);
NameUtil.validNewDomainName(name);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_DOMAIN);
LdapDomain d = (LdapDomain) getDomainByAsciiName(name, zlc);
if (d != null) {
throw AccountServiceException.DOMAIN_EXISTS(name);
}
// Attribute checking can not express "allow setting on
// creation, but do not allow modifies afterwards"
String domainType = (String) domainAttrs.get(A_zimbraDomainType);
if (domainType == null) {
domainType = DomainType.local.name();
} else {
// add back later
domainAttrs.remove(A_zimbraDomainType);
}
String domainStatus = (String) domainAttrs.get(A_zimbraDomainStatus);
if (domainStatus == null) {
domainStatus = DOMAIN_STATUS_ACTIVE;
} else {
// add back later
domainAttrs.remove(A_zimbraDomainStatus);
}
String smimeLdapURL = (String) domainAttrs.get(A_zimbraSMIMELdapURL);
if (!StringUtil.isNullOrEmpty(smimeLdapURL)) {
// add back later
domainAttrs.remove(A_zimbraSMIMELdapURL);
}
String smimeLdapStartTlsEnabled = (String) domainAttrs.get(A_zimbraSMIMELdapStartTlsEnabled);
if (!StringUtil.isNullOrEmpty(smimeLdapStartTlsEnabled)) {
// add back later
domainAttrs.remove(A_zimbraSMIMELdapStartTlsEnabled);
}
String smimeLdapBindDn = (String) domainAttrs.get(A_zimbraSMIMELdapBindDn);
if (!StringUtil.isNullOrEmpty(smimeLdapBindDn)) {
// add back later
domainAttrs.remove(A_zimbraSMIMELdapBindDn);
}
String smimeLdapBindPassword = (String) domainAttrs.get(A_zimbraSMIMELdapBindPassword);
if (!StringUtil.isNullOrEmpty(smimeLdapBindPassword)) {
// add back later
domainAttrs.remove(A_zimbraSMIMELdapBindPassword);
}
String smimeLdapSearchBase = (String) domainAttrs.get(A_zimbraSMIMELdapSearchBase);
if (!StringUtil.isNullOrEmpty(smimeLdapSearchBase)) {
// add back later
domainAttrs.remove(A_zimbraSMIMELdapSearchBase);
}
String smimeLdapFilter = (String) domainAttrs.get(A_zimbraSMIMELdapFilter);
if (!StringUtil.isNullOrEmpty(smimeLdapFilter)) {
// add back later
domainAttrs.remove(A_zimbraSMIMELdapFilter);
}
String smimeLdapAttribute = (String) domainAttrs.get(A_zimbraSMIMELdapAttribute);
if (!StringUtil.isNullOrEmpty(smimeLdapAttribute)) {
// add back later
domainAttrs.remove(A_zimbraSMIMELdapAttribute);
}
CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
AttributeManager.getInstance().preModify(domainAttrs, null, callbackContext, true);
// Add back attrs we circumvented from attribute checking
domainAttrs.put(A_zimbraDomainType, domainType);
domainAttrs.put(A_zimbraDomainStatus, domainStatus);
domainAttrs.put(A_zimbraSMIMELdapURL, smimeLdapURL);
domainAttrs.put(A_zimbraSMIMELdapStartTlsEnabled, smimeLdapStartTlsEnabled);
domainAttrs.put(A_zimbraSMIMELdapBindDn, smimeLdapBindDn);
domainAttrs.put(A_zimbraSMIMELdapBindPassword, smimeLdapBindPassword);
domainAttrs.put(A_zimbraSMIMELdapSearchBase, smimeLdapSearchBase);
domainAttrs.put(A_zimbraSMIMELdapFilter, smimeLdapFilter);
domainAttrs.put(A_zimbraSMIMELdapAttribute, smimeLdapAttribute);
String[] parts = name.split("\\.");
String[] dns = mDIT.domainToDNs(parts);
createParentDomains(zlc, parts, dns);
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(domainAttrs);
Set<String> ocs = LdapObjectClass.getDomainObjectClasses(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_zimbraDomainName, name);
String mailStatus = (String) domainAttrs.get(A_zimbraMailStatus);
if (mailStatus == null)
entry.setAttr(A_zimbraMailStatus, MAIL_STATUS_ENABLED);
if (domainType.equalsIgnoreCase(DomainType.alias.name())) {
entry.setAttr(A_zimbraMailCatchAllAddress, "@" + name);
}
entry.setAttr(A_o, name + " domain");
entry.setAttr(A_dc, parts[0]);
String dn = dns[0];
entry.setDN(dn);
//NOTE: all four of these should be in a transaction...
try {
zlc.createEntry(entry);
} catch (LdapEntryAlreadyExistException e) {
zlc.replaceAttributes(dn, entry.getAttributes());
}
String acctBaseDn = mDIT.domainDNToAccountBaseDN(dn);
if (!acctBaseDn.equals(dn)) {
/*
* create the account base dn entry only if if is not the same as the domain dn
*
* TODO, the objectclass(organizationalRole) and attrs(ou and cn) for the account
* base dn entry is still hardcoded, it should be parameterized in LdapDIT
* according the BASE_RDN_ACCOUNT. This is actually a design decision depending
* on how far we want to allow the DIT to be customized.
*/
zlc.createEntry(mDIT.domainDNToAccountBaseDN(dn), "organizationalRole", new String[] { A_ou, "people", A_cn, "people" });
// create the base DN for dynamic groups
zlc.createEntry(mDIT.domainDNToDynamicGroupsBaseDN(dn), "organizationalRole", new String[] { A_cn, "groups", A_description, "dynamic groups base" });
}
Domain domain = getDomainById(zimbraIdStr, zlc);
AttributeManager.getInstance().postModify(domainAttrs, domain, callbackContext);
return domain;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.DOMAIN_EXISTS(name);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to create domain: " + name, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.account.callback.CallbackContext in project zm-mailbox by Zimbra.
the class LdapProvisioning method createUCService.
@Override
public UCService createUCService(String name, Map<String, Object> attrs) throws ServiceException {
name = name.toLowerCase().trim();
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_UCSERVICE);
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(attrs);
Set<String> ocs = LdapObjectClass.getUCServiceObjectClasses(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_cn, name);
String dn = mDIT.ucServiceNameToDN(name);
entry.setDN(dn);
zlc.createEntry(entry);
UCService ucService = getUCServiceById(zimbraIdStr, zlc, true);
AttributeManager.getInstance().postModify(attrs, ucService, callbackContext);
return ucService;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.SERVER_EXISTS(name);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to create ucservice: " + name, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.account.callback.CallbackContext 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);
}
}
Aggregations