Search in sources :

Example 36 with AuthToken

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) {
            }
        }
    }
}
Also used : Account(com.zimbra.cs.account.Account) ZGetMiniCalResult(com.zimbra.client.ZMailbox.ZGetMiniCalResult) ItemId(com.zimbra.cs.service.util.ItemId) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) ZMiniCalError(com.zimbra.client.ZMailbox.ZMiniCalError) ZMailbox(com.zimbra.client.ZMailbox) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) AuthToken(com.zimbra.cs.account.AuthToken)

Example 37 with AuthToken

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;
    }
}
Also used : ParsedMessageOptions(com.zimbra.cs.mime.ParsedMessageOptions) Options(com.zimbra.client.ZMailbox.Options) ZMailbox(com.zimbra.client.ZMailbox) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ServiceException(com.zimbra.common.service.ServiceException) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Example 38 with AuthToken

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;
}
Also used : Account(com.zimbra.cs.account.Account) AuthToken(com.zimbra.cs.account.AuthToken) ZAuthToken(com.zimbra.common.auth.ZAuthToken)

Example 39 with 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;
    }
}
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)

Example 40 with AuthToken

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());
}
Also used : AuthToken(com.zimbra.cs.account.AuthToken)

Aggregations

AuthToken (com.zimbra.cs.account.AuthToken)98 ServiceException (com.zimbra.common.service.ServiceException)46 Account (com.zimbra.cs.account.Account)44 ZimbraAuthToken (com.zimbra.cs.account.ZimbraAuthToken)27 AuthTokenException (com.zimbra.cs.account.AuthTokenException)26 Element (com.zimbra.common.soap.Element)24 Provisioning (com.zimbra.cs.account.Provisioning)23 ZMailbox (com.zimbra.client.ZMailbox)19 ZAuthToken (com.zimbra.common.auth.ZAuthToken)18 IOException (java.io.IOException)14 Server (com.zimbra.cs.account.Server)12 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)12 HttpClient (org.apache.commons.httpclient.HttpClient)12 HashMap (java.util.HashMap)11 GetMethod (org.apache.commons.httpclient.methods.GetMethod)11 Test (org.junit.Test)11 SoapHttpTransport (com.zimbra.common.soap.SoapHttpTransport)10 ServletException (javax.servlet.ServletException)10 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)8 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)8