Search in sources :

Example 6 with LdapCos

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);
    }
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) LdapEntryNotFoundException(com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException) ZAttributes(com.zimbra.cs.ldap.ZAttributes) LdapCos(com.zimbra.cs.account.ldap.entry.LdapCos)

Example 7 with LdapCos

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);
    }
}
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 8 with LdapCos

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);
    }
}
Also used : 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)

Aggregations

LdapCos (com.zimbra.cs.account.ldap.entry.LdapCos)8 ServiceException (com.zimbra.common.service.ServiceException)6 AccountServiceException (com.zimbra.cs.account.AccountServiceException)6 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)6 Cos (com.zimbra.cs.account.Cos)3 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)2 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)2 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)2 ArrayList (java.util.ArrayList)2 Account (com.zimbra.cs.account.Account)1 AlwaysOnCluster (com.zimbra.cs.account.AlwaysOnCluster)1 Domain (com.zimbra.cs.account.Domain)1 DynamicGroup (com.zimbra.cs.account.DynamicGroup)1 Group (com.zimbra.cs.account.Group)1 GuestAccount (com.zimbra.cs.account.GuestAccount)1 Server (com.zimbra.cs.account.Server)1 UCService (com.zimbra.cs.account.UCService)1 XMPPComponent (com.zimbra.cs.account.XMPPComponent)1 LdapAccount (com.zimbra.cs.account.ldap.entry.LdapAccount)1 LdapAlwaysOnCluster (com.zimbra.cs.account.ldap.entry.LdapAlwaysOnCluster)1