Search in sources :

Example 1 with AddressListInfo

use of com.zimbra.soap.account.type.AddressListInfo in project zm-mailbox by Zimbra.

the class LdapProvisioning method deleteAddressList.

@Override
public void deleteAddressList(String addressListId) throws ServiceException {
    AddressListInfo adl = getAddressListById(addressListId);
    if (adl == null) {
        throw AccountServiceException.NO_SUCH_ADDRESS_LIST(addressListId);
    }
    ZLdapContext zlc = null;
    try {
        zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.DELETE_ADDRESSLIST);
        zlc.deleteEntry(adl.getDn());
    } catch (ServiceException e) {
        throw ServiceException.FAILURE(String.format("unable to purge address list: %s", addressListId), e);
    } finally {
        LdapClient.closeContext(zlc);
    }
}
Also used : AddressListInfo(com.zimbra.soap.account.type.AddressListInfo) 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)

Example 2 with AddressListInfo

use of com.zimbra.soap.account.type.AddressListInfo in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAddressListByQuery.

private List<AddressListInfo> getAddressListByQuery(String base, ZLdapFilter filter, boolean activeOnly, boolean getDN) throws ServiceException {
    List<AddressListInfo> result = new ArrayList<AddressListInfo>();
    try {
        ZSearchResultEnumeration ne = helper.searchDir(base, filter, ZSearchControls.SEARCH_CTLS_SUBTREE(), null, LdapServerType.REPLICA);
        while (ne.hasMore()) {
            ZSearchResultEntry sr = ne.next();
            if (getDN) {
                AddressListInfo adl = new AddressListInfo(sr.getDN());
                result.add(adl);
            } else {
                ZAttributes attrs = sr.getAttributes();
                if (attrs != null) {
                    boolean active = Boolean.parseBoolean(attrs.getAttrString(Provisioning.A_zimbraIsAddressListActive));
                    boolean addToRes = activeOnly ? active : Boolean.TRUE;
                    if (addToRes) {
                        AddressListInfo adl = new AddressListInfo(attrs.getAttrString(Provisioning.A_zimbraId), attrs.getAttrString(Provisioning.A_uid), attrs.getAttrString(Provisioning.A_description));
                        if (!activeOnly) {
                            adl.setActive(active);
                            adl.setGalFilter(attrs.getAttrString(Provisioning.A_zimbraAddressListGalFilter));
                            adl.setLdapFilter(attrs.getAttrString(Provisioning.A_zimbraAddressListLdapFilter));
                        }
                        result.add(adl);
                    }
                }
            }
        }
        ne.close();
    } catch (ServiceException e) {
        throw ServiceException.FAILURE("unable to lookup address lists via query: " + filter.toFilterString() + " message: " + e.getMessage(), e);
    }
    return result;
}
Also used : AddressListInfo(com.zimbra.soap.account.type.AddressListInfo) 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) ZAttributes(com.zimbra.cs.ldap.ZAttributes) ArrayList(java.util.ArrayList) ZSearchResultEntry(com.zimbra.cs.ldap.ZSearchResultEntry)

Example 3 with AddressListInfo

use of com.zimbra.soap.account.type.AddressListInfo in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAllAddressLists.

@Override
public List<AddressListInfo> getAllAddressLists(Domain domain, boolean activeOnly) throws ServiceException {
    LdapEntry ldapEntry = (LdapEntry) (domain instanceof LdapEntry ? domain : getDomainById(domain.getId()));
    if (ldapEntry == null) {
        throw AccountServiceException.NO_SUCH_DOMAIN(domain.getName());
    }
    List<AddressListInfo> result = getAddressListByQuery(ldapEntry.getDN(), filterFactory.allAddressLists(), activeOnly);
    result = Collections.unmodifiableList(result);
    return result;
}
Also used : AddressListInfo(com.zimbra.soap.account.type.AddressListInfo) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry)

Example 4 with AddressListInfo

use of com.zimbra.soap.account.type.AddressListInfo in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAddressListById.

private AddressListInfo getAddressListById(String zimbraId) throws ServiceException {
    AddressListInfo adl = null;
    List<AddressListInfo> adlList = getAddressListByQuery(mDIT.mailBranchBaseDN(), filterFactory.addressListById(zimbraId), false, true);
    if (adlList.size() != 0) {
        adl = adlList.get(0);
    }
    return adl;
}
Also used : AddressListInfo(com.zimbra.soap.account.type.AddressListInfo)

Example 5 with AddressListInfo

use of com.zimbra.soap.account.type.AddressListInfo in project zm-mailbox by Zimbra.

the class LdapProvisioning method getAddressListByName.

@Override
public AddressListInfo getAddressListByName(String name, Domain domain) throws ServiceException {
    LdapEntry ldapEntry = (LdapEntry) (domain instanceof LdapEntry ? domain : getDomainById(domain.getId()));
    if (ldapEntry == null) {
        throw AccountServiceException.NO_SUCH_DOMAIN(domain.getName());
    }
    List<AddressListInfo> result = getAddressListByQuery(ldapEntry.getDN(), filterFactory.addressListByName(name), false);
    if (result.size() < 1) {
        throw AccountServiceException.NO_SUCH_ADDRESS_LIST(name);
    }
    // first should be what we want, ignore extras
    return result.get(0);
}
Also used : AddressListInfo(com.zimbra.soap.account.type.AddressListInfo) LdapEntry(com.zimbra.cs.account.ldap.entry.LdapEntry)

Aggregations

AddressListInfo (com.zimbra.soap.account.type.AddressListInfo)5 ServiceException (com.zimbra.common.service.ServiceException)2 AccountServiceException (com.zimbra.cs.account.AccountServiceException)2 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)2 LdapEntry (com.zimbra.cs.account.ldap.entry.LdapEntry)2 ZAttributes (com.zimbra.cs.ldap.ZAttributes)1 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)1 ZSearchResultEntry (com.zimbra.cs.ldap.ZSearchResultEntry)1 ZSearchResultEnumeration (com.zimbra.cs.ldap.ZSearchResultEnumeration)1 ArrayList (java.util.ArrayList)1