Search in sources :

Example 1 with RemoveAccountAliasResponse

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

the class RemoveAccountAlias method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    Provisioning prov = Provisioning.getInstance();
    RemoveAccountAliasRequest req = JaxbUtil.elementToJaxb(request);
    String id = req.getId();
    String alias = req.getAlias();
    Account account = null;
    if (id != null) {
        account = prov.get(AccountBy.id, id, zsc.getAuthToken());
    }
    try {
        defendAgainstAccountOrCalendarResourceHarvesting(account, AccountBy.id, id, zsc, Admin.R_removeAccountAlias, Admin.R_removeCalendarResourceAlias);
    } catch (AccountServiceException ase) {
    // still may want to remove the alias, even if it doesn't point at anything
    // note: if we got a permission denied instead of AccountServiceException,
    //       means we don't have the rights so shouldn't get any further
    }
    String acctName = "";
    if (account != null) {
        acctName = account.getName();
    }
    // if the admin can remove an alias in the domain
    checkDomainRightByEmail(zsc, alias, Admin.R_deleteAlias);
    // If account is null, still invoke removeAlias. Ensures dangling aliases are cleaned up as much as possible
    prov.removeAlias(account, alias);
    ZimbraLog.security.info(ZimbraLog.encodeAttrs(new String[] { "cmd", "RemoveAccountAlias", "name", acctName, "alias", alias }));
    return zsc.jaxbToElement(new RemoveAccountAliasResponse());
}
Also used : RemoveAccountAliasResponse(com.zimbra.soap.admin.message.RemoveAccountAliasResponse) Account(com.zimbra.cs.account.Account) AccountServiceException(com.zimbra.cs.account.AccountServiceException) RemoveAccountAliasRequest(com.zimbra.soap.admin.message.RemoveAccountAliasRequest) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) Provisioning(com.zimbra.cs.account.Provisioning)

Example 2 with RemoveAccountAliasResponse

use of com.zimbra.soap.admin.message.RemoveAccountAliasResponse 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

RemoveAccountAliasRequest (com.zimbra.soap.admin.message.RemoveAccountAliasRequest)2 RemoveAccountAliasResponse (com.zimbra.soap.admin.message.RemoveAccountAliasResponse)2 SoapFaultException (com.zimbra.common.soap.SoapFaultException)1 Account (com.zimbra.cs.account.Account)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 Provisioning (com.zimbra.cs.account.Provisioning)1 SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 AddAccountAliasRequest (com.zimbra.soap.admin.message.AddAccountAliasRequest)1 AddAccountAliasResponse (com.zimbra.soap.admin.message.AddAccountAliasResponse)1 CreateAccountRequest (com.zimbra.soap.admin.message.CreateAccountRequest)1 CreateAccountResponse (com.zimbra.soap.admin.message.CreateAccountResponse)1 DeleteAccountRequest (com.zimbra.soap.admin.message.DeleteAccountRequest)1 DeleteAccountResponse (com.zimbra.soap.admin.message.DeleteAccountResponse)1 GetAccountRequest (com.zimbra.soap.admin.message.GetAccountRequest)1 GetAccountResponse (com.zimbra.soap.admin.message.GetAccountResponse)1 GetMailboxRequest (com.zimbra.soap.admin.message.GetMailboxRequest)1 GetMailboxResponse (com.zimbra.soap.admin.message.GetMailboxResponse)1 RenameAccountRequest (com.zimbra.soap.admin.message.RenameAccountRequest)1 RenameAccountResponse (com.zimbra.soap.admin.message.RenameAccountResponse)1