Search in sources :

Example 21 with ZimbraSoapContext

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

the class ModifyIdentity method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    Identity identity = null;
    if (!canModifyOptions(zsc, account))
        throw ServiceException.PERM_DENIED("can not modify options");
    Provisioning prov = Provisioning.getInstance();
    Element eIdentity = request.getElement(AccountConstants.E_IDENTITY);
    Map<String, Object> attrs = AccountService.getAttrs(eIdentity, AccountConstants.A_NAME);
    // remove anything that doesn't start with zimbraPref. ldap will also do additional checks
    for (Iterator<String> it = attrs.keySet().iterator(); it.hasNext(); ) if (// if this changes, make sure we don't let them ever change objectclass
    !it.next().toLowerCase().startsWith("zimbrapref"))
        it.remove();
    String key, id = eIdentity.getAttribute(AccountConstants.A_ID, null);
    if (id != null) {
        identity = prov.get(account, Key.IdentityBy.id, key = id);
    } else {
        identity = prov.get(account, Key.IdentityBy.name, key = eIdentity.getAttribute(AccountConstants.A_NAME));
    }
    if (identity == null) {
        String[] childIds = account.getChildAccount();
        for (String childId : childIds) {
            Account childAccount = prov.get(AccountBy.id, childId, zsc.getAuthToken());
            if (childAccount != null) {
                Identity childIdentity;
                if (id != null) {
                    childIdentity = prov.get(childAccount, Key.IdentityBy.id, key = id);
                } else {
                    childIdentity = prov.get(childAccount, Key.IdentityBy.name, key = eIdentity.getAttribute(AccountConstants.A_NAME));
                }
                if (childIdentity != null) {
                    identity = childIdentity;
                    account = childAccount;
                    break;
                }
            }
        }
    }
    if (identity == null)
        throw AccountServiceException.NO_SUCH_IDENTITY(key);
    prov.modifyIdentity(account, identity.getName(), attrs);
    Element response = zsc.createElement(AccountConstants.MODIFY_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)

Example 22 with ZimbraSoapContext

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

the class ModifyProperties method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Account account = getRequestedAccount(zsc);
    if (!canModifyOptions(zsc, account)) {
        throw ServiceException.PERM_DENIED("can not modify options");
    }
    ZimletUserProperties props = ZimletUserProperties.getProperties(account);
    int numUserproperties = request.listElements(AccountConstants.E_PROPERTY).size();
    if (numUserproperties > account.getLongAttr(Provisioning.A_zimbraZimletUserPropertiesMaxNumEntries, 150)) {
        throw AccountServiceException.TOO_MANY_ZIMLETUSERPROPERTIES();
    }
    for (Element e : request.listElements(AccountConstants.E_PROPERTY)) {
        props.setProperty(e.getAttribute(AccountConstants.A_ZIMLET), e.getAttribute(AccountConstants.A_NAME), e.getText());
    }
    props.saveProperties(account);
    Element response = zsc.createElement(AccountConstants.MODIFY_PROPERTIES_RESPONSE);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) ZimletUserProperties(com.zimbra.cs.zimlet.ZimletUserProperties)

Example 23 with ZimbraSoapContext

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

the class ResetPassword method handle.

public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    if (!checkPasswordSecurity(context)) {
        throw ServiceException.INVALID_REQUEST("clear text password is not allowed", null);
    }
    Provisioning prov = Provisioning.getInstance();
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    ResetPasswordRequest req = JaxbUtil.elementToJaxb(request);
    req.validateResetPasswordRequest();
    AuthToken at = zsc.getAuthToken();
    AuthProvider.validateAuthToken(prov, at, false);
    Account acct = at.getAccount();
    boolean locked = acct.getBooleanAttr(Provisioning.A_zimbraPasswordLocked, false);
    if (locked) {
        throw AccountServiceException.PASSWORD_LOCKED();
    }
    ResetPasswordUtil.validateFeatureResetPasswordStatus(acct);
    String newPassword = req.getPassword();
    checkPasswordStrength(prov, acct, newPassword);
    // proxy if required
    if (!Provisioning.onLocalServer(acct)) {
        try {
            return proxyRequest(request, context, acct.getId());
        } catch (ServiceException e) {
            // if something went wrong proxying the request, just execute it locally
            if (ServiceException.PROXY_ERROR.equals(e.getCode())) {
                ZimbraLog.account.warn("encountered proxy error", e);
            } else {
                // but if it's a real error, it's a real error
                throw e;
            }
        }
    }
    setPasswordAndPurgeAuthTokens(prov, acct, newPassword);
    Element response = zsc.createElement(AccountConstants.E_RESET_PASSWORD_RESPONSE);
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) ResetPasswordRequest(com.zimbra.soap.account.message.ResetPasswordRequest) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) AuthToken(com.zimbra.cs.account.AuthToken) Provisioning(com.zimbra.cs.account.Provisioning)

Example 24 with ZimbraSoapContext

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

the class SubscribeDistributionList method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    Account acct = getRequestedAccount(zsc);
    if (!canAccessAccount(zsc, acct)) {
        throw ServiceException.PERM_DENIED("can not access account");
    }
    Element response = zsc.createElement(AccountConstants.SUBSCRIBE_DISTRIBUTION_LIST_RESPONSE);
    Group group = getGroupBasic(request, prov);
    SubscribeDistributionListHandler handler = new SubscribeDistributionListHandler(group, request, response, prov, acct);
    handler.handle();
    return response;
}
Also used : Account(com.zimbra.cs.account.Account) Group(com.zimbra.cs.account.Group) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Element(com.zimbra.common.soap.Element) Provisioning(com.zimbra.cs.account.Provisioning)

Example 25 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)

Aggregations

ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)410 Element (com.zimbra.common.soap.Element)322 Account (com.zimbra.cs.account.Account)175 Provisioning (com.zimbra.cs.account.Provisioning)164 Mailbox (com.zimbra.cs.mailbox.Mailbox)126 OperationContext (com.zimbra.cs.mailbox.OperationContext)95 ItemId (com.zimbra.cs.service.util.ItemId)60 Server (com.zimbra.cs.account.Server)48 ServiceException (com.zimbra.common.service.ServiceException)43 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)43 HashMap (java.util.HashMap)42 Domain (com.zimbra.cs.account.Domain)34 ArrayList (java.util.ArrayList)27 HashSet (java.util.HashSet)26 IOException (java.io.IOException)24 Test (org.junit.Test)20 Message (com.zimbra.cs.mailbox.Message)18 Group (com.zimbra.cs.account.Group)17 CalendarItem (com.zimbra.cs.mailbox.CalendarItem)17 MimeMessage (javax.mail.internet.MimeMessage)16