Search in sources :

Example 21 with LdapException

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

the class LdapProvisioning method renameCos.

@Override
public void renameCos(String zimbraId, String newName) throws ServiceException {
    LdapCos cos = (LdapCos) get(Key.CosBy.id, zimbraId);
    if (cos == null)
        throw AccountServiceException.NO_SUCH_COS(zimbraId);
    if (cos.isDefaultCos())
        throw ServiceException.INVALID_REQUEST("unable to rename default cos", null);
    newName = newName.toLowerCase().trim();
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.RENAME_COS);
        String newDn = mDIT.cosNametoDN(newName);
        zlc.renameEntry(cos.getDN(), newDn);
        // remove old cos from cache
        cosCache.remove(cos);
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.COS_EXISTS(newName);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to rename cos: " + 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) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos) LdapException(com.zimbra.cs.ldap.LdapException)

Example 22 with LdapException

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

the class UBIDLdapException method mapToExternalLdapException.

// need more precise mapping for external LDAP exceptions so we
// can report config error better
static LdapException mapToExternalLdapException(String message, LDAPException e) {
    Throwable cause = e.getCause();
    ResultCode rc = e.getResultCode();
    // the LdapException instance to return
    LdapException ldapException = mapToLdapException(message, e);
    if (cause instanceof IOException) {
        // Unboundid hides the original IOException and throws a 
        // generic IOException.  This doesn't work with check.toResult(IOException).
        // Do our best to figure out the original IOException and set it 
        // in the detail field.  Very hacky!
        //
        // Seems the root exception can be found in the message of the IOException
        // thrown by Unboundi.
        // 
        // e.g. An error occurred while attempting to establish a connection to server bogus:389:  java.net.UnknownHostException: bogus 
        IOException ioException = (IOException) cause;
        String causeMsg = ioException.getMessage();
        IOException rootException = null;
        if (causeMsg != null) {
            //
            if (causeMsg.contains("java.net.UnknownHostException")) {
                rootException = new java.net.UnknownHostException(causeMsg);
            } else if (causeMsg.contains("java.net.ConnectException")) {
                rootException = new java.net.ConnectException(causeMsg);
            } else if (causeMsg.contains("javax.net.ssl.SSLHandshakeException")) {
                rootException = new javax.net.ssl.SSLHandshakeException(causeMsg);
            }
        }
        if (rootException != null) {
            ldapException.setDetail(rootException);
        } else {
            ldapException.setDetail(cause);
        }
    } else {
        String causeMsg = e.getMessage();
        Throwable rootException = null;
        if (causeMsg.contains("unsupported extended operation")) {
            // most likely startTLS failed, for backward compatibility with check.toResult,
            // return a generic IOException
            rootException = new IOException(causeMsg);
        } else {
            // just map using the regular mapping
            rootException = mapToLdapException(message, e);
        }
        ldapException.setDetail(rootException);
    }
    return ldapException;
}
Also used : IOException(java.io.IOException) LdapException(com.zimbra.cs.ldap.LdapException) ResultCode(com.unboundid.ldap.sdk.ResultCode)

Example 23 with LdapException

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

the class TestLdapZLdapFilter method bug64260.

@Test
@Bug(bug = 64260)
public void bug64260() throws Exception {
    String badStringFilter = "ad:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(givenName=*%s*)(mail=*%s*))(!(msExchHideFromAddressLists=TRUE))(!(displayName=*(EMC)))(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(objectCategory=msExchDynamicDistributionList)))";
    ZLdapFilter filter;
    boolean caughtException = false;
    try {
        filter = filterDactory.fromFilterString(FilterId.UNITTEST, badStringFilter);
    } catch (LdapException e) {
        // e.printStackTrace();
        if (LdapException.INVALID_SEARCH_FILTER.equals(e.getCode())) {
            caughtException = true;
        }
    }
    assertTrue(caughtException);
    String goodStringFilter = "(&(|(displayName=*)(cn=*)(sn=*)(givenName=*)(mail=*))(!(msExchHideFromAddressLists=TRUE))(!(displayName=*\\28EMC\\29))(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(objectCategory=msExchDynamicDistributionList)))";
    // String goodStringFilter = "(displayName=*\\28EMC\\29)";
    filter = filterDactory.fromFilterString(FilterId.UNITTEST, goodStringFilter);
// System.out.println(filter.toFilterString());
/*
DEV:
zmprov mcf -zimbraGalLdapFilterDef 'zimbraAccountSync:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(zimbraPhoneticFirstName=*%s*)(zimbraPhoneticLastName=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(objectclass=zimbraCalendarResource)))'
zmprov mcf +zimbraGalLdapFilterDef 'zimbraAccountSync:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(gn=*%s*)(zimbraPhoneticFirstName=*%s*)(zimbraPhoneticLastName=*%s*)(mail=*%s*)(zimbraMailDeliveryAddress=*%s*)(zimbraMailAlias=*%s*))(|(objectclass=zimbraAccount)(objectclass=zimbraDistributionList))(!(objectclass=zimbraCalendarResource))(!(displayName=*\28EMC\29)))'


DF:
zmprov mds galsync@zimbra.com VMware -zimbraGalSyncLdapFilter '(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(givenName=*%s*)(mail=*%s*))(!(msExchHideFromAddressLists=TRUE))(!(displayName=*EMC))(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(objectCategory=msExchDynamicDistributionList)))'
zmprov mds galsync@zimbra.com VMware +zimbraGalSyncLdapFilter '(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(givenName=*%s*)(mail=*%s*))(!(msExchHideFromAddressLists=TRUE))(!(displayName=*\28EMC\29))(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(objectCategory=msExchDynamicDistributionList)))'

zmprov mcf -zimbraGalLdapFilterDef 'ad:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(givenName=*%s*)(mail=*%s*))(!(msExchHideFromAddressLists=TRUE))(!(displayName=*EMC))(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(objectCategory=msExchDynamicDistributionList)))'
zmprov mcf +zimbraGalLdapFilterDef 'ad:(&(|(displayName=*%s*)(cn=*%s*)(sn=*%s*)(givenName=*%s*)(mail=*%s*))(!(msExchHideFromAddressLists=TRUE))(!(displayName=*\28EMC\29))(mailnickname=*)(|(&(objectCategory=person)(objectClass=user)(!(homeMDB=*))(!(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=user)(|(homeMDB=*)(msExchHomeServerName=*)))(&(objectCategory=person)(objectClass=contact))(objectCategory=group)(objectCategory=publicFolder)(objectCategory=msExchDynamicDistributionList)))'
         */
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) LdapException(com.zimbra.cs.ldap.LdapException) Bug(com.zimbra.qa.QA.Bug)

Aggregations

LdapException (com.zimbra.cs.ldap.LdapException)23 AccountServiceException (com.zimbra.cs.account.AccountServiceException)20 LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)20 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)20 ServiceException (com.zimbra.common.service.ServiceException)19 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)19 ZMutableEntry (com.zimbra.cs.ldap.ZMutableEntry)14 CallbackContext (com.zimbra.cs.account.callback.CallbackContext)13 Date (java.util.Date)13 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