Search in sources :

Example 36 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class DataSourceCallback method lookupAccountsFromDB.

// look up all accounts on this server
private List<Account> lookupAccountsFromDB(Provisioning prov) throws ServiceException {
    Set<String> accountIds = null;
    List<Account> accts = new ArrayList<Account>();
    DbConnection conn = null;
    try {
        conn = DbPool.getConnection();
        accountIds = DbMailbox.listAccountIds(conn);
    } finally {
        DbPool.quietClose(conn);
    }
    for (String accountId : accountIds) {
        Account account = null;
        try {
            account = prov.get(AccountBy.id, accountId);
        } catch (ServiceException e) {
            ZimbraLog.datasource.debug("Unable to look up account for id %s: %s", accountId, e.toString());
        }
        if (account != null) {
            accts.add(account);
        }
    }
    return accts;
}
Also used : Account(com.zimbra.cs.account.Account) ServiceException(com.zimbra.common.service.ServiceException) ArrayList(java.util.ArrayList) DbConnection(com.zimbra.cs.db.DbPool.DbConnection)

Example 37 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class DisplayName method preModify.

@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
    if (!((entry instanceof Account) || (entry instanceof DistributionList)))
        return;
    String displayName;
    // update cn only if we are not unsetting display name(cn is required for ZIMBRA_DEFAULT_PERSON_OC)
    SingleValueMod mod = singleValueMod(attrName, value);
    if (mod.unsetting())
        return;
    else
        displayName = mod.value();
    String namingRdnAttr = null;
    Provisioning prov = Provisioning.getInstance();
    if (prov instanceof LdapProv) {
        namingRdnAttr = ((LdapProv) prov).getDIT().getNamingRdnAttr(entry);
    }
    // update cn only if it is not the naming attr
    if (// non LdapProvisioning, pass thru
    namingRdnAttr == null || !namingRdnAttr.equals(Provisioning.A_cn)) {
        if (!attrsToModify.containsKey(Provisioning.A_cn)) {
            attrsToModify.put(Provisioning.A_cn, displayName);
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) Provisioning(com.zimbra.cs.account.Provisioning) LdapProv(com.zimbra.cs.account.ldap.LdapProv) DistributionList(com.zimbra.cs.account.DistributionList)

Example 38 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class PlainTextSignature method preModify.

@Override
public void preModify(CallbackContext context, String attrName, Object value, Map attrsToModify, Entry entry) throws ServiceException {
    SingleValueMod mod = singleValueMod(attrName, value);
    if (mod.unsetting())
        return;
    Account account;
    if (entry instanceof Account) {
        account = (Account) entry;
    } else if (entry instanceof Identity) {
        account = ((Identity) entry).getAccount();
    } else if (entry instanceof DataSource) {
        account = ((DataSource) entry).getAccount();
    } else {
        return;
    }
    Signature sig = Provisioning.getInstance().get(account, Key.SignatureBy.id, mod.value());
    if (sig == null) {
        throw ServiceException.INVALID_REQUEST("No such signature " + mod.value() + " for account " + account.getName(), null);
    }
    String sigAttr = SignatureUtil.mimeTypeToAttrName(MimeConstants.CT_TEXT_PLAIN);
    String plainSig = sig.getAttr(sigAttr, null);
    if (StringUtil.isNullOrEmpty(plainSig)) {
        throw ServiceException.INVALID_REQUEST("Signature " + mod.value() + " must have plain text content", null);
    }
}
Also used : Account(com.zimbra.cs.account.Account) Signature(com.zimbra.cs.account.Signature) Identity(com.zimbra.cs.account.Identity) DataSource(com.zimbra.cs.account.DataSource)

Example 39 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class PrefMailForwardingAddress method preModify.

/*
     * for modifying, we can get the max len from entry.getAccount
     * 
     * if the account entry is being created, or if someone is setting it (not a valid supported case) 
     * directly with createAccount, entry will be null, and we cannot do entry.getAccount to get the 
     * max length.  So we pass the max length in the context.
     * 
     * FIXME: currently callback keys are not set in LdapProvisioning because preModify is called before
     *        cos is decided.
     */
@Override
public void preModify(CallbackContext context, String attrName, Object attrValue, Map attrsToModify, Entry entry) throws ServiceException {
    if (entry != null && !(entry instanceof Account)) {
        return;
    }
    SingleValueMod mod = singleValueMod(attrsToModify, attrName);
    if (mod.unsetting())
        return;
    int maxLen = -1;
    int maxAddrs = -1;
    String maxLenInCtxt = context.getData(DataKey.MAIL_FORWARDING_ADDRESS_MAX_LEN);
    if (maxLenInCtxt != null) {
        try {
            maxLen = Integer.parseInt(maxLenInCtxt);
        } catch (NumberFormatException e) {
            ZimbraLog.account.warn("encountered invalid " + DataKey.MAIL_FORWARDING_ADDRESS_MAX_LEN.name() + ": " + maxLenInCtxt);
        }
    }
    String maxAddrsInCtxt = context.getData(DataKey.MAIL_FORWARDING_ADDRESS_MAX_NUM_ADDRS);
    if (maxAddrsInCtxt != null) {
        try {
            maxLen = Integer.parseInt(maxAddrsInCtxt);
        } catch (NumberFormatException e) {
            ZimbraLog.account.warn("encountered invalid " + DataKey.MAIL_FORWARDING_ADDRESS_MAX_NUM_ADDRS.name() + ": " + maxAddrsInCtxt);
        }
    }
    // if we don't have a good max len/addrs value in the context, get it from the entry
    if (entry == null)
        return;
    Account account = (Account) entry;
    if (maxLen == -1)
        maxLen = account.getMailForwardingAddressMaxLength();
    if (maxAddrs == -1)
        maxAddrs = account.getMailForwardingAddressMaxNumAddrs();
    String newValue = mod.value();
    if (newValue.length() > maxLen) {
        throw ServiceException.INVALID_REQUEST("value is too long, the limit(" + Provisioning.A_zimbraMailForwardingAddressMaxLength + ") is " + maxLen, null);
    }
    String[] addrs = newValue.split(",");
    if (addrs.length > maxAddrs) {
        throw ServiceException.INVALID_REQUEST("value is too long, the limit(" + Provisioning.A_zimbraMailForwardingAddressMaxNumAddrs + ") is " + maxAddrs, null);
    }
}
Also used : Account(com.zimbra.cs.account.Account)

Example 40 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class SoapProvisioning method getAllAdminAccounts.

// SoapProvisioning only, for zmprov
public List<Account> getAllAdminAccounts(boolean applyDefault) throws ServiceException {
    ArrayList<Account> result = new ArrayList<Account>();
    GetAllAdminAccountsResponse resp = invokeJaxb(new GetAllAdminAccountsRequest(applyDefault));
    for (AccountInfo acct : resp.getAccountList()) {
        result.add(new SoapAccount(acct, this));
    }
    return result;
}
Also used : Account(com.zimbra.cs.account.Account) GetAllAdminAccountsResponse(com.zimbra.soap.admin.message.GetAllAdminAccountsResponse) GetAllAdminAccountsRequest(com.zimbra.soap.admin.message.GetAllAdminAccountsRequest) ArrayList(java.util.ArrayList) AccountInfo(com.zimbra.soap.admin.type.AccountInfo)

Aggregations

Account (com.zimbra.cs.account.Account)1444 Test (org.junit.Test)691 Mailbox (com.zimbra.cs.mailbox.Mailbox)468 OperationContext (com.zimbra.cs.mailbox.OperationContext)354 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)331 Message (com.zimbra.cs.mailbox.Message)315 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)294 Element (com.zimbra.common.soap.Element)280 ServiceException (com.zimbra.common.service.ServiceException)261 ItemId (com.zimbra.cs.service.util.ItemId)248 Provisioning (com.zimbra.cs.account.Provisioning)234 HashMap (java.util.HashMap)179 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)175 Domain (com.zimbra.cs.account.Domain)149 MimeMessage (javax.mail.internet.MimeMessage)125 GuestAccount (com.zimbra.cs.account.GuestAccount)107 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)100 SyntaxException (org.apache.jsieve.exception.SyntaxException)90 AccountServiceException (com.zimbra.cs.account.AccountServiceException)87 Header (javax.mail.Header)84