Search in sources :

Example 1 with LdapXMPPComponent

use of com.zimbra.cs.account.ldap.entry.LdapXMPPComponent in project zm-mailbox by Zimbra.

the class LdapProvisioning method deleteXMPPComponent.

@Override
public void deleteXMPPComponent(XMPPComponent comp) throws ServiceException {
    String zimbraId = comp.getId();
    ZLdapContext zlc = null;
    LdapXMPPComponent l = (LdapXMPPComponent) get(Key.XMPPComponentBy.id, zimbraId);
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_XMPPCOMPONENT);
        zlc.deleteEntry(l.getDN());
        xmppComponentCache.remove(l);
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to purge XMPPComponent : " + 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) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent)

Example 2 with LdapXMPPComponent

use of com.zimbra.cs.account.ldap.entry.LdapXMPPComponent in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAllXMPPComponents.

@Override
public List<XMPPComponent> getAllXMPPComponents() throws ServiceException {
    List<XMPPComponent> result = new ArrayList<XMPPComponent>();
    try {
        String base = mDIT.xmppcomponentBaseDN();
        ZLdapFilter filter = filterFactory.allXMPPComponents();
        ZSearchResultEnumeration ne = helper.searchDir(base, filter, ZSearchControls.SEARCH_CTLS_SUBTREE());
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            LdapXMPPComponent x = new LdapXMPPComponent(sr.getDN(), sr.getAttributes(), this);
            result.add(x);
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to list all XMPPComponents", e);
    }
    if (result.size() > 0) {
        xmppComponentCache.put(result, true);
    }
    Collections.sort(result);
    return result;
}
Also used : ZLdapFilter(com.zimbra.cs.ldap.ZLdapFilter) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZSearchResultEnumeration(com.zimbra.cs.ldap.ZSearchResultEnumeration) ArrayList(java.util.ArrayList) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent) XMPPComponent(com.zimbra.cs.account.XMPPComponent) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 3 with LdapXMPPComponent

use of com.zimbra.cs.account.ldap.entry.LdapXMPPComponent in project zm-mailbox by Zimbra.

the class LdapProvisioning method renameXMPPComponent.

// Only called from renameDomain for now
void renameXMPPComponent(String zimbraId, String newName) throws ServiceException {
    LdapXMPPComponent comp = (LdapXMPPComponent) get(Key.XMPPComponentBy.id, zimbraId);
    if (comp == null)
        throw AccountServiceException.NO_SUCH_XMPP_COMPONENT(zimbraId);
    newName = newName.toLowerCase().trim();
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.RENAME_XMPPCOMPONENT);
        String newDn = mDIT.xmppcomponentNameToDN(newName);
        zlc.renameEntry(comp.getDN(), newDn);
        // remove old comp from cache
        xmppComponentCache.remove(comp);
    } catch (LdapEntryAlreadyExistException nabe) {
        throw AccountServiceException.IM_COMPONENT_EXISTS(newName);
    } catch (LdapException e) {
        throw e;
    } catch (AccountServiceException e) {
        throw e;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to rename XMPPComponent: " + 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) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent) LdapException(com.zimbra.cs.ldap.LdapException)

Example 4 with LdapXMPPComponent

use of com.zimbra.cs.account.ldap.entry.LdapXMPPComponent in project zm-mailbox by Zimbra.

the class LdapProvisioning method getXMPPComponentByName.

private XMPPComponent getXMPPComponentByName(String name, boolean nocache) throws ServiceException {
    if (!nocache) {
        XMPPComponent x = xmppComponentCache.getByName(name);
        if (x != null)
            return x;
    }
    try {
        String dn = mDIT.xmppcomponentNameToDN(name);
        ZAttributes attrs = helper.getAttributes(LdapUsage.GET_XMPPCOMPONENT, dn);
        XMPPComponent x = new LdapXMPPComponent(dn, attrs, this);
        xmppComponentCache.put(x);
        return x;
    } catch (LdapEntryNotFoundException e) {
        return null;
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup xmpp component 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) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent) XMPPComponent(com.zimbra.cs.account.XMPPComponent) LdapXMPPComponent(com.zimbra.cs.account.ldap.entry.LdapXMPPComponent)

Aggregations

ServiceException (com.zimbra.common.service.ServiceException)4 AccountServiceException (com.zimbra.cs.account.AccountServiceException)4 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)4 LdapXMPPComponent (com.zimbra.cs.account.ldap.entry.LdapXMPPComponent)4 XMPPComponent (com.zimbra.cs.account.XMPPComponent)2 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)2 LdapException (com.zimbra.cs.ldap.LdapException)1 LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)1 LdapEntryNotFoundException (com.zimbra.cs.ldap.LdapException.LdapEntryNotFoundException)1 ZAttributes (com.zimbra.cs.ldap.ZAttributes)1 ZLdapFilter (com.zimbra.cs.ldap.ZLdapFilter)1 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)1 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)1 ArrayList (java.util.ArrayList)1