Search in sources :

Example 21 with ZAuthToken

use of com.zimbra.common.auth.ZAuthToken in project zm-mailbox by Zimbra.

the class ZimbraSoapContext method toProxyContext.

/**
     * Serializes this object for use in a proxied SOAP request.
     * <p>
     * The attributes encapsulated by the {@link ZimbraSoapContext} -- the response protocol, the auth token, etc. are
     * carried forward, except that if {@code excludeAccountDetails} is set, any account details are omitted.
     */
Element toProxyContext(SoapProtocol proto, boolean excludeAccountDetails) {
    Element ctxt = proto.getFactory().createElement(HeaderConstants.CONTEXT);
    ctxt.addAttribute(HeaderConstants.A_HOPCOUNT, mHopCount);
    String proxyAuthToken = null;
    if (mAuthToken != null) {
        proxyAuthToken = mAuthToken.getProxyAuthToken();
    }
    if (proxyAuthToken != null) {
        new ZAuthToken(proxyAuthToken).encodeSoapCtxt(ctxt);
    } else if (mRawAuthToken != null) {
        mRawAuthToken.encodeSoapCtxt(ctxt);
    }
    if (mResponseProtocol != mRequestProtocol) {
        ctxt.addNonUniqueElement(HeaderConstants.E_FORMAT).addAttribute(HeaderConstants.A_TYPE, mResponseProtocol == SoapProtocol.SoapJS ? HeaderConstants.TYPE_JAVASCRIPT : HeaderConstants.TYPE_XML);
    }
    if (!mSessionEnabled) {
        // be backwards-compatible for sanity-preservation purposes
        ctxt.addUniqueElement(HeaderConstants.E_NO_SESSION);
    } else if (mSessionInfo != null) {
        encodeSession(ctxt, mSessionInfo.sessionId, null).addAttribute(HeaderConstants.A_PROXIED, true);
    } else {
        ctxt.addUniqueElement(HeaderConstants.E_SESSION).addAttribute(HeaderConstants.A_PROXIED, true);
    }
    if (!excludeAccountDetails) {
        Element eAcct = ctxt.addNonUniqueElement(HeaderConstants.E_ACCOUNT).addAttribute(HeaderConstants.A_MOUNTPOINT, mMountpointTraversed);
        if (mRequestedAccountId != null && !mRequestedAccountId.equalsIgnoreCase(mAuthTokenAccountId)) {
            eAcct.addAttribute(HeaderConstants.A_BY, HeaderConstants.BY_ID).setText(mRequestedAccountId);
        }
    }
    if (mUnqualifiedItemIds) {
        ctxt.addUniqueElement(HeaderConstants.E_NO_QUALIFY);
    }
    Element ua = ctxt.addUniqueElement(HeaderConstants.E_USER_AGENT);
    ua.addAttribute(HeaderConstants.A_NAME, SoapTransport.DEFAULT_USER_AGENT_NAME);
    ua.addAttribute(HeaderConstants.A_VERSION, BuildInfo.VERSION);
    ctxt.addUniqueElement(HeaderConstants.E_VIA).setText(getNextVia());
    if (null != soapRequestId) {
        ctxt.addUniqueElement(HeaderConstants.E_SOAP_ID).setText(soapRequestId);
    }
    return ctxt;
}
Also used : Element(com.zimbra.common.soap.Element) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Example 22 with ZAuthToken

use of com.zimbra.common.auth.ZAuthToken in project zm-mailbox by Zimbra.

the class AbstractProxyProperty method getMountpoints.

protected ArrayList<Pair<Mountpoint, ZFolder>> getMountpoints(DavContext ctxt) {
    ArrayList<Pair<Mountpoint, ZFolder>> mps = new ArrayList<Pair<Mountpoint, ZFolder>>();
    try {
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        for (MailItem item : mbox.getItemList(ctxt.getOperationContext(), MailItem.Type.MOUNTPOINT)) {
            Mountpoint mp = (Mountpoint) item;
            // skip non-calendar mountpoints
            if (mp.getDefaultView() != MailItem.Type.APPOINTMENT && mp.getDefaultView() != MailItem.Type.TASK) {
                continue;
            }
            ZAuthToken zat = AuthProvider.getAuthToken(ctxt.getAuthAccount()).toZAuthToken();
            ZMailbox zmbx = RemoteCollection.getRemoteMailbox(zat, mp.getOwnerId());
            // skip dangling mountpoints
            if (zmbx == null) {
                continue;
            }
            try {
                ZFolder folder = zmbx.getFolderById(mp.getTarget().toString(account));
                // skip dangling mountpoints
                if (folder == null) {
                    continue;
                }
                mps.add(new Pair<Mountpoint, ZFolder>(mp, folder));
            } catch (ServiceException se) {
                ZimbraLog.dav.warn("can't get remote folder", se);
            }
        }
    } catch (ServiceException se) {
        ZimbraLog.dav.warn("can't get mailbox", se);
    }
    return mps;
}
Also used : MailItem(com.zimbra.cs.mailbox.MailItem) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ServiceException(com.zimbra.common.service.ServiceException) ArrayList(java.util.ArrayList) ZFolder(com.zimbra.client.ZFolder) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) ZAuthToken(com.zimbra.common.auth.ZAuthToken) Pair(com.zimbra.common.util.Pair)

Example 23 with ZAuthToken

use of com.zimbra.common.auth.ZAuthToken in project zm-mailbox by Zimbra.

