Search in sources :

Example 1 with DeleteAccountRequest

use of com.zimbra.soap.admin.message.DeleteAccountRequest 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 ");
    }
}
Also used : Account(com.zimbra.cs.account.Account) DeleteAccountRequest(com.zimbra.soap.admin.message.DeleteAccountRequest) AddAccountAliasRequest(com.zimbra.soap.admin.message.AddAccountAliasRequest) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) RemoveAccountAliasRequest(com.zimbra.soap.admin.message.RemoveAccountAliasRequest) GetMailboxRequest(com.zimbra.soap.admin.message.GetMailboxRequest) RenameAccountRequest(com.zimbra.soap.admin.message.RenameAccountRequest) MailboxByAccountIdSelector(com.zimbra.soap.admin.type.MailboxByAccountIdSelector) AddAccountAliasResponse(com.zimbra.soap.admin.message.AddAccountAliasResponse) GetAccountRequest(com.zimbra.soap.admin.message.GetAccountRequest) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 2 with DeleteAccountRequest

use of com.zimbra.soap.admin.message.DeleteAccountRequest in project zm-mailbox by Zimbra.

the class DeleteAccount method handle.

/**
 * Deletes an account and its mailbox.
 */
@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    DeleteAccountRequest req = zsc.elementToJaxb(request);
    String id = req.getId();
    if (null == id) {
        throw ServiceException.INVALID_REQUEST("missing required attribute: " + AdminConstants.E_ID, null);
    }
    // Confirm that the account exists and that the mailbox is located on the current host
    Account account = prov.get(AccountBy.id, id, zsc.getAuthToken());
    defendAgainstAccountHarvesting(account, AccountBy.id, id, zsc, Admin.R_deleteAccount);
    /*
         * bug 69009
         *
         * We delete the mailbox before deleting the LDAP entry.
         * It's possible that a message delivery or other user action could
         * cause the mailbox to be recreated between the mailbox delete step
         * and the LDAP delete step.
         *
         * To prevent this race condition, put the account in "maintenance" mode
         * so mail delivery and any user action is blocked.
         */
    prov.modifyAccountStatus(account, AccountStatus.maintenance.name());
    Mailbox mbox = Provisioning.onLocalServer(account) ? MailboxManager.getInstance().getMailboxByAccount(account, false) : null;
    if (mbox != null) {
        mbox.deleteMailbox();
    }
    prov.deleteAccount(id);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "DeleteAccount", "name", account.getName(), "id", account.getId() }));
    return zsc.jaxbToElement(new DeleteAccountResponse());
}
Also used : Account(com.zimbra.cs.account.Account) DeleteAccountRequest(com.zimbra.soap.admin.message.DeleteAccountRequest) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DeleteAccountResponse(com.zimbra.soap.admin.message.DeleteAccountResponse) Provisioning(com.zimbra.cs.account.Provisioning)

Example 3 with DeleteAccountRequest

use of com.zimbra.soap.admin.message.DeleteAccountRequest in project zm-mailbox by Zimbra.

the class TestDomainAdmin method testModifyAccountInDiffDomain.

