use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class MailboxManager method getMailboxSizes.
/**
* Returns the zimbra IDs and approximate sizes for all mailboxes on
* the system. Note that mailboxes are created lazily, so there may be
* accounts homed on this system for whom there is is not yet a mailbox
* and hence are not included in the returned <code>Map</code>.
*
* @throws ServiceException The following error codes are possible:<ul>
* <li><code>service.FAILURE</code> - an error occurred while accessing
* the database; a SQLException is encapsulated</ul>
*/
public Map<String, Long> getMailboxSizes(List<NamedEntry> accounts) throws ServiceException {
List<Integer> requested;
synchronized (this) {
if (accounts == null) {
requested = new ArrayList<Integer>(mailboxIds.values());
} else {
requested = new ArrayList<Integer>(accounts.size());
for (NamedEntry account : accounts) {
Integer mailboxId = mailboxIds.get(account.getId());
if (mailboxId != null)
requested.add(mailboxId);
}
}
}
DbConnection conn = null;
try {
conn = DbPool.getConnection();
return DbMailbox.getMailboxSizes(conn, requested);
} finally {
if (conn != null)
DbPool.quietClose(conn);
}
}
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;
}
}
use of com.zimbra.cs.account.NamedEntry in project zm-mailbox by Zimbra.
the class TestDistListACL method doCheckSentToDistListGuestRight.
private void doCheckSentToDistListGuestRight(DistributionList targetDl, String email, String guest, boolean expected) throws ServiceException {
ZimbraLog.test.info("DL name %s ID %s", targetDl.getName(), targetDl.getId());
Group group = prov.getGroupBasic(Key.DistributionListBy.name, listAddress);
Assert.assertNotNull("Unable to find Group object for DL by name", group);
AccessManager.ViaGrant via = new AccessManager.ViaGrant();
NamedEntry ne = GranteeType.lookupGrantee(prov, GranteeType.GT_GUEST, GranteeBy.name, email);
MailTarget grantee = null;
if (ne instanceof MailTarget) {
grantee = (MailTarget) ne;
}
boolean result = RightCommand.checkRight(prov, "dl", /* targetType */
TargetBy.name, listAddress, grantee, RightConsts.RT_sendToDistList, null, /* attrs */
via);
if (expected) {
Assert.assertTrue(String.format("%s should be able to send to DL (as guest %s)", email, guest), accessMgr.canDo(email, group, User.R_sendToDistList, false));
Assert.assertTrue(String.format("%s should have right to send to DL (as guest %s)", email, guest), result);
ZimbraLog.test.info("Test for %s against dom %s Via=%s", email, guest, via);
} else {
Assert.assertFalse(String.format("%s should NOT be able to send to DL (because not guest %s)", email, guest), accessMgr.canDo(email, group, User.R_sendToDistList, false));
Assert.assertFalse(String.format("%s should NOT have right to send to DL (because not guest %s)", email, guest), result);
}
}
Aggregations