Search in sources :

Example 51 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetAccountDistributionLists method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account acct = getRequestedAccount(zsc);
    Provisioning prov = Provisioning.getInstance();
    if (!canAccessAccount(zsc, acct)) {
        throw ServiceException.PERM_DENIED("can not access account");
    }
    boolean needOwnerOf = request.getAttributeBool(AccountConstants.A_OWNER_OF, false);
    MemberOfSelector needMemberOf = MemberOfSelector.fromString(request.getAttribute(AccountConstants.A_MEMBER_OF, MemberOfSelector.directOnly.name()));
    Iterable<String> needAttrs = Splitter.on(',').trimResults().split(request.getAttribute(AccountConstants.A_ATTRS, ""));
    Set<Group> ownerOf = null;
    List<Group> memberOf = null;
    HashMap<String, String> via = new HashMap<String, String>();
    if (needOwnerOf) {
        ownerOf = Group.GroupOwner.getOwnedGroups(acct);
    }
    if (MemberOfSelector.none != needMemberOf) {
        memberOf = prov.getGroups(acct, MemberOfSelector.directOnly == needMemberOf, via);
    }
    /*
         * merge the two results into one locale-sensitive sorted list
         */
    Set<Entry> combined = Sets.newHashSet();
    Set<String> combinedIds = Sets.newHashSet();
    Set<String> ownerOfGroupIds = Sets.newHashSet();
    Set<String> memberOfGroupIds = Sets.newHashSet();
    if (ownerOf != null) {
        for (Group group : ownerOf) {
            String groupId = group.getId();
            ownerOfGroupIds.add(groupId);
            if (!combinedIds.contains(groupId)) {
                combined.add(group);
                combinedIds.add(groupId);
            }
        }
    }
    if (memberOf != null) {
        for (Group group : memberOf) {
            String groupId = group.getId();
            memberOfGroupIds.add(groupId);
            if (!combinedIds.contains(groupId)) {
                combined.add(group);
                combinedIds.add(groupId);
            }
        }
    }
    // sort it
    List<Entry> sortedGroups = Entry.sortByDisplayName(combined, acct.getLocale());
    Element response = zsc.createElement(AccountConstants.GET_ACCOUNT_DISTRIBUTION_LISTS_RESPONSE);
    for (Entry entry : sortedGroups) {
        Group group = (Group) entry;
        Element eDL = response.addElement(AccountConstants.E_DL);
        eDL.addAttribute(AccountConstants.A_NAME, group.getName());
        if (group.isDynamic()) {
            eDL.addAttribute(AccountConstants.A_REF, ((LdapDynamicGroup) group).getDN());
        } else {
            eDL.addAttribute(AccountConstants.A_REF, ((LdapDistributionList) group).getDN());
        }
        eDL.addAttribute(AccountConstants.A_ID, group.getId());
        eDL.addAttribute(AccountConstants.A_DISPLAY, group.getDisplayName());
        eDL.addAttribute(AccountConstants.A_DYNAMIC, group.isDynamic());
        boolean isOwner = ownerOfGroupIds.contains(group.getId());
        if (needOwnerOf) {
            eDL.addAttribute(AccountConstants.A_IS_OWNER, isOwner);
        }
        if (MemberOfSelector.none != needMemberOf) {
            boolean isMember = memberOfGroupIds.contains(group.getId());
            eDL.addAttribute(AccountConstants.A_IS_MEMBER, isMember);
            if (isMember) {
                String viaDl = via.get(group.getName());
                if (viaDl != null) {
                    eDL.addAttribute(AccountConstants.A_VIA, viaDl);
                }
            }
        }
        Set<String> returnAttrs = GetDistributionList.visibleAttrs(needAttrs, isOwner);
        if (!returnAttrs.isEmpty()) {
            GetDistributionList.encodeAttrs(group, eDL, returnAttrs);
        }
    }
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) Group(com.zimbra.cs.account.Group) HashMap(java.util.HashMap) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) Entry(com.zimbra.cs.account.Entry) MemberOfSelector(com.zimbra.soap.account.type.MemberOfSelector) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext)

