use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class FixCalendarPriority method fixAccounts.
private static void fixAccounts(List<String> acctNames) throws ServiceException {
int numAccts = acctNames.size();
boolean all = (numAccts == 1 && ALL.equals(acctNames.get(0)));
int numFixedAccts = 0;
int numFixedAppts = 0;
List<NamedEntry> accts;
if (all) {
accts = getAccountsOnServer();
} else {
accts = new ArrayList<NamedEntry>(acctNames.size());
for (String name : acctNames) {
try {
accts.add(Provisioning.getInstance().get(AccountBy.name, name));
} catch (ServiceException e) {
ZimbraLog.calendar.error("Error looking up account " + name + ": " + e.getMessage(), e);
}
}
}
numAccts = accts.size();
int every = 10;
for (NamedEntry entry : accts) {
if (!(entry instanceof Account))
continue;
Account acct = (Account) entry;
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
try {
numFixedAppts += mbox.fixAllCalendarItemPriority(null);
} catch (ServiceException e) {
ZimbraLog.calendar.error("Error fixing calendar item priority in mailbox " + mbox.getId() + ": " + e.getMessage(), e);
}
numFixedAccts++;
if (numFixedAccts % every == 0) {
ZimbraLog.calendar.info("Progress: fixed calendar item priority in " + numFixedAccts + "/" + numAccts + " accounts");
}
}
ZimbraLog.calendar.info("Fixed priority in total " + numFixedAppts + " calendar items in " + numFixedAccts + " accounts");
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class FixCalendarTZ method fixAccounts.
private static void fixAccounts(List<String> acctNames, long after, TimeZoneFixupRules tzfixupRules) throws ServiceException {
int numAccts = acctNames.size();
boolean all = (numAccts == 1 && ALL.equals(acctNames.get(0)));
int numFixedAccts = 0;
int numFixedAppts = 0;
List<NamedEntry> accts;
if (all) {
accts = getAccountsOnServer();
} else {
accts = new ArrayList<NamedEntry>(acctNames.size());
for (String name : acctNames) {
try {
accts.add(Provisioning.getInstance().get(AccountBy.name, name));
} catch (ServiceException e) {
ZimbraLog.calendar.error("Error looking up account " + name + ": " + e.getMessage(), e);
}
}
}
numAccts = accts.size();
int every = 10;
for (NamedEntry entry : accts) {
if (!(entry instanceof Account))
continue;
Account acct = (Account) entry;
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
try {
numFixedAppts += mbox.fixAllCalendarItemTZ(null, after, tzfixupRules);
} catch (ServiceException e) {
ZimbraLog.calendar.error("Error fixing timezones in mailbox " + mbox.getId() + ": " + e.getMessage(), e);
}
numFixedAccts++;
if (numFixedAccts % every == 0) {
ZimbraLog.calendar.info("Progress: fixed calendar timezones in " + numFixedAccts + "/" + numAccts + " accounts");
}
}
ZimbraLog.calendar.info("Fixed timezones in total " + numFixedAppts + " calendar items in " + numFixedAccts + " accounts");
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class GrantPermission method lookupGranteeByName.
// orig: FolderAction.lookupGranteeByName
private static NamedEntry lookupGranteeByName(String name, GranteeType type, ZimbraSoapContext zsc) throws ServiceException {
if (type == GranteeType.GT_AUTHUSER || type == GranteeType.GT_PUBLIC || type == GranteeType.GT_GUEST || type == GranteeType.GT_KEY)
return null;
Provisioning prov = Provisioning.getInstance();
// for addresses, default to the authenticated user's domain
if ((type == GranteeType.GT_USER || type == GranteeType.GT_GROUP) && name.indexOf('@') == -1) {
Account authacct = prov.get(AccountBy.id, zsc.getAuthtokenAccountId(), zsc.getAuthToken());
String authname = (authacct == null ? null : authacct.getName());
if (authacct != null)
name += authname.substring(authname.indexOf('@'));
}
NamedEntry nentry = null;
if (name != null)
switch(type) {
case GT_USER:
nentry = lookupEmailAddress(name);
break;
case GT_GROUP:
nentry = prov.get(Key.DistributionListBy.name, name);
break;
case GT_DOMAIN:
nentry = prov.get(Key.DomainBy.name, name);
break;
}
if (nentry != null)
return nentry;
switch(type) {
case GT_USER:
throw AccountServiceException.NO_SUCH_ACCOUNT(name);
case GT_GROUP:
throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(name);
case GT_DOMAIN:
throw AccountServiceException.NO_SUCH_DOMAIN(name);
default:
throw ServiceException.FAILURE("LDAP entry not found for " + name + " : " + type, null);
}
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class GrantPermission method handleACE.
/**
* // orig: FolderAction
*
* @param eACE
* @param zsc
* @param granting true if granting, false if revoking
* @return
* @throws ServiceException
*/
static ZimbraACE handleACE(Element eACE, ZimbraSoapContext zsc, boolean granting) throws ServiceException {
Right right = RightManager.getInstance().getUserRight(eACE.getAttribute(MailConstants.A_RIGHT));
GranteeType gtype = GranteeType.fromCode(eACE.getAttribute(MailConstants.A_GRANT_TYPE));
String zid = eACE.getAttribute(MailConstants.A_ZIMBRA_ID, null);
boolean deny = eACE.getAttributeBool(MailConstants.A_DENY, false);
String secret = null;
NamedEntry nentry = null;
if (gtype == GranteeType.GT_AUTHUSER) {
zid = GuestAccount.GUID_AUTHUSER;
} else if (gtype == GranteeType.GT_PUBLIC) {
zid = GuestAccount.GUID_PUBLIC;
} else if (gtype == GranteeType.GT_GUEST) {
zid = eACE.getAttribute(MailConstants.A_DISPLAY);
if (zid == null || zid.indexOf('@') < 0)
throw ServiceException.INVALID_REQUEST("invalid guest id or password", null);
// make sure they didn't accidentally specify "guest" instead of "usr"
try {
nentry = lookupGranteeByName(zid, GranteeType.GT_USER, zsc);
zid = nentry.getId();
gtype = nentry instanceof DistributionList ? GranteeType.GT_GROUP : GranteeType.GT_USER;
} catch (ServiceException e) {
// this is the normal path, where lookupGranteeByName throws account.NO_SUCH_USER
secret = eACE.getAttribute(MailConstants.A_PASSWORD);
}
} else if (gtype == GranteeType.GT_KEY) {
zid = eACE.getAttribute(MailConstants.A_DISPLAY);
// unlike guest, we do not require the display name to be an email address
/*
if (zid == null || zid.indexOf('@') < 0)
throw ServiceException.INVALID_REQUEST("invalid guest id or key", null);
*/
// unlike guest, we do not fixup grantee type for key grantees if they specify an internal user
// get the optional accesskey
secret = eACE.getAttribute(MailConstants.A_ACCESSKEY, null);
} else if (zid != null) {
nentry = lookupGranteeByZimbraId(zid, gtype, granting);
} else {
nentry = lookupGranteeByName(eACE.getAttribute(MailConstants.A_DISPLAY), gtype, zsc);
zid = nentry.getId();
// make sure they didn't accidentally specify "usr" instead of "grp"
if (gtype == GranteeType.GT_USER && nentry instanceof DistributionList)
gtype = GranteeType.GT_GROUP;
}
RightModifier rightModifier = null;
if (deny)
rightModifier = RightModifier.RM_DENY;
return new ZimbraACE(zid, gtype, right, rightModifier, secret);
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class GrantPermission method lookupGranteeByZimbraId.
// orig: FolderAction.lookupGranteeByZimbraId
private static NamedEntry lookupGranteeByZimbraId(String zid, GranteeType type, boolean granting) throws ServiceException {
Provisioning prov = Provisioning.getInstance();
NamedEntry nentry = null;
try {
switch(type) {
case GT_USER:
nentry = prov.get(AccountBy.id, zid);
if (nentry == null && granting)
throw AccountServiceException.NO_SUCH_ACCOUNT(zid);
else
return nentry;
case GT_GROUP:
nentry = prov.get(Key.DistributionListBy.id, zid);
if (nentry == null && granting)
throw AccountServiceException.NO_SUCH_DISTRIBUTION_LIST(zid);
else
return nentry;
case GT_DOMAIN:
nentry = prov.get(Key.DomainBy.id, zid);
if (nentry == null && granting)
throw AccountServiceException.NO_SUCH_DOMAIN(zid);
else
return nentry;
case GT_GUEST:
case GT_KEY:
case GT_AUTHUSER:
case GT_PUBLIC:
default:
return null;
}
} catch (ServiceException e) {
if (granting)
throw e;
else
return null;
}
}
Aggregations