use of com.zimbra.soap.admin.message.RenameAccountRequest in project zm-mailbox by Zimbra.
the class TestDomainAdmin method testGetAccountInDiffDomain.
@Test
public void testGetAccountInDiffDomain() throws Exception {
Account acct = TestJaxbProvisioning.ensureAccountExists(DIFF_ACCT);
String acctId = acct.getId();
String domAdminId = createAdminConsoleStyleDomainAdmin(DOMADMIN);
SoapProvisioning domAdminSoapProv = getSoapProvisioning(DOMADMIN, TestUtil.DEFAULT_PASSWORD);
GetAccountRequest getAcctReq = new GetAccountRequest(AccountSelector.fromName(DIFF_ACCT), true);
try {
domAdminSoapProv.invokeJaxb(getAcctReq);
fail("GetAccountRequest succeeded for account in other domain!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
try {
domAdminSoapProv.invokeJaxbOnTargetAccount(getAcctReq, acctId);
fail("GetAccountRequest succeeded for account in other domain!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
// try non-existent acct
getAcctReq = new GetAccountRequest(AccountSelector.fromName(DIFF_ACCT2), true);
try {
domAdminSoapProv.invokeJaxb(getAcctReq);
fail("GetAccountRequest succeeded for non-existent account in other domain!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
GetMailboxRequest gmReq = new GetMailboxRequest(new MailboxByAccountIdSelector(acctId));
try {
domAdminSoapProv.invokeJaxb(gmReq);
fail("GetMailboxRequest succeeded for account in other domain!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
try {
domAdminSoapProv.invokeJaxbOnTargetAccount(gmReq, acctId);
fail("GetMailboxRequest succeeded for account in other domain!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
AddAccountAliasResponse aaaResp;
try {
aaaResp = domAdminSoapProv.invokeJaxb(new AddAccountAliasRequest(acctId, ALIAS_FOR_TARGET_ACCT));
fail("AddAccountAliasRequest succeeded for account in other domain!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
try {
aaaResp = domAdminSoapProv.invokeJaxbOnTargetAccount(new AddAccountAliasRequest(acctId, ALIAS_FOR_TARGET_ACCT2), acctId);
fail("AddAccountAliasRequest succeeded for account in other domain!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
aaaResp = adminSoapProv.invokeJaxb(new AddAccountAliasRequest(acctId, ALIAS_FOR_TARGET_ACCT));
assertNotNull("AddAccountAliasResponse for " + TARGET_ACCT + " as FULL ADMIN", aaaResp);
try {
domAdminSoapProv.invokeJaxb(new RemoveAccountAliasRequest(acctId, ALIAS_FOR_TARGET_ACCT));
fail("RemoveAccountAliasRequest succeeded for account in other domain!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
try {
domAdminSoapProv.invokeJaxb(new RenameAccountRequest(acctId, TARGET_ACCT_RENAMED));
fail("RenameAccountRequest succeeded for account in other domain!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
try {
domAdminSoapProv.invokeJaxb(new DeleteAccountRequest(acctId));
fail("DeleteAccountRequest succeeded for account in other domain!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
}
use of com.zimbra.soap.admin.message.RenameAccountRequest in project zm-mailbox by Zimbra.
the class TestDomainAdmin method testGetAccountInDomAdminDomain.
@Test
public void testGetAccountInDomAdminDomain() throws Exception {
String domAdminId = createAdminConsoleStyleDomainAdmin(DOMADMIN);
SoapProvisioning domAdminSoapProv = getSoapProvisioning(DOMADMIN, TestUtil.DEFAULT_PASSWORD);
CreateAccountResponse caResp;
caResp = domAdminSoapProv.invokeJaxb(new CreateAccountRequest(TARGET_ACCT, TestUtil.DEFAULT_PASSWORD));
assertNotNull("CreateAccountResponse for " + TARGET_ACCT + " simple as domAdmin", caResp);
String acctId = caResp.getAccount().getId();
GetAccountRequest getAcctReq = new GetAccountRequest(AccountSelector.fromName(TARGET_ACCT), true);
GetAccountResponse getAcctResp = domAdminSoapProv.invokeJaxb(getAcctReq);
assertNotNull("GetAccountResponse for " + TARGET_ACCT + " simple as domAdmin", getAcctResp);
getAcctResp = domAdminSoapProv.invokeJaxbOnTargetAccount(getAcctReq, acctId);
assertNotNull("GetAccountResponse for " + TARGET_ACCT + " as domAdmin specifying target acct", getAcctResp);
GetMailboxRequest gmReq = new GetMailboxRequest(new MailboxByAccountIdSelector(acctId));
GetMailboxResponse gmResp = domAdminSoapProv.invokeJaxb(gmReq);
assertNotNull("GetMailboxResponse for " + TARGET_ACCT + " simple as domAdmin", gmResp);
gmResp = domAdminSoapProv.invokeJaxbOnTargetAccount(gmReq, acctId);
assertNotNull("GetMailboxResponse for " + TARGET_ACCT + " as domAdmin specifying target acct", gmResp);
AddAccountAliasResponse aaaResp;
aaaResp = domAdminSoapProv.invokeJaxb(new AddAccountAliasRequest(acctId, ALIAS_FOR_TARGET_ACCT));
assertNotNull("AddAccountAliasResponse for " + TARGET_ACCT + " simple as domAdmin", aaaResp);
aaaResp = domAdminSoapProv.invokeJaxbOnTargetAccount(new AddAccountAliasRequest(acctId, ALIAS_FOR_TARGET_ACCT2), acctId);
assertNotNull("AddAccountAliasResponse for " + TARGET_ACCT + " as domAdmin specifying target acct", aaaResp);
RemoveAccountAliasResponse daaResp;
daaResp = domAdminSoapProv.invokeJaxb(new RemoveAccountAliasRequest(acctId, ALIAS_FOR_TARGET_ACCT));
assertNotNull("RemoveAccountAliasResponse for " + TARGET_ACCT + " simple as domAdmin", daaResp);
daaResp = domAdminSoapProv.invokeJaxbOnTargetAccount(new RemoveAccountAliasRequest(acctId, ALIAS_FOR_TARGET_ACCT2), acctId);
assertNotNull("RemoveAccountAliasResponse for " + TARGET_ACCT + " as domAdmin specifying target acct", daaResp);
RenameAccountResponse renAResp;
renAResp = domAdminSoapProv.invokeJaxb(new RenameAccountRequest(acctId, TARGET_ACCT_RENAMED));
assertNotNull("RenameAccountResponse for " + TARGET_ACCT + " simple as domAdmin", renAResp);
renAResp = domAdminSoapProv.invokeJaxb(new RenameAccountRequest(acctId, TARGET_ACCT));
assertNotNull("RenameAccountResponse for " + TARGET_ACCT + " as domAdmin specifying target acct", renAResp);
DeleteAccountRequest delAcctReq;
DeleteAccountResponse delAcctResp;
delAcctReq = new DeleteAccountRequest(null);
try {
delAcctResp = domAdminSoapProv.invokeJaxbOnTargetAccount(delAcctReq, acctId);
fail("DeleteAccountRequest succeeded in spite of having no 'id' specified!!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "invalid request: missing required attribute: id");
}
delAcctReq = new DeleteAccountRequest(acctId);
delAcctResp = domAdminSoapProv.invokeJaxbOnTargetAccount(delAcctReq, acctId);
assertNotNull("DeleteAccountResponse for " + TARGET_ACCT + " as domAdmin specifying target acct", delAcctResp);
try {
getAcctResp = domAdminSoapProv.invokeJaxb(getAcctReq);
fail("GetAccountRequest succeeded after delete!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "no such account: ");
}
try {
getAcctResp = domAdminSoapProv.invokeJaxb(new GetAccountRequest(AccountSelector.fromId(acctId), true));
fail("GetAccountRequest succeeded after delete!");
} catch (SoapFaultException sfe) {
// because by id not name
checkSoapReason(sfe, "permission denied: can not access account ");
}
try {
getAcctResp = domAdminSoapProv.invokeJaxbOnTargetAccount(getAcctReq, acctId);
fail("GetAccountRequest succeeded after delete!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
try {
gmResp = domAdminSoapProv.invokeJaxb(gmReq);
fail("GetMailboxRequest succeeded after delete!");
} catch (SoapFaultException sfe) {
// because by id
checkSoapReason(sfe, "permission denied: can not access account ");
}
try {
gmResp = domAdminSoapProv.invokeJaxbOnTargetAccount(gmReq, acctId);
fail("GetMailboxRequest succeeded after delete!");
} catch (SoapFaultException sfe) {
checkSoapReason(sfe, "permission denied: can not access account ");
}
}
use of com.zimbra.soap.admin.message.RenameAccountRequest in project zm-mailbox by Zimbra.
the class RenameAccount method handle.
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
ZimbraSoapContext zsc = getZimbraSoapContext(context);
Provisioning prov = Provisioning.getInstance();
RenameAccountRequest req = zsc.elementToJaxb(request);
String id = req.getId();
String newName = req.getNewName();
Account account = prov.get(AccountBy.id, id, zsc.getAuthToken());
defendAgainstAccountHarvesting(account, AccountBy.id, id, zsc, Admin.R_renameAccount);
String oldName = account.getName();
// check if the admin can rename the account
checkAccountRight(zsc, account, Admin.R_renameAccount);
// check if the admin can "create account" in the domain (can be same or diff)
checkDomainRightByEmail(zsc, newName, Admin.R_createAccount);
Mailbox mbox = Provisioning.onLocalServer(account) ? MailboxManager.getInstance().getMailboxByAccount(account) : null;
prov.renameAccount(id, newName);
if (mbox != null) {
mbox.renameMailbox(oldName, newName);
}
ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "RenameAccount", "name", oldName, "newName", newName }));
// get again with new name...
account = prov.get(AccountBy.id, id, true, zsc.getAuthToken());
if (account == null) {
throw ServiceException.FAILURE("unable to get account after rename: " + id, null);
}
Element response = zsc.createElement(AdminConstants.RENAME_ACCOUNT_RESPONSE);
ToXML.encodeAccount(response, account);
return response;
}
Aggregations