Search in sources :

Example 51 with SoapProvisioning

use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.

the class TestServiceServlet method before.

@BeforeClass
public static void before() throws Exception {
    cleanup();
    TestUtil.createAccount(USER_NAME);
    baseURL = TestUtil.getBaseUrl() + "/fromservice/";
    prov = Provisioning.getInstance();
    localServer = prov.getLocalServer();
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_zimbraIsDelegatedAdminAccount, "TRUE");
    attrs.put(Provisioning.A_zimbraAdminConsoleUIComponents, "accountListView");
    attrs.put(Provisioning.A_zimbraAdminConsoleUIComponents, "downloadsView");
    attrs.put(Provisioning.A_zimbraAdminConsoleUIComponents, "DLListView");
    delegatedAdminWithoutRights = TestUtil.createAccount(TestUtil.addDomainIfNecessary(DELEGATED_ADMIN_WITHOUT_RIGHTS), attrs);
    attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_zimbraIsDelegatedAdminAccount, "TRUE");
    attrs.put(Provisioning.A_zimbraAdminConsoleUIComponents, "accountListView");
    attrs.put(Provisioning.A_zimbraAdminConsoleUIComponents, "downloadsView");
    attrs.put(Provisioning.A_zimbraAdminConsoleUIComponents, "DLListView");
    delegatedAdminWithRights = TestUtil.createAccount(TestUtil.addDomainIfNecessary(DELEGATED_ADMIN_WITH_RIGHTS), attrs);
    SoapProvisioning adminSoapProv = TestUtil.newSoapProvisioning();
    TestUtil.grantRightToAdmin(adminSoapProv, com.zimbra.soap.type.TargetType.fromString(com.zimbra.cs.account.accesscontrol.TargetType.server.toString()), localServer.getName(), delegatedAdminWithRights.getName(), Admin.R_deployZimlet.getName());
    TestUtil.grantRightToAdmin(adminSoapProv, com.zimbra.soap.type.TargetType.fromString(com.zimbra.cs.account.accesscontrol.TargetType.server.toString()), localServer.getName(), delegatedAdminWithRights.getName(), Admin.R_flushCache.getName());
    GetMethod method = new GetMethod(String.format("%sflushacl", baseURL));
    addAuthTokenHeader(method, AuthProvider.getAdminAuthToken().getEncoded());
    HttpClient client = new HttpClient();
    int code = HttpClientUtil.executeMethod(client, method);
    if (HttpStatus.SC_OK != code) {
        Assert.fail(String.format("Failed to flush all cache in /zimbra web app. Response code: %d", code));
    }
}
Also used : SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) BeforeClass(org.junit.BeforeClass)

Example 52 with SoapProvisioning

use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.

the class TestSoapProvisioning method isExpired.

@Test
public void isExpired() throws Exception {
    // 5 seconds
    long lifeTimeSecs = 5;
    String acctName = TestUtil.getAddress("isExpired", domain.getName());
    String password = "test123";
    Map<String, Object> attrs = Maps.newHashMap();
    attrs.put(Provisioning.A_zimbraIsAdminAccount, ProvisioningConstants.TRUE);
    attrs.put(Provisioning.A_zimbraAdminAuthTokenLifetime, String.valueOf(lifeTimeSecs) + "s");
    Account acct = provUtil.createAccount(acctName, password, attrs);
    SoapProvisioning soapProv = new SoapProvisioning();
    Server server = prov.getLocalServer();
    soapProv.soapSetURI(URLUtil.getAdminURL(server));
    assertTrue(soapProv.isExpired());
    soapProv.soapAdminAuthenticate(acctName, password);
    assertFalse(soapProv.isExpired());
    System.out.println("Waiting for " + lifeTimeSecs + " seconds");
    Thread.sleep((lifeTimeSecs + 1) * 1000);
    assertTrue(soapProv.isExpired());
    prov.deleteAccount(acct.getId());
}
Also used : Account(com.zimbra.cs.account.Account) Server(com.zimbra.cs.account.Server) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning)

Example 53 with SoapProvisioning

use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.

the class LocalConfigCLI method reload.

private void reload() throws ServiceException {
    String host = LC.zimbra_zmprov_default_soap_server.value();
    int port = LC.zimbra_admin_service_port.intValue();
    SoapHttpTransport transport = new SoapHttpTransport("https://" + host + ":" + port + AdminConstants.ADMIN_SERVICE_URI);
    SoapProvisioning prov = new SoapProvisioning();
    prov.soapSetURI(transport.getURI());
    prov.soapZimbraAdminAuthenticate();
    transport.setAuthToken(prov.getAuthToken());
    try {
        transport.invoke(JaxbUtil.jaxbToElement(new ReloadLocalConfigRequest()));
    } catch (IOException e) {
        throw ZClientException.IO_ERROR(e.getMessage(), e);
    }
}
Also used : SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) ReloadLocalConfigRequest(com.zimbra.soap.admin.message.ReloadLocalConfigRequest) SoapHttpTransport(com.zimbra.common.soap.SoapHttpTransport) IOException(java.io.IOException)

