Search in sources :

Example 41 with ZLdapContext

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

the class ZLdapHelper method deleteEntry.

@Override
public void deleteEntry(String dn, LdapUsage ldapUsage) throws ServiceException {
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, ldapUsage);
        zlc.deleteEntry(dn);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext)

Example 42 with ZLdapContext

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

the class ZLdapHelper method modifyEntry.

@Override
public void modifyEntry(String dn, Map<String, ? extends Object> attrs, Entry entry, LdapUsage ldapUsage) throws ServiceException {
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, ldapUsage);
        modifyAttrs(zlc, dn, attrs, entry);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext)

Example 43 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext 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);
    }
}
Also used : LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapUCService(com.zimbra.cs.account.ldap.entry.LdapUCService) LdapException(com.zimbra.cs.ldap.LdapException)

Example 44 with ZLdapContext

use of com.zimbra.cs.ldap.ZLdapContext 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);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) Zimlet(com.zimbra.cs.account.Zimlet) LdapZimlet(com.zimbra.cs.account.ldap.entry.LdapZimlet) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) LdapException(com.zimbra.cs.ldap.LdapException) Date(java.util.Date)

Example 45 with ZLdapContext

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

the class LdapProvisioning method searchZimbraLdap.

private void searchZimbraLdap(String base, String query, String[] returnAttrs, boolean useMaster, SearchLdapVisitor visitor) throws ServiceException {
    SearchLdapOptions searchOptions = new SearchLdapOptions(base, query, returnAttrs, SearchLdapOptions.SIZE_UNLIMITED, null, ZSearchScope.SEARCH_SCOPE_SUBTREE, visitor);
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.get(useMaster), LdapUsage.SEARCH);
        zlc.searchPaged(searchOptions);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) SearchLdapOptions(com.zimbra.cs.ldap.SearchLdapOptions)

Aggregations

ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)112 ServiceException (com.zimbra.common.service.ServiceException)51 AccountServiceException (com.zimbra.cs.account.AccountServiceException)48 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)46 LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)21 LdapException (com.zimbra.cs.ldap.LdapException)20 ZMutableEntry (com.zimbra.cs.ldap.ZMutableEntry)18 Domain (com.zimbra.cs.account.Domain)17 CallbackContext (com.zimbra.cs.account.callback.CallbackContext)14 Date (java.util.Date)14 LdapDomain (com.zimbra.cs.account.ldap.entry.LdapDomain)12 HashMap (java.util.HashMap)12 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)11 SearchLdapOptions (com.zimbra.cs.ldap.SearchLdapOptions)11 Account (com.zimbra.cs.account.Account)9 LdapDynamicGroup (com.zimbra.cs.account.ldap.entry.LdapDynamicGroup)8 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)8 GuestAccount (com.zimbra.cs.account.GuestAccount)7 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)7 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)7