use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class GetMiniCal method doRemoteFolders.
private static void doRemoteFolders(ZimbraSoapContext zsc, String remoteAccountId, List<String> remoteFolders, long rangeStart, long rangeEnd, Set<String> busyDates, Element response, Map<ItemId, ItemId> reverseIidMap, ItemIdFormatter ifmt) {
try {
Account target = Provisioning.getInstance().get(Key.AccountBy.id, remoteAccountId);
if (target == null)
throw AccountServiceException.NO_SUCH_ACCOUNT(remoteAccountId);
AuthToken authToken = AuthToken.getCsrfUnsecuredAuthToken(zsc.getAuthToken());
ZMailbox.Options zoptions = new ZMailbox.Options(authToken.toZAuthToken(), AccountUtil.getSoapUri(target));
zoptions.setTargetAccount(remoteAccountId);
zoptions.setTargetAccountBy(AccountBy.id);
zoptions.setNoSession(true);
ZMailbox zmbx = ZMailbox.getMailbox(zoptions);
String[] remoteIds = new String[remoteFolders.size()];
for (int i = 0; i < remoteIds.length; i++) remoteIds[i] = remoteFolders.get(i).toString();
ZGetMiniCalResult result = zmbx.getMiniCal(rangeStart, rangeEnd, remoteIds);
Set<String> dates = result.getDates();
if (dates != null) {
for (String datestamp : dates) {
busyDates.add(datestamp);
}
}
List<ZMiniCalError> errors = result.getErrors();
if (errors != null) {
for (ZMiniCalError error : errors) {
try {
ItemId iid = new ItemId(error.getFolderId(), zsc);
// Error must mention folder id requested by client.
ItemId reqIid = reverseIidMap.get(iid);
String fid = ifmt.formatItemId(reqIid != null ? reqIid : iid);
addError(response, fid, error.getErrCode(), error.getErrMsg());
} catch (ServiceException e) {
}
}
}
} catch (ServiceException e) {
ZimbraLog.calendar.warn("Error making remote GetMiniCalRequest", e);
// Mark all remote folders with the same error.
for (String remoteFid : remoteFolders) {
try {
ItemId iid = new ItemId(remoteFid, zsc);
// Error must mention folder id requested by client.
ItemId reqIid = reverseIidMap.get(iid);
String fid = ifmt.formatItemId(reqIid != null ? reqIid : iid);
addError(response, fid, e.getCode(), e.getMessage());
} catch (ServiceException e2) {
}
}
}
}
use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class Mailbox method getRemoteCalItemByUID.
public com.zimbra.soap.mail.type.CalendarItemInfo getRemoteCalItemByUID(Account ownerAccount, String uid, boolean includeInvites, boolean includeContent) throws ServiceException {
Options options = new Options();
AuthToken authToken = AuthToken.getCsrfUnsecuredAuthToken(getAuthToken(getOperationContext()));
options.setAuthToken(authToken.toZAuthToken());
options.setTargetAccount(getAccount().getName());
options.setTargetAccountBy(AccountBy.name);
options.setUri(AccountUtil.getSoapUri(ownerAccount));
options.setNoSession(true);
ZMailbox zmbox = ZMailbox.getMailbox(options);
try {
return zmbox.getRemoteCalItemByUID(ownerAccount.getId(), uid, includeInvites, includeContent);
} catch (ServiceException e) {
String exceptionCode = e.getCode();
if (exceptionCode.equals(AccountServiceException.NO_SUCH_ACCOUNT) || exceptionCode.equals(MailServiceException.NO_SUCH_CALITEM)) {
ZimbraLog.calendar.debug("Either remote acct or calendar item not found [%s]", exceptionCode);
} else {
ZimbraLog.calendar.debug("Unexpected exception thrown when getting remote calendar item - ignoring", e);
}
return null;
}
}
use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class Mailbox method getAuthToken.
private AuthToken getAuthToken(OperationContext octxt) throws ServiceException {
AuthToken authToken = octxt == null ? null : octxt.getAuthToken();
if (authToken == null) {
Account authuser = octxt == null ? getAccount() : octxt.getAuthenticatedUser();
boolean isAdminRequest = octxt == null ? false : octxt.isUsingAdminPrivileges();
authToken = AuthProvider.getAuthToken(authuser, isAdminRequest);
}
return authToken;
}
use of com.zimbra.cs.account.AuthToken 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;
}
}
use of com.zimbra.cs.account.AuthToken in project zm-mailbox by Zimbra.
the class AuthProvider method getAuthToken.
public static AuthToken getAuthToken(Account acct, long expires) throws AuthProviderException {
List<AuthProvider> providers = getProviders();
AuthProviderException authProviderExp = null;
for (AuthProvider ap : providers) {
try {
AuthToken at = ap.authToken(acct, expires);
if (at == null) {
authProviderExp = AuthProviderException.FAILURE("auth provider " + ap.getName() + " returned null");
} else {
return at;
}
} catch (AuthProviderException e) {
if (e.canIgnore()) {
logger().debug(ap.getName() + ":" + e.getMessage());
} else {
authProviderExp = e;
}
}
}
if (null != authProviderExp) {
throw authProviderExp;
}
throw AuthProviderException.FAILURE("cannot get authtoken from account " + acct.getName());
}
Aggregations