use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class JWTBasedAuthTest method testAccountAndExpiresJWT.
@Test
public void testAccountAndExpiresJWT() {
Account acct;
try {
acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
AuthToken at = AuthProvider.getAuthToken(acct, 0, TokenType.JWT);
validateJWT(at, acct.getId());
} catch (ServiceException e) {
Assert.fail("testAccountAndExpiresJWT failed");
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class AutoProvision method createAccount.
protected Account createAccount(String acctZimbraName, ExternalEntry externalEntry, String password, AutoProvMode mode) throws ServiceException {
ZAttributes externalAttrs = externalEntry.getAttrs();
Map<String, Object> zimbraAttrs = mapAttrs(externalAttrs);
/*
// TODO: should we do this?
String zimbraPassword = RandomPassword.generate();
zimbraAttrs.put(Provisioning.A_zimbraPasswordMustChange, Provisioning.TRUE);
*/
// if password is provided, use it
String zimbraPassword = null;
if (password != null) {
zimbraPassword = password;
zimbraAttrs.remove(Provisioning.A_userPassword);
}
Account acct = null;
try {
acct = prov.createAccount(acctZimbraName, zimbraPassword, zimbraAttrs);
} catch (ServiceException e) {
if (AccountServiceException.ACCOUNT_EXISTS.equals(e.getCode())) {
ZimbraLog.autoprov.debug("account %s already exists", acctZimbraName);
// the account already exists, that's fine, just return null
switch(mode) {
case EAGER:
// that's fine, just return null
return null;
case LAZY:
case MANUAL:
default:
throw e;
}
} else {
throw e;
}
}
ZimbraLog.autoprov.info("auto provisioned account: " + acctZimbraName);
ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "auto provision Account", "name", acct.getName(), "id", acct.getId() }, zimbraAttrs));
// send notification email
try {
sendNotifMessage(acct, zimbraPassword);
} catch (ServiceException e) {
// exception during sending notif email should not fail this method
ZimbraLog.autoprov.warn("unable to send auto provision notification email", e);
}
// invoke post create listener if configured
try {
AutoProvisionListener listener = AutoProvisionCachedInfo.getInfo(domain).getListener();
if (listener != null) {
listener.postCreate(domain, acct, externalEntry.getDN());
} else {
// eager mode should configure Listener
if (mode == AutoProvMode.EAGER) {
ZimbraLog.autoprov.warn("EAGER mode should configure " + Provisioning.A_zimbraAutoProvListenerClass);
}
}
} catch (ServiceException e) {
// exception during the post create listener should not fail this method
ZimbraLog.autoprov.warn("encountered error in post auto provision listener", e);
}
return acct;
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class AutoProvisionEager method createAccountBatch.
private void createAccountBatch() throws ServiceException {
long polledAt = System.currentTimeMillis();
List<ExternalEntry> entries = new ArrayList<ExternalEntry>();
boolean hitSizeLimitExceededException = searchAccounts(entries, domain.getAutoProvBatchSize());
ZimbraLog.autoprov.info("%d external LDAP entries returned as search result", entries.size());
int stuckAcctNum = 0;
for (ExternalEntry entry : entries) {
if (scheduler.isShutDownRequested()) {
ZimbraLog.autoprov.info("eager auto provision aborted");
return;
}
try {
ZAttributes externalAttrs = entry.getAttrs();
String acctZimbraName = mapName(externalAttrs, null);
ZimbraLog.autoprov.info("auto creating account in EAGER mode: " + acctZimbraName + ", dn=\"" + entry.getDN() + "\"");
Account acct = createAccount(acctZimbraName, entry, null, AutoProvMode.EAGER);
if (acct == null) {
stuckAcctNum++;
}
} catch (ServiceException e) {
// log and continue with next entry
ZimbraLog.autoprov.warn("unable to auto create account, dn=\"" + entry.getDN() + "\"", e);
stuckAcctNum++;
}
}
// in the last batch we won't hit size limit, then the last polled timstamp will be set, we can forget about the stuck ones
if (hitSizeLimitExceededException && entries.size() == stuckAcctNum) {
ZimbraLog.autoprov.info("search result contains unsuccessful external entries, increasing batch size by %d", stuckAcctNum);
int currentBatchSize = domain.getAutoProvBatchSize();
domain.setAutoProvBatchSize(currentBatchSize + stuckAcctNum);
ZimbraLog.autoprov.info("batch size is %d now", domain.getAutoProvBatchSize());
}
//
if (!hitSizeLimitExceededException) {
String lastPolledAt = LdapDateUtil.toGeneralizedTimeWithMs(new Date(polledAt));
ZimbraLog.autoprov.info("Auto Provisioning has finished for now, setting last polled timestamp: " + lastPolledAt);
domain.setAutoProvLastPolledTimestampAsString(lastPolledAt);
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class TrustedSenderList method preModify.
@SuppressWarnings("unchecked")
@Override
public void preModify(CallbackContext context, String name, Object value, @SuppressWarnings("rawtypes") Map mod, Entry entry) throws ServiceException {
if (context.isCreate() || !(entry instanceof Account)) {
return;
}
// Skip if already processed.
if (context.isDoneAndSetIfNot(TrustedSenderList.class)) {
return;
}
Account account = (Account) entry;
int max = account.getMailTrustedSenderListMaxNumEntries();
Object replace = mod.get(name);
Object add = mod.get("+" + name);
Object remove = mod.get("-" + name);
if (replace != null) {
Set<String> set = getMultiValueSet(replace);
if (set.size() > max) {
throw AccountServiceException.TOO_MANY_TRUSTED_SENDERS(set.size() + " > " + max);
}
} else {
String[] current = account.getMultiAttr(name, false);
if (add != null) {
Set<String> set = getMultiValueSet(add);
if (current.length > 0) {
if (current.length + set.size() > max) {
throw AccountServiceException.TOO_MANY_TRUSTED_SENDERS(current.length + " + " + set.size() + " > " + max);
}
} else {
// copy CoS values
List<String> def = getMultiValue(account.getAttrDefault(name));
if (def.size() + set.size() > max) {
throw AccountServiceException.TOO_MANY_TRUSTED_SENDERS(def.size() + " + " + set.size() + " > " + max);
}
set.addAll(def);
mod.put("+" + name, set);
}
}
if (remove != null) {
if (current.length == 0) {
// copy CoS values
Set<String> def;
if (add == null) {
def = getMultiValueSet(account.getAttrDefault(name));
} else {
// honor the result from "add"
def = (Set<String>) mod.get("+" + name);
assert (def != null);
}
def.removeAll(getMultiValueSet(remove));
mod.remove("-" + name);
mod.put("+" + name, def);
}
}
}
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class DataSourceCallback method scheduleCos.
/**
* Updates data source schedules for all accounts that are on the current server
* and in the given COS.
*/
private void scheduleCos(Cos cos) throws ServiceException {
ZimbraLog.datasource.info("Updating schedule for all DataSources for all accounts in COS %s.", cos.getName());
List<Account> accts;
Provisioning prov = Provisioning.getInstance();
// Look up all account id's for this server
if (prov instanceof LdapProv)
accts = lookupAccountsFromLDAP(prov, cos.getId());
else
accts = lookupAccountsFromDB(prov);
// Update schedules for all data sources on this server
for (Account account : accts) {
if (account != null && Provisioning.ACCOUNT_STATUS_ACTIVE.equals(account.getAccountStatus(prov))) {
Cos accountCos = prov.getCOS(account);
if (accountCos != null && cos.getId().equals(accountCos.getId())) {
scheduleAccount(account);
}
}
}
}
Aggregations