Search in sources :

Example 6 with ZAuthToken

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

the class LmcAdminAuthRequest method parseResponseXML.

protected LmcSoapResponse parseResponseXML(Element responseXML) throws ServiceException {
    // get the auth token out, no default, must be present or a service exception is thrown
    String authToken = DomUtil.getString(responseXML, AdminConstants.E_AUTH_TOKEN);
    ZAuthToken zat = new ZAuthToken(null, authToken, null);
    // get the session id, if not present, default to null
    String sessionId = DomUtil.getString(responseXML, HeaderConstants.E_SESSION, null);
    LmcAdminAuthResponse responseObj = new LmcAdminAuthResponse();
    LmcSession sess = new LmcSession(zat, sessionId);
    responseObj.setSession(sess);
    return responseObj;
}
Also used : ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Example 7 with ZAuthToken

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

the class LmcAuthRequest method parseResponseXML.

protected LmcSoapResponse parseResponseXML(Element responseXML) throws ServiceException {
    // get the auth token out, no default, must be present or a service exception is thrown
    String authToken = DomUtil.getString(responseXML, AccountConstants.E_AUTH_TOKEN);
    ZAuthToken zat = new ZAuthToken(null, authToken, null);
    // get the session id, if not present, default to null
    String sessionId = DomUtil.getString(responseXML, HeaderConstants.E_SESSION, null);
    LmcAuthResponse responseObj = new LmcAuthResponse();
    LmcSession sess = new LmcSession(zat, sessionId);
    responseObj.setSession(sess);
    return responseObj;
}
Also used : ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Example 8 with ZAuthToken

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

the class SoapCLI method auth.

/**
     * Authenticates using the provided ZAuthToken
     * @throws IOException
     * @throws com.zimbra.common.soap.SoapFaultException
     * @throws ServiceException
     */
protected LmcSession auth(ZAuthToken zAuthToken) throws SoapFaultException, IOException, ServiceException {
    if (zAuthToken == null)
        return auth();
    URL url = new URL("https", mHost, mPort, AdminConstants.ADMIN_SERVICE_URI);
    mServerUrl = url.toExternalForm();
    SoapTransport trans = getTransport();
    mAuth = false;
    Element authReq = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
    zAuthToken.encodeAuthReq(authReq, true);
    try {
        Element authResp = trans.invokeWithoutSession(authReq);
        ZAuthToken zat = new ZAuthToken(authResp.getElement(AdminConstants.E_AUTH_TOKEN), true);
        trans.setAuthToken(zat);
        mAuth = true;
        return new LmcSession(zat, null);
    } catch (UnknownHostException e) {
        // UnknownHostException's error message is not clear; rethrow with a more descriptive message
        throw new IOException("Unknown host: " + mHost);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) Element(com.zimbra.common.soap.Element) LmcSession(com.zimbra.cs.client.LmcSession) IOException(java.io.IOException) ZAuthToken(com.zimbra.common.auth.ZAuthToken) URL(java.net.URL) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 9 with ZAuthToken

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

the class SoapCLI method auth.

/**
     * Authenticates using the username and password from the local config.
     * @throws IOException
     * @throws com.zimbra.common.soap.SoapFaultException
     * @throws ServiceException
     */
protected LmcSession auth() throws SoapFaultException, IOException, ServiceException {
    URL url = new URL("https", mHost, mPort, AdminConstants.ADMIN_SERVICE_URI);
    mServerUrl = url.toExternalForm();
    SoapTransport trans = getTransport();
    mAuth = false;
    Element authReq = new Element.XMLElement(AdminConstants.AUTH_REQUEST);
    authReq.addAttribute(AdminConstants.E_NAME, mUser, Element.Disposition.CONTENT);
    authReq.addAttribute(AdminConstants.E_PASSWORD, mPassword, Element.Disposition.CONTENT);
    try {
        Element authResp = trans.invokeWithoutSession(authReq);
        String authToken = authResp.getAttribute(AdminConstants.E_AUTH_TOKEN);
        ZAuthToken zat = new ZAuthToken(null, authToken, null);
        trans.setAuthToken(authToken);
        mAuth = true;
        return new LmcSession(zat, null);
    } catch (UnknownHostException e) {
        // UnknownHostException's error message is not clear; rethrow with a more descriptive message
        throw new IOException("Unknown host: " + mHost);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) Element(com.zimbra.common.soap.Element) LmcSession(com.zimbra.cs.client.LmcSession) IOException(java.io.IOException) ZAuthToken(com.zimbra.common.auth.ZAuthToken) URL(java.net.URL) SoapTransport(com.zimbra.common.soap.SoapTransport)

Example 10 with ZAuthToken

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

the class Mailbox method refreshMountpoint.

/**
     * Updates the remote owner and item id stored in the mountpoint to match the current location of the
     * target folder.  The target folder is identified by the remote UUID stored in the mountpoint's metadata.
     * @param octxt
     * @param mountpointId item id of the Mountpoint
     * @return
     * @throws ServiceException
     */
public Mountpoint refreshMountpoint(OperationContext octxt, int mountpointId) throws ServiceException {
    Mountpoint mp = getMountpointById(octxt, mountpointId);
    Provisioning prov = Provisioning.getInstance();
    ShareLocator shloc = prov.getShareLocatorById(mp.getRemoteUuid());
    if (shloc == null || mp.getOwnerId().equalsIgnoreCase(shloc.getShareOwnerAccountId())) {
        // Share apparently did not move.
        return mp;
    }
    // Look up remote folder by UUID to discover the new numeric id.
    Account shareOwner = Provisioning.getInstance().get(Key.AccountBy.id, shloc.getShareOwnerAccountId());
    AuthToken at = AuthToken.getCsrfUnsecuredAuthToken(octxt.getAuthToken());
    String pxyAuthToken = Provisioning.onLocalServer(shareOwner) ? null : at.getProxyAuthToken();
    ZAuthToken zat = null;
    if (pxyAuthToken == null) {
        zat = at.toZAuthToken();
        zat.resetProxyAuthToken();
    } else {
        zat = new ZAuthToken(pxyAuthToken);
    }
    ZMailbox.Options zoptions = new ZMailbox.Options(zat, AccountUtil.getSoapUri(shareOwner));
    zoptions.setNoSession(true);
    zoptions.setTargetAccount(shareOwner.getId());
    zoptions.setTargetAccountBy(Key.AccountBy.id);
    ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
    ZFolder zfolder = zmbx.getFolderByUuid(shloc.getUuid());
    if (zfolder != null) {
        ItemId fid = new ItemId(zfolder.getId(), shareOwner.getId());
        return refreshMountpoint(octxt, mountpointId, shareOwner.getId(), fid.getId());
    } else {
        return null;
    }
}
Also used : Account(com.zimbra.cs.account.Account) ParsedMessageOptions(com.zimbra.cs.mime.ParsedMessageOptions) Options(com.zimbra.client.ZMailbox.Options) ZMailbox(com.zimbra.client.ZMailbox) Options(com.zimbra.client.ZMailbox.Options) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ZFolder(com.zimbra.client.ZFolder) RefreshMountpoint(com.zimbra.cs.redolog.op.RefreshMountpoint) CreateMountpoint(com.zimbra.cs.redolog.op.CreateMountpoint) ZAuthToken(com.zimbra.common.auth.ZAuthToken) ItemId(com.zimbra.cs.service.util.ItemId) Provisioning(com.zimbra.cs.account.Provisioning) ShareLocator(com.zimbra.cs.account.ShareLocator)

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