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;
}
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);
}
}
}
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);
}
}
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);
}
}
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;
}
Aggregations