Search in sources :

Example 11 with AccountBy

use of com.zimbra.common.account.Key.AccountBy in project zm-mailbox by Zimbra.

the class LockoutMailbox method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = super.getZimbraSoapContext(context);
    LockoutMailboxRequest req = JaxbUtil.elementToJaxb(request);
    AccountNameSelector acctSel = req.getAccount();
    if (acctSel == null) {
        throw ServiceException.INVALID_REQUEST(String.format("missing <%s>", AdminConstants.E_ACCOUNT), null);
    }
    String accountSelectorKey = acctSel.getKey();
    AccountBy by = acctSel.getBy().toKeyAccountBy();
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(by, accountSelectorKey, zsc.getAuthToken());
    defendAgainstAccountOrCalendarResourceHarvesting(account, by, accountSelectorKey, zsc, Admin.R_moveAccountMailbox, Admin.R_moveCalendarResourceMailbox);
    // Reload account to pick up any changes made by other servers.
    prov.reload(account);
    // check rights
    checkRights(zsc, context, account);
    String method = request.getAttribute(AdminConstants.A_OPERATION, AdminConstants.A_START);
    if (method.equalsIgnoreCase(AdminConstants.A_START)) {
        MailboxManager.getInstance().lockoutMailbox(account.getId());
    } else if (method.equalsIgnoreCase(AdminConstants.A_END)) {
        MailboxManager.getInstance().undoLockout(account.getId());
    } else {
        throw ServiceException.FAILURE("Unknown lockout method " + method, null);
    }
    return zsc.createElement(AdminConstants.LOCKOUT_MAILBOX_RESPONSE);
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) AccountNameSelector(com.zimbra.soap.type.AccountNameSelector) Provisioning(com.zimbra.cs.account.Provisioning) LockoutMailboxRequest(com.zimbra.soap.admin.message.LockoutMailboxRequest) AccountBy(com.zimbra.common.account.Key.AccountBy)

Example 12 with AccountBy

use of com.zimbra.common.account.Key.AccountBy in project zm-mailbox by Zimbra.

the class GalSyncAccountUtil method deleteGalSyncAccount.

private Element deleteGalSyncAccount(String name, String id) throws ServiceException, IOException {
    mTransport = null;
    try {
        mTransport = new SoapHttpTransport(mAdminURL);
        auth();
        mTransport.setAuthToken(mAuth);
        XMLElement req = new XMLElement(AdminConstants.DELETE_GAL_SYNC_ACCOUNT_REQUEST);
        Element acct = req.addElement(AdminConstants.E_ACCOUNT);
        String account;
        AccountBy by;
        if (name == null) {
            by = AccountBy.id;
            account = id;
        } else {
            by = AccountBy.name;
            account = name;
        }
        acct.addAttribute(AdminConstants.A_BY, by.name());
        acct.setText(account);
        return mTransport.invokeWithoutSession(req);
    } finally {
        if (mTransport != null)
            mTransport.shutdown();
    }
}
Also used : XMLElement(com.zimbra.common.soap.Element.XMLElement) Element(com.zimbra.common.soap.Element) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) XMLElement(com.zimbra.common.soap.Element.XMLElement) AccountBy(com.zimbra.common.account.Key.AccountBy)

Example 13 with AccountBy

use of com.zimbra.common.account.Key.AccountBy in project zm-mailbox by Zimbra.

the class GetAccount method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    GetAccountRequest req = JaxbUtil.elementToJaxb(request);
    AccountSelector acctSel = req.getAccount();
    if (acctSel == null) {
        throw ServiceException.INVALID_REQUEST(String.format("missing <%s>", AdminConstants.E_ACCOUNT), null);
    }
    String accountSelectorKey = acctSel.getKey();
    AccountBy by = acctSel.getBy().toKeyAccountBy();
    Account account = prov.get(by, accountSelectorKey, zsc.getAuthToken());
    defendAgainstAccountHarvesting(account, by, accountSelectorKey, zsc, Admin.R_getAccountInfo);
    AdminAccessControl aac = checkAccountRight(zsc, account, AdminRight.PR_ALWAYS_ALLOW);
    Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_RESPONSE);
    boolean applyCos = !Boolean.FALSE.equals(req.isApplyCos());
    Set<String> reqAttrs = getReqAttrs(req.getAttrs(), AttributeClass.account);
    ToXML.encodeAccount(response, account, applyCos, reqAttrs, aac.getAttrRightChecker(account));
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) AccountSelector(com.zimbra.soap.type.AccountSelector) GetAccountRequest(com.zimbra.soap.admin.message.GetAccountRequest) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.common.account.Key.AccountBy)

Example 14 with AccountBy

use of com.zimbra.common.account.Key.AccountBy in project zm-mailbox by Zimbra.

the class GetAccountInfo method handle.

/* (non-Javadoc)
     * @see com.zimbra.soap.DocumentHandler#handle(org.dom4j.Element, java.util.Map)
     */
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    GetAccountInfoRequest req = JaxbUtil.elementToJaxb(request);
    AccountBy accountBy = req.getAccount().getBy().toKeyAccountBy();
    String accountSelectorKey = req.getAccount().getKey();
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.get(accountBy, accountSelectorKey, zsc.getAuthToken());
    defendAgainstAccountOrCalendarResourceHarvesting(account, accountBy, accountSelectorKey, zsc, Admin.R_getAccountInfo, Admin.R_getCalendarResourceInfo);
    Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_INFO_RESPONSE);
    response.addNonUniqueElement(AdminConstants.E_NAME).setText(account.getName());
    addAttr(response, Provisioning.A_zimbraId, account.getId());
    addAttr(response, Provisioning.A_zimbraMailHost, account.getAttr(Provisioning.A_zimbraMailHost));
    doCos(account, response);
    addUrls(response, account);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GetAccountInfoRequest(com.zimbra.soap.admin.message.GetAccountInfoRequest) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.common.account.Key.AccountBy)

Example 15 with AccountBy

use of com.zimbra.common.account.Key.AccountBy in project zm-mailbox by Zimbra.

the class GetAccountMembership method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    GetAccountMembershipRequest req = JaxbUtil.elementToJaxb(request);
    AccountBy acctBy = req.getAccount().getBy().toKeyAccountBy();
    String accountSelectorKey = req.getAccount().getKey();
    Account account = prov.get(acctBy, accountSelectorKey, zsc.getAuthToken());
    defendAgainstAccountHarvesting(account, acctBy, accountSelectorKey, zsc, Admin.R_getAccountMembership);
    HashMap<String, String> via = new HashMap<String, String>();
    List<Group> groups = prov.getGroups(account, false, via);
    Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_MEMBERSHIP_RESPONSE);
    for (Group group : groups) {
        Element eDL = response.addNonUniqueElement(AdminConstants.E_DL);
        eDL.addAttribute(AdminConstants.A_NAME, group.getName());
        eDL.addAttribute(AdminConstants.A_ID, group.getId());
        eDL.addAttribute(AdminConstants.A_DYNAMIC, group.isDynamic());
        String viaDl = via.get(group.getName());
        if (viaDl != null) {
            eDL.addAttribute(AdminConstants.A_VIA, viaDl);
        }
        try {
            if (group.isDynamic()) {
                checkDynamicGroupRight(zsc, (DynamicGroup) group, needGetAttrsRight());
            } else {
                checkDistributionListRight(zsc, (DistributionList) group, needGetAttrsRight());
            }
            String isAdminGroup = group.getAttr(Provisioning.A_zimbraIsAdminGroup);
            if (isAdminGroup != null) {
                eDL.addNonUniqueElement(AdminConstants.E_A).addAttribute(AdminConstants.A_N, Provisioning.A_zimbraIsAdminGroup).setText(isAdminGroup);
            }
        } catch (ServiceException e) {
            if (ServiceException.PERM_DENIED.equals(e.getCode())) {
                ZimbraLog.acl.warn("no permission to view %s of dl %s", Provisioning.A_zimbraIsAdminGroup, group.getName());
            }
        }
    }
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) DynamicGroup(com.zimbra.cs.account.DynamicGroup) Group(com.zimbra.cs.account.Group) ServiceException(com.zimbra.common.service.ServiceException) HashMap(java.util.HashMap) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GetAccountMembershipRequest(com.zimbra.soap.admin.message.GetAccountMembershipRequest) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.common.account.Key.AccountBy)

Aggregations

AccountBy (com.zimbra.common.account.Key.AccountBy)15 Account (com.zimbra.cs.account.Account)12 Provisioning (com.zimbra.cs.account.Provisioning)12 Element (com.zimbra.common.soap.Element)9 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)9 ServiceException (com.zimbra.common.service.ServiceException)5 Domain (com.zimbra.cs.account.Domain)4 HashMap (java.util.HashMap)4 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)3 AuthToken (com.zimbra.cs.account.AuthToken)3 AuthTokenException (com.zimbra.cs.account.AuthTokenException)3 Key (com.zimbra.common.account.Key)2 Server (com.zimbra.cs.account.Server)2 TwoFactorAuth (com.zimbra.cs.account.auth.twofactor.TwoFactorAuth)2 EmailAddress (com.zimbra.cs.account.names.NameUtil.EmailAddress)2 ZMailbox (com.zimbra.client.ZMailbox)1 DistributionListBy (com.zimbra.common.account.Key.DistributionListBy)1 XMLElement (com.zimbra.common.soap.Element.XMLElement)1 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)1