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);
}
}
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;
}
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)))'
*/
}
Aggregations