@Test
public void testModifyAccountInDiffDomain() throws Exception {
    String domAdminId = createAdminConsoleStyleDomainAdmin(DOMADMIN);
    Account acct = TestJaxbProvisioning.ensureAccountExists(DIFF_ACCT);
    String acctId = acct.getId();
    SoapProvisioning domAdminSoapProv = getSoapProvisioning(DOMADMIN, TestUtil.DEFAULT_PASSWORD);
    ModifyAccountRequest modAcctReq = new ModifyAccountRequest(acctId);
    modAcctReq.addAttr(new Attr(Provisioning.A_description, "dummy description"));
    try {
        domAdminSoapProv.invokeJaxb(modAcctReq);
    } catch (SoapFaultException sfe) {
        checkSoapReason(sfe, "permission denied: can not access account ");
    }
    try {
        domAdminSoapProv.invokeJaxbOnTargetAccount(modAcctReq, acctId);
    } catch (SoapFaultException sfe) {
        checkSoapReason(sfe, "permission denied: can not access account ");
    }
    DeleteAccountRequest delAcctReq = new DeleteAccountRequest(acctId);
    DeleteAccountResponse delAcctResp = adminSoapProv.invokeJaxbOnTargetAccount(delAcctReq, acctId);
    assertNotNull("DeleteAccountResponse for " + DIFF_ACCT + " as ADMIN specifying target acct", delAcctResp);
    try {
        domAdminSoapProv.invokeJaxb(modAcctReq);
        fail("ModifyAccountRequest succeeded after delete!");
    } catch (SoapFaultException sfe) {
        // Get this instead of "no such account: " because modify by ID (not name) and for domain admin
        // cannot know whether that ID was for a domain we administered or not.
        checkSoapReason(sfe, "permission denied: can not access account ");
    }
    try {
        domAdminSoapProv.invokeJaxbOnTargetAccount(modAcctReq, acctId);
        fail("ModifyAccountRequest succeeded after delete!");
    } catch (SoapFaultException sfe) {
        checkSoapReason(sfe, "permission denied: can not access account ");
    }
}
Also used : Account(com.zimbra.cs.account.Account) DeleteAccountRequest(com.zimbra.soap.admin.message.DeleteAccountRequest) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) ModifyAccountRequest(com.zimbra.soap.admin.message.ModifyAccountRequest) DeleteAccountResponse(com.zimbra.soap.admin.message.DeleteAccountResponse) Attr(com.zimbra.soap.admin.type.Attr) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 4 with DeleteAccountRequest

use of com.zimbra.soap.admin.message.DeleteAccountRequest in project zm-mailbox by Zimbra.

the class TestDomainAdmin method testModifyAccountInDomAdminDomain.

@Test
public void testModifyAccountInDomAdminDomain() throws Exception {
    Account acct = TestJaxbProvisioning.ensureAccountExists(TARGET_ACCT);
    String acctId = acct.getId();
    String domAdminId = createAdminConsoleStyleDomainAdmin(DOMADMIN);
    SoapProvisioning domAdminSoapProv = getSoapProvisioning(DOMADMIN, TestUtil.DEFAULT_PASSWORD);
    ModifyAccountRequest modAcctReq;
    ModifyAccountResponse modAcctResp;
    modAcctReq = new ModifyAccountRequest(null);
    modAcctReq.addAttr(new Attr(Provisioning.A_description, "dummy description"));
    try {
        modAcctResp = domAdminSoapProv.invokeJaxb(modAcctReq);
        fail("ModifyAccountRequest succeeded without 'id'!");
    } catch (SoapFaultException sfe) {
        checkSoapReason(sfe, "invalid request: missing required attribute: id");
    }
    modAcctReq = new ModifyAccountRequest(acctId);
    modAcctReq.addAttr(new Attr(Provisioning.A_description, "dummy description"));
    modAcctResp = domAdminSoapProv.invokeJaxb(modAcctReq);
    assertNotNull("ModifyAccountResponse for " + TARGET_ACCT + " simple as domAdmin", modAcctResp);
    modAcctReq = new ModifyAccountRequest(acctId);
    modAcctReq.addAttr(new Attr(Provisioning.A_description, "another dummy description"));
    modAcctResp = domAdminSoapProv.invokeJaxbOnTargetAccount(modAcctReq, acctId);
    assertNotNull("ModifyAccountResponse for " + TARGET_ACCT + " as domAdmin specifying target acct", modAcctResp);
    DeleteAccountRequest delAcctReq = new DeleteAccountRequest(acctId);
    DeleteAccountResponse delAcctResp = domAdminSoapProv.invokeJaxbOnTargetAccount(delAcctReq, acctId);
    assertNotNull("DeleteAccountResponse for " + TARGET_ACCT + " as domAdmin specifying target acct", delAcctResp);
    try {
        modAcctResp = domAdminSoapProv.invokeJaxb(modAcctReq);
        fail("ModifyAccountRequest succeeded after delete!");
    } catch (SoapFaultException sfe) {
        // Get this instead of "no such account: " because modify by ID (not name) and for domain admin
        // cannot know whether that ID was for a domain we administered or not.
        checkSoapReason(sfe, "permission denied: can not access account ");
    }
    try {
        modAcctResp = domAdminSoapProv.invokeJaxbOnTargetAccount(modAcctReq, acctId);
        fail("ModifyAccountRequest succeeded after delete!");
    } catch (SoapFaultException sfe) {
        checkSoapReason(sfe, "permission denied: can not access account ");
    }
    // as full admin
    try {
        modAcctResp = adminSoapProv.invokeJaxb(modAcctReq);
        fail("ModifyAccountRequest succeeded after delete!");
    } catch (SoapFaultException sfe) {
        // Full admin gets "no such account: " instead of "permission denied"
        checkSoapReason(sfe, "no such account: ");
    }
}
Also used : Account(com.zimbra.cs.account.Account) DeleteAccountRequest(com.zimbra.soap.admin.message.DeleteAccountRequest) ModifyAccountResponse(com.zimbra.soap.admin.message.ModifyAccountResponse) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) ModifyAccountRequest(com.zimbra.soap.admin.message.ModifyAccountRequest) DeleteAccountResponse(com.zimbra.soap.admin.message.DeleteAccountResponse) Attr(com.zimbra.soap.admin.type.Attr) SoapFaultException(com.zimbra.common.soap.SoapFaultException) Test(org.junit.Test)

