use of com.zimbra.common.account.Key.AccountBy in project zm-mailbox by Zimbra.
the class LockoutMailbox method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = super.getZimbraSoapContext(context);
LockoutMailboxRequest req = JaxbUtil.elementToJaxb(request);
AccountNameSelector acctSel = req.getAccount();
if (acctSel == null) {
throw ServiceException.INVALID_REQUEST(String.format("missing <%s>", AdminConstants.E_ACCOUNT), null);
}
String accountSelectorKey = acctSel.getKey();
AccountBy by = acctSel.getBy().toKeyAccountBy();
Provisioning prov = Provisioning.getInstance();
Account account = prov.get(by, accountSelectorKey, zsc.getAuthToken());
defendAgainstAccountOrCalendarResourceHarvesting(account, by, accountSelectorKey, zsc, Admin.R_moveAccountMailbox, Admin.R_moveCalendarResourceMailbox);
// Reload account to pick up any changes made by other servers.
prov.reload(account);
// check rights
checkRights(zsc, context, account);
String method = request.getAttribute(AdminConstants.A_OPERATION, AdminConstants.A_START);
if (method.equalsIgnoreCase(AdminConstants.A_START)) {
MailboxManager.getInstance().lockoutMailbox(account.getId());
} else if (method.equalsIgnoreCase(AdminConstants.A_END)) {
MailboxManager.getInstance().undoLockout(account.getId());
} else {
throw ServiceException.FAILURE("Unknown lockout method " + method, null);
}
return zsc.createElement(AdminConstants.LOCKOUT_MAILBOX_RESPONSE);
}
use of com.zimbra.common.account.Key.AccountBy in project zm-mailbox by Zimbra.
the class GalSyncAccountUtil method deleteGalSyncAccount.
private Element deleteGalSyncAccount(String name, String id) throws ServiceException, IOException {
mTransport = null;
try {
mTransport = new SoapHttpTransport(mAdminURL);
auth();
mTransport.setAuthToken(mAuth);
XMLElement req = new XMLElement(AdminConstants.DELETE_GAL_SYNC_ACCOUNT_REQUEST);
Element acct = req.addElement(AdminConstants.E_ACCOUNT);
String account;
AccountBy by;
if (name == null) {
by = AccountBy.id;
account = id;
} else {
by = AccountBy.name;
account = name;
}
acct.addAttribute(AdminConstants.A_BY, by.name());
acct.setText(account);
return mTransport.invokeWithoutSession(req);
} finally {
if (mTransport != null)
mTransport.shutdown();
}
}
use of com.zimbra.common.account.Key.AccountBy in project zm-mailbox by Zimbra.
the class GetAccount method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
GetAccountRequest req = JaxbUtil.elementToJaxb(request);
AccountSelector acctSel = req.getAccount();
if (acctSel == null) {
throw ServiceException.INVALID_REQUEST(String.format("missing <%s>", AdminConstants.E_ACCOUNT), null);
}
String accountSelectorKey = acctSel.getKey();
AccountBy by = acctSel.getBy().toKeyAccountBy();
Account account = prov.get(by, accountSelectorKey, zsc.getAuthToken());
defendAgainstAccountHarvesting(account, by, accountSelectorKey, zsc, Admin.R_getAccountInfo);
AdminAccessControl aac = checkAccountRight(zsc, account, AdminRight.PR_ALWAYS_ALLOW);
Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_RESPONSE);
boolean applyCos = !Boolean.FALSE.equals(req.isApplyCos());
Set<String> reqAttrs = getReqAttrs(req.getAttrs(), AttributeClass.account);
ToXML.encodeAccount(response, account, applyCos, reqAttrs, aac.getAttrRightChecker(account));
return response;
}
use of com.zimbra.common.account.Key.AccountBy in project zm-mailbox by Zimbra.
the class GetAccountInfo method handle.
/* (non-Javadoc)
* @see com.zimbra.soap.DocumentHandler#handle(org.dom4j.Element, java.util.Map)
*/
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
GetAccountInfoRequest req = JaxbUtil.elementToJaxb(request);
AccountBy accountBy = req.getAccount().getBy().toKeyAccountBy();
String accountSelectorKey = req.getAccount().getKey();
Provisioning prov = Provisioning.getInstance();
Account account = prov.get(accountBy, accountSelectorKey, zsc.getAuthToken());
defendAgainstAccountOrCalendarResourceHarvesting(account, accountBy, accountSelectorKey, zsc, Admin.R_getAccountInfo, Admin.R_getCalendarResourceInfo);
Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_INFO_RESPONSE);
response.addNonUniqueElement(AdminConstants.E_NAME).setText(account.getName());
addAttr(response, Provisioning.A_zimbraId, account.getId());
addAttr(response, Provisioning.A_zimbraMailHost, account.getAttr(Provisioning.A_zimbraMailHost));
doCos(account, response);
addUrls(response, account);
return response;
}
use of com.zimbra.common.account.Key.AccountBy in project zm-mailbox by Zimbra.
the class GetAccountMembership method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
GetAccountMembershipRequest req = JaxbUtil.elementToJaxb(request);
AccountBy acctBy = req.getAccount().getBy().toKeyAccountBy();
String accountSelectorKey = req.getAccount().getKey();
Account account = prov.get(acctBy, accountSelectorKey, zsc.getAuthToken());
defendAgainstAccountHarvesting(account, acctBy, accountSelectorKey, zsc, Admin.R_getAccountMembership);
HashMap<String, String> via = new HashMap<String, String>();
List<Group> groups = prov.getGroups(account, false, via);
Element response = zsc.createElement(AdminConstants.GET_ACCOUNT_MEMBERSHIP_RESPONSE);
for (Group group : groups) {
Element eDL = response.addNonUniqueElement(AdminConstants.E_DL);
eDL.addAttribute(AdminConstants.A_NAME, group.getName());
eDL.addAttribute(AdminConstants.A_ID, group.getId());
eDL.addAttribute(AdminConstants.A_DYNAMIC, group.isDynamic());
String viaDl = via.get(group.getName());
if (viaDl != null) {
eDL.addAttribute(AdminConstants.A_VIA, viaDl);
}
try {
if (group.isDynamic()) {
checkDynamicGroupRight(zsc, (DynamicGroup) group, needGetAttrsRight());
} else {
checkDistributionListRight(zsc, (DistributionList) group, needGetAttrsRight());
}
String isAdminGroup = group.getAttr(Provisioning.A_zimbraIsAdminGroup);
if (isAdminGroup != null) {
eDL.addNonUniqueElement(AdminConstants.E_A).addAttribute(AdminConstants.A_N, Provisioning.A_zimbraIsAdminGroup).setText(isAdminGroup);
}
} catch (ServiceException e) {
if (ServiceException.PERM_DENIED.equals(e.getCode())) {
ZimbraLog.acl.warn("no permission to view %s of dl %s", Provisioning.A_zimbraIsAdminGroup, group.getName());
}
}
}
return response;
}
Aggregations