Search in sources :

Example 21 with LdapEntryAlreadyExistException

use of com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException in project zm-mailbox by Zimbra.

the class LdapProvisioning method createXMPPComponent.

@Override
public XMPPComponent createXMPPComponent(String name, Domain domain, Server server, Map<String, Object> inAttrs) throws ServiceException {
    name = name.toLowerCase().trim();
    // sanity checking
    removeAttrIgnoreCase("objectclass", inAttrs);
    removeAttrIgnoreCase(A_zimbraDomainId, inAttrs);
    removeAttrIgnoreCase(A_zimbraServerId, inAttrs);
    CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
    AttributeManager.getInstance().preModify(inAttrs, null, callbackContext, true);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_XMPPCOMPONENT);
        ZMutableEntry entry = LdapClient.createMutableEntry();
        entry.mapToAttrs(inAttrs);
        entry.setAttr(A_objectClass, "zimbraXMPPComponent");
        String compId = LdapUtil.generateUUID();
        entry.setAttr(A_zimbraId, compId);
        entry.setAttr(A_zimbraCreateTimestamp, LdapDateUtil.toGeneralizedTime(new Date()));
        entry.setAttr(A_cn, name);
        String dn = mDIT.xmppcomponentNameToDN(name);
        entry.setDN(dn);
        entry.setAttr(A_zimbraDomainId, domain.getId());
        entry.setAttr(A_zimbraServerId, server.getId());
        zlc.createEntry(entry);
        XMPPComponent comp = getXMPPComponentById(compId, zlc, true);
        AttributeManager.getInstance().postModify(inAttrs, comp, callbackContext);
        return comp;
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.IM_COMPONENT_EXISTS(name);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) XMPPComponent(com.zimbra.cs.account.XMPPComponent) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent) Date(java.util.Date)

Aggregations

LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)21 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)21 AccountServiceException (com.zimbra.cs.account.AccountServiceException)20 LdapException (com.zimbra.cs.ldap.LdapException)20 ServiceException (com.zimbra.common.service.ServiceException)19 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)19 ZMutableEntry (com.zimbra.cs.ldap.ZMutableEntry)15 CallbackContext (com.zimbra.cs.account.callback.CallbackContext)14 Date (java.util.Date)14 Domain (com.zimbra.cs.account.Domain)8 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)8 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)5 HashMap (java.util.HashMap)4 Account (com.zimbra.cs.account.Account)3 GuestAccount (com.zimbra.cs.account.GuestAccount)3 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)3 LdapCos (com.zimbra.cs.account.ldap.entry.LdapCos)3 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)3 Cos (com.zimbra.cs.account.Cos)2 DynamicGroup (com.zimbra.cs.account.DynamicGroup)2