use of com.zimbra.cs.account.ldap.entry.LdapCos in project zm-mailbox by Zimbra.
the class LdapProvisioning method getCosByName.
private Cos getCosByName(String name, ZLdapContext initZlc) throws ServiceException {
LdapCos cos = cosCache.getByName(name);
if (cos != null)
return cos;
try {
String dn = mDIT.cosNametoDN(name);
ZAttributes attrs = helper.getAttributes(initZlc, LdapServerType.REPLICA, LdapUsage.GET_COS, dn, null);
cos = new LdapCos(dn, attrs, this);
cosCache.put(cos);
return cos;
} catch (LdapEntryNotFoundException e) {
return null;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to lookup COS by name: " + name + " message: " + e.getMessage(), e);
}
}
use of com.zimbra.cs.account.ldap.entry.LdapCos 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.account.ldap.entry.LdapCos in project zm-mailbox by Zimbra.
the class LdapProvisioning method deleteCos.
@Override
public void deleteCos(String zimbraId) throws ServiceException {
LdapCos c = (LdapCos) get(Key.CosBy.id, zimbraId);
if (c == null)
throw AccountServiceException.NO_SUCH_COS(zimbraId);
if (c.isDefaultCos())
throw ServiceException.INVALID_REQUEST("unable to delete default cos", null);
// TODO: should we go through all accounts with this cos and remove the zimbraCOSId attr?
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_COS);
zlc.deleteEntry(c.getDN());
cosCache.remove(c);
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to purge cos: " + zimbraId, e);
} finally {
LdapClient.closeContext(zlc);
}
}
Aggregations