Example 52 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetAccountInfo method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Element a = request.getElement(AccountConstants.E_ACCOUNT);
    String key = a.getAttribute(AccountConstants.A_BY);
    String value = a.getText();
    if (Strings.isNullOrEmpty(value)) {
        throw ServiceException.INVALID_REQUEST("no text specified for the " + AccountConstants.E_ACCOUNT + " element", null);
    }
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(AccountBy.fromString(key), value, zsc.getAuthToken());
    // prevent directory harvest attack, mask no such account as permission denied
    if (account == null)
        throw ServiceException.PERM_DENIED("can not access account");
    Element response = zsc.createElement(AccountConstants.GET_ACCOUNT_INFO_RESPONSE);
    response.addAttribute(AccountConstants.E_NAME, account.getName(), Element.Disposition.CONTENT);
    response.addKeyValuePair(Provisioning.A_zimbraId, account.getId(), AccountConstants.E_ATTR, AccountConstants.A_NAME);
    response.addKeyValuePair(Provisioning.A_zimbraMailHost, account.getAttr(Provisioning.A_zimbraMailHost), AccountConstants.E_ATTR, AccountConstants.A_NAME);
    response.addKeyValuePair(Provisioning.A_displayName, account.getAttr(Provisioning.A_displayName), AccountConstants.E_ATTR, AccountConstants.A_NAME);
    addUrls(response, account);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 53 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class GetIdentities method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canAccessAccount(zsc, account)) {
        throw ServiceException.PERM_DENIED("can not access account");
    }
    Element response = zsc.createElement(AccountConstants.GET_IDENTITIES_RESPONSE);
    Provisioning prov = Provisioning.getInstance();
    for (Identity ident : prov.getAllIdentities(account)) {
        ToXML.encodeIdentity(response, ident);
    }
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Identity(com.zimbra.cs.account.Identity) Provisioning(com.zimbra.cs.account.Provisioning)

Example 54 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class CreateDistributionList method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    Account acct = getAuthenticatedAccount(zsc);
    String name = request.getAttribute(AccountConstants.E_NAME).toLowerCase();
    if (!AccessManager.getInstance().canCreateGroup(acct, name)) {
        throw ServiceException.PERM_DENIED("you do not have sufficient rights to create distribution list");
    }
    Map<String, Object> attrs = AccountService.getKeyValuePairs(request, AccountConstants.E_A, AccountConstants.A_N);
    boolean dynamic = request.getAttributeBool(AccountConstants.A_DYNAMIC, true);
    // creator of the group will automatically become the first owner of the group
    Account creator = getAuthenticatedAccount(zsc);
    Group group = prov.createDelegatedGroup(name, attrs, dynamic, creator);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "CreateDistributionList", "name", name }, attrs));
    Element response = zsc.createElement(AccountConstants.CREATE_DISTRIBUTION_LIST_RESPONSE);
    Element eDL = response.addElement(AccountConstants.E_DL);
    eDL.addAttribute(AccountConstants.A_NAME, group.getName());
    if (group.isDynamic()) {
        eDL.addAttribute(AccountConstants.A_REF, ((LdapDynamicGroup) group).getDN());
    } else {
        eDL.addAttribute(AccountConstants.A_REF, ((LdapDistributionList) group).getDN());
    }
    eDL.addAttribute(AccountConstants.A_ID, group.getId());
    GetDistributionList.encodeAttrs(group, eDL, null);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) LdapDynamicGroup(com.zimbra.cs.account.ldap.entry.LdapDynamicGroup) Group(com.zimbra.cs.account.Group) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 55 with ZimbraSoapContext

use of com.zimbra.soap.ZimbraSoapContext in project zm-mailbox by Zimbra.

the class DeleteIdentity method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException, SoapFaultException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canModifyOptions(zsc, account))
        throw ServiceException.PERM_DENIED("can not modify options");
    Provisioning prov = Provisioning.getInstance();
    Element eIdentity = request.getElement(AccountConstants.E_IDENTITY);
    // identity can be specified by name or by ID
    Identity ident = null;
    String idStr = eIdentity.getAttribute(AccountConstants.A_ID, null);
    if (idStr != null) {
        ident = prov.get(account, Key.IdentityBy.id, idStr);
    } else {
        idStr = eIdentity.getAttribute(AccountConstants.A_NAME);
        ident = prov.get(account, Key.IdentityBy.name, idStr);
    }
    if (ident != null)
        Provisioning.getInstance().deleteIdentity(account, ident.getName());
    else
        throw AccountServiceException.NO_SUCH_IDENTITY(idStr);
    Element response = zsc.createElement(AccountConstants.DELETE_IDENTITY_RESPONSE);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Identity(com.zimbra.cs.account.Identity) Provisioning(com.zimbra.cs.account.Provisioning)

Aggregations

ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)382 Element (com.zimbra.common.soap.Element)315 Provisioning (com.zimbra.cs.account.Provisioning)162 Account (com.zimbra.cs.account.Account)158 Mailbox (com.zimbra.cs.mailbox.Mailbox)106 OperationContext (com.zimbra.cs.mailbox.OperationContext)82 ItemId (com.zimbra.cs.service.util.ItemId)58 Server (com.zimbra.cs.account.Server)47 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)44 ServiceException (com.zimbra.common.service.ServiceException)40 HashMap (java.util.HashMap)37 Domain (com.zimbra.cs.account.Domain)32 HashSet (java.util.HashSet)25 ArrayList (java.util.ArrayList)23 IOException (java.io.IOException)20 Group (com.zimbra.cs.account.Group)17 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)17 Message (com.zimbra.cs.mailbox.Message)17 MimeMessage (javax.mail.internet.MimeMessage)16 Map (java.util.Map)15