Example 54 with SoapProvisioning

use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.

the class ModifyAccount method checkNewServer.

/*
     * if the account's home server is changed as a result of this command and the new server is no longer this server,
     * need to send a flush cache command to the new server so we don't get into the following:
     *
     * account is on server A (this server)
     *
     * on server B: zmprov ma {account} zimbraMailHost B (the ma is proxied to server A; and on server B, the account
     * still appears to be on A)
     *
     * zmprov ma {account} {any attr} {value} ERROR: service.TOO_MANY_HOPS Until the account is expired from cache on
     * server B.
     */
private void checkNewServer(ZimbraSoapContext zsc, Map<String, Object> context, Account acct, Server newServer) {
    try {
        if (!Provisioning.onLocalServer(acct)) {
            // in the case when zimbraMailHost is being removed, newServer will be null
            if (newServer != null) {
                SoapProvisioning soapProv = new SoapProvisioning();
                String adminUrl = URLUtil.getAdminURL(newServer, AdminConstants.ADMIN_SERVICE_URI, true);
                soapProv.soapSetURI(adminUrl);
                soapProv.soapZimbraAdminAuthenticate();
                soapProv.flushCache(CacheEntryType.account, new CacheEntry[] { new CacheEntry(CacheEntryBy.id, acct.getId()) });
            }
        }
    } catch (ServiceException e) {
        // ignore any error and continue
        ZimbraLog.mailbox.warn("cannot flush account cache on server " + (newServer == null ? "" : newServer.getName()) + " for " + acct.getName(), e);
    }
}
Also used : AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) CacheEntry(com.zimbra.cs.account.Provisioning.CacheEntry)

Example 55 with SoapProvisioning

use of com.zimbra.cs.account.soap.SoapProvisioning in project zm-mailbox by Zimbra.

the class TestJaxbProvisioning method ensureMailboxExists.

public static Account ensureMailboxExists(String name) throws ServiceException {
    SoapProvisioning prov = TestUtil.newSoapProvisioning();
    Account acct = ensureAccountExists(name);
    if (acct == null) {
        ZimbraLog.test.debug("ensureMailboxExists returning null!!!");
    } else {
        // The act of getting a mailbox is sufficient to create it if the associated account exists.
        // Note that prov.getAccount() USED TO implicitly created a mailbox even though it was not really
        // supposed to and this routine used to rely on that.
        MailboxInfo mboxInfo = prov.getMailbox(acct);
        ZimbraLog.test.debug("ensureMailboxExists Returning Mailbox=%s Account=%s Id=%s", mboxInfo.getMailboxId(), acct.getName(), acct.getId());
    }
    return acct;
}
Also used : Account(com.zimbra.cs.account.Account) SoapProvisioning(com.zimbra.cs.account.soap.SoapProvisioning) MailboxInfo(com.zimbra.cs.account.soap.SoapProvisioning.MailboxInfo)

Aggregations

SoapProvisioning (com.zimbra.cs.account.soap.SoapProvisioning)78 Test (org.junit.Test)18 SoapFaultException (com.zimbra.common.soap.SoapFaultException)14 Account (com.zimbra.cs.account.Account)13 Attr (com.zimbra.soap.admin.type.Attr)10 ServiceException (com.zimbra.common.service.ServiceException)9 CreateDistributionListRequest (com.zimbra.soap.admin.message.CreateDistributionListRequest)6 CreateDistributionListResponse (com.zimbra.soap.admin.message.CreateDistributionListResponse)6 AccountLogger (com.zimbra.common.util.AccountLogger)5 Server (com.zimbra.cs.account.Server)5 CreateCalendarResourceRequest (com.zimbra.soap.admin.message.CreateCalendarResourceRequest)4 CreateCalendarResourceResponse (com.zimbra.soap.admin.message.CreateCalendarResourceResponse)4 DeleteCalendarResourceRequest (com.zimbra.soap.admin.message.DeleteCalendarResourceRequest)4 List (java.util.List)4 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)3 AccountServiceException (com.zimbra.cs.account.AccountServiceException)3 Provisioning (com.zimbra.cs.account.Provisioning)3 CacheEntry (com.zimbra.cs.account.Provisioning.CacheEntry)3 DeleteAccountRequest (com.zimbra.soap.admin.message.DeleteAccountRequest)3 DeleteAccountResponse (com.zimbra.soap.admin.message.DeleteAccountResponse)3