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;
}
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;
}
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;
}
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);
}
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);
}
Aggregations