Example 5 with DeleteAccountRequest

use of com.zimbra.soap.admin.message.DeleteAccountRequest 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 ");
    }
}
Also used : CreateAccountResponse(com.zimbra.soap.admin.message.CreateAccountResponse) DeleteAccountRequest(com.zimbra.soap.admin.message.DeleteAccountRequest) AddAccountAliasRequest(com.zimbra.soap.admin.message.AddAccountAliasRequest) RemoveAccountAliasRequest(com.zimbra.soap.admin.message.RemoveAccountAliasRequest) DeleteAccountResponse(com.zimbra.soap.admin.message.DeleteAccountResponse) RenameAccountRequest(com.zimbra.soap.admin.message.RenameAccountRequest) GetMailboxResponse(com.zimbra.soap.admin.message.GetMailboxResponse) MailboxByAccountIdSelector(com.zimbra.soap.admin.type.MailboxByAccountIdSelector) GetAccountRequest(com.zimbra.soap.admin.message.GetAccountRequest) SoapFaultException(com.zimbra.common.soap.SoapFaultException) GetAccountResponse(com.zimbra.soap.admin.message.GetAccountResponse) RemoveAccountAliasResponse(com.zimbra.soap.admin.message.RemoveAccountAliasResponse) CreateAccountRequest(com.zimbra.soap.admin.message.CreateAccountRequest) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) GetMailboxRequest(com.zimbra.soap.admin.message.GetMailboxRequest) RenameAccountResponse(com.zimbra.soap.admin.message.RenameAccountResponse) AddAccountAliasResponse(com.zimbra.soap.admin.message.AddAccountAliasResponse) Test(org.junit.Test)

Aggregations

DeleteAccountRequest (com.zimbra.soap.admin.message.DeleteAccountRequest)5 SoapFaultException (com.zimbra.common.soap.SoapFaultException)4 Account (com.zimbra.cs.account.Account)4 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)4 DeleteAccountResponse (com.zimbra.soap.admin.message.DeleteAccountResponse)4 Test (org.junit.Test)4 AddAccountAliasRequest (com.zimbra.soap.admin.message.AddAccountAliasRequest)2 AddAccountAliasResponse (com.zimbra.soap.admin.message.AddAccountAliasResponse)2 GetAccountRequest (com.zimbra.soap.admin.message.GetAccountRequest)2 GetMailboxRequest (com.zimbra.soap.admin.message.GetMailboxRequest)2 ModifyAccountRequest (com.zimbra.soap.admin.message.ModifyAccountRequest)2 RemoveAccountAliasRequest (com.zimbra.soap.admin.message.RemoveAccountAliasRequest)2 RenameAccountRequest (com.zimbra.soap.admin.message.RenameAccountRequest)2 Attr (com.zimbra.soap.admin.type.Attr)2 MailboxByAccountIdSelector (com.zimbra.soap.admin.type.MailboxByAccountIdSelector)2 Provisioning (com.zimbra.cs.account.Provisioning)1 Mailbox (com.zimbra.cs.mailbox.Mailbox)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 CreateAccountRequest (com.zimbra.soap.admin.message.CreateAccountRequest)1 CreateAccountResponse (com.zimbra.soap.admin.message.CreateAccountResponse)1