the class CtagInfoCache method getFolder.

private CtagInfo getFolder(CalendarKey key) throws ServiceException {
    String accountId = key.getAccountId();
    int folderId = key.getFolderId();
    CtagInfo calInfo = null;
    Provisioning prov = Provisioning.getInstance();
    Account acct = prov.get(AccountBy.id, accountId);
    if (acct == null) {
        ZimbraLog.calendar.warn("Invalid account %s during cache lookup", accountId);
        return null;
    }
    if (Provisioning.onLocalServer(acct)) {
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
        Folder folder = mbox.getFolderById(null, folderId);
        if (folder != null)
            calInfo = new CtagInfo(folder);
        else
            ZimbraLog.calendar.warn("Invalid folder %d in account %s during cache lookup", folderId, accountId);
    } else {
        ZAuthToken zat = AuthProvider.getAdminAuthToken().toZAuthToken();
        ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(acct));
        zoptions.setNoSession(true);
        zoptions.setTargetAccount(acct.getId());
        zoptions.setTargetAccountBy(Key.AccountBy.id);
        ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
        ItemId iidFolder = new ItemId(accountId, folderId);
        ZFolder zfolder = zmbx.getFolderById(iidFolder.toString());
        if (zfolder != null)
            calInfo = new CtagInfo(zfolder);
        else
            ZimbraLog.calendar.warn("Invalid folder %d in account %s during cache lookup", folderId, accountId);
    }
    return calInfo;
}
Also used : Account(com.zimbra.cs.account.Account) ZFolder(com.zimbra.client.ZFolder) Folder(com.zimbra.cs.mailbox.Folder) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ItemId(com.zimbra.cs.service.util.ItemId) Provisioning(com.zimbra.cs.account.Provisioning) ZMailbox(com.zimbra.client.ZMailbox) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMailbox(com.zimbra.client.ZMailbox) ZFolder(com.zimbra.client.ZFolder)

Example 24 with ZAuthToken

use of com.zimbra.common.auth.ZAuthToken in project zm-mailbox by Zimbra.

the class TestSoap method testAuthRequest.

/**
     * Confirms that attrs and prefs are selected when specified in {@link ZMailbox} options.
     */
@Test
public void testAuthRequest() throws Exception {
    // Test password auth.
    ZMailbox.Options options = new ZMailbox.Options();
    options.setAccount(USER_NAME);
    options.setAccountBy(AccountBy.name);
    options.setPassword(TestUtil.DEFAULT_PASSWORD);
    options.setUri(TestUtil.getSoapUrl());
    ZMailbox mbox = runAuthTest(options);
    ZAuthToken authToken = mbox.getAuthToken();
    // Test auth token auth.
    options = new ZMailbox.Options();
    options.setAuthToken(authToken);
    options.setAuthAuthToken(true);
    options.setUri(TestUtil.getSoapUrl());
    runAuthTest(options);
}
Also used : ZMailbox(com.zimbra.client.ZMailbox) ZAuthToken(com.zimbra.common.auth.ZAuthToken) Test(org.junit.Test) SoapTest(com.zimbra.qa.unittest.prov.soap.SoapTest)

Example 25 with ZAuthToken

use of com.zimbra.common.auth.ZAuthToken in project zm-mailbox by Zimbra.

the class SoapProvisioning method soapAdminAuthenticate.

public void soapAdminAuthenticate(ZAuthToken zat) throws ServiceException {
    // TODO: Do we need 3rd party AuthToken support in JAXB before we can migrate to JAXB?
    if (mTransport == null)
        throw ZClientException.CLIENT_ERROR("must call setURI before calling adminAuthenticate", null);
    XMLElement req = new XMLElement(AdminConstants.AUTH_REQUEST);
    zat.encodeAuthReq(req, true);
    Element response = invoke(req);
    mAuthToken = new ZAuthToken(response.getElement(AdminConstants.E_AUTH_TOKEN), true);
    mAuthTokenLifetime = response.getAttributeLong(AdminConstants.E_LIFETIME);
    mAuthTokenExpiration = System.currentTimeMillis() + mAuthTokenLifetime;
    mTransport.setAuthToken(mAuthToken);
}
Also used : Element(com.zimbra.common.soap.Element) XMLElement(com.zimbra.common.soap.Element.XMLElement) XMLElement(com.zimbra.common.soap.Element.XMLElement) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Aggregations

ZAuthToken (com.zimbra.common.auth.ZAuthToken)36 ZMailbox (com.zimbra.client.ZMailbox)14 Element (com.zimbra.common.soap.Element)11 AuthToken (com.zimbra.cs.account.AuthToken)7 ZFolder (com.zimbra.client.ZFolder)6 ServiceException (com.zimbra.common.service.ServiceException)6 XMLElement (com.zimbra.common.soap.Element.XMLElement)6 Account (com.zimbra.cs.account.Account)6 IOException (java.io.IOException)6 HttpClient (org.apache.commons.httpclient.HttpClient)6 HttpState (org.apache.commons.httpclient.HttpState)6 Test (org.junit.Test)6 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)5 ItemId (com.zimbra.cs.service.util.ItemId)5 URI (java.net.URI)5 GetMethod (org.apache.commons.httpclient.methods.GetMethod)5 Folder (com.zimbra.cs.mailbox.Folder)3 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 Options (com.zimbra.client.ZMailbox.Options)2 ZMountpoint (com.zimbra.client.ZMountpoint)2