Search in sources :

Example 1 with GranteeChooser

use of com.zimbra.soap.type.GranteeChooser in project zm-mailbox by Zimbra.

the class TestJaxbProvisioning method accountGetShareInfo.

public GetShareInfoResponse accountGetShareInfo(Account acct, AccountSelector owner, Boolean includeSelf, ShareSet shareSet) {
    GetShareInfoResponse resp = null;
    GranteeChooser grantee = null;
    try {
        resp = prov.invokeJaxbOnTargetAccount(GetShareInfoRequest.create(owner, grantee, includeSelf), acct.getId());
        Assert.assertNotNull(String.format("GetShareInfoRequest for account %s", acct.getName()), resp);
        checkGetShareInfo(shareSet, resp.getShares());
    } catch (ServiceException e) {
        Assert.fail("Unexpected exception while creating mountpoint " + e);
    }
    return resp;
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) GetShareInfoResponse(com.zimbra.soap.account.message.GetShareInfoResponse) GranteeChooser(com.zimbra.soap.type.GranteeChooser)

Example 2 with GranteeChooser

use of com.zimbra.soap.type.GranteeChooser in project zm-mailbox by Zimbra.

the class TestJaxbProvisioning method accountGetShareInfoExpectFail.

public void accountGetShareInfoExpectFail(Account acct, AccountSelector owner, Boolean includeSelf, String reason) {
    GranteeChooser grantee = null;
    try {
        prov.invokeJaxbOnTargetAccount(GetShareInfoRequest.create(owner, grantee, includeSelf), acct.getId());
        Assert.fail("Unexpected success for GetShareInfoRequest");
    } catch (ServiceException e) {
        Assert.assertTrue(String.format("Unexpected exception %s (expected msg '%s')", e.getMessage(), reason), e.getMessage().contains(reason));
    }
}
Also used : ServiceException(com.zimbra.common.service.ServiceException) GranteeChooser(com.zimbra.soap.type.GranteeChooser)

Example 3 with GranteeChooser

use of com.zimbra.soap.type.GranteeChooser in project zm-mailbox by Zimbra.

the class GetShareInfo method doGetShareInfo.

/**
     * @param zsc
     * @param targetAcct
     * @param request
     * @param response
     */
private void doGetShareInfo(ZimbraSoapContext zsc, Map<String, Object> context, Account targetAcct, Element request, GetShareInfoResponse response) throws ServiceException {
    Provisioning prov = Provisioning.getInstance();
    GetShareInfoRequest req = JaxbUtil.elementToJaxb(request);
    GranteeChooser granteeChooser = req.getGrantee();
    byte granteeType = getGranteeType(granteeChooser);
    String granteeId = granteeChooser == null ? null : granteeChooser.getId();
    String granteeName = granteeChooser == null ? null : granteeChooser.getName();
    Account owner = null;
    AccountSelector ownerSelector = req.getOwner();
    if (ownerSelector != null) {
        owner = prov.get(ownerSelector);
        // when an invalid user name/id is used.
        if ((owner == null) || (owner.isAccountExternal())) {
            return;
        } else {
            AccountStatus status = owner.getAccountStatus();
            if (status != null && status.isClosed()) {
                return;
            }
        }
    }
    OperationContext octxt = getOperationContext(zsc, context);
    ShareInfo.MountedFolders mountedFolders = null;
    if (!Boolean.TRUE.equals(req.getInternal())) {
        // this (new ShareInfo.MountedFolders) should be executed on the requested
        // account's home server.
        // If we get here, we should be proxied to the right server naturally by the framework.
        mountedFolders = new ShareInfo.MountedFolders(octxt, targetAcct);
    }
    ResultFilter resultFilter;
    if (Boolean.FALSE.equals(req.getIncludeSelf())) {
        resultFilter = new ResultFilterByTargetExcludeSelf(granteeId, granteeName, targetAcct);
    } else {
        resultFilter = new ResultFilterByTarget(granteeId, granteeName);
    }
    String filterDomain = null;
    if (LC.PUBLIC_SHARE_VISIBILITY.samePrimaryDomain.equals(LC.getPublicShareAdvertisingScope())) {
        filterDomain = targetAcct.getDomainName();
    }
    ResultFilter resultFilter2 = new ResultFilterForPublicShares(filterDomain);
    ShareInfoVisitor visitor = new ShareInfoVisitor(prov, response, mountedFolders, resultFilter, resultFilter2);
    if (owner == null) {
        // retrieve from published share info
        ShareInfo.Published.get(prov, targetAcct, granteeType, owner, visitor);
    } else {
        if (targetAcct.getId().equals(owner.getId()))
            throw ServiceException.INVALID_REQUEST("cannot discover shares on self", null);
        if (Provisioning.onLocalServer(owner))
            ShareInfo.Discover.discover(octxt, prov, targetAcct, granteeType, owner, visitor);
        else {
            // issue an GetShareInfoRequest to the home server of the owner, and tell it *not*
            // to proxy to the requesting account's mailbox server.
            fetchRemoteShareInfo(context, request, owner.getId(), visitor);
        }
    }
    visitor.finish();
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) GranteeChooser(com.zimbra.soap.type.GranteeChooser) AccountSelector(com.zimbra.soap.type.AccountSelector) ShareInfo(com.zimbra.cs.account.ShareInfo) Provisioning(com.zimbra.cs.account.Provisioning) AccountStatus(com.zimbra.common.account.ZAttrProvisioning.AccountStatus) GetShareInfoRequest(com.zimbra.soap.account.message.GetShareInfoRequest) PublishedShareInfoVisitor(com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor)

Example 4 with GranteeChooser

use of com.zimbra.soap.type.GranteeChooser in project zm-mailbox by Zimbra.

the class GetShareInfo method handle.

@Override
public Element handle(Element request, Map<String, Object> context) throws ServiceException {
    ZimbraSoapContext zsc = getZimbraSoapContext(context);
    OperationContext octxt = getOperationContext(zsc, context);
    Provisioning prov = Provisioning.getInstance();
    GetShareInfoRequest req = JaxbUtil.elementToJaxb(request);
    GranteeChooser granteeChooser = req.getGrantee();
    byte granteeType = com.zimbra.cs.service.account.GetShareInfo.getGranteeType(granteeChooser == null ? null : granteeChooser.getType());
    String granteeId = null;
    String granteeName = null;
    if (granteeChooser != null) {
        granteeId = granteeChooser.getId();
        granteeName = granteeChooser.getName();
    }
    Account ownerAcct = null;
    AccountBy acctBy = req.getOwner().getBy().toKeyAccountBy();
    String accountSelectorKey = req.getOwner().getKey();
    ownerAcct = prov.get(acctBy, accountSelectorKey);
    // in the account namespace GetShareInfo
    // to defend against harvest attacks return "no shares" instead of error when an invalid user name/id is used.
    // this is the admin namespace GetShareInfo, we want to let the admin know if the owner name is bad
    // unless the admin is a domain admin for a different domain...
    defendAgainstAccountOrCalendarResourceHarvesting(ownerAcct, acctBy, accountSelectorKey, zsc, Admin.R_adminLoginAs, Admin.R_adminLoginCalendarResourceAs);
    GetShareInfoResponse response = new GetShareInfoResponse();
    ResultFilter resultFilter = new ResultFilterByTarget(granteeId, granteeName);
    ShareInfoVisitor visitor = new ShareInfoVisitor(prov, response, null, resultFilter);
    ShareInfo.Discover.discover(octxt, prov, null, granteeType, ownerAcct, visitor);
    visitor.finish();
    return zsc.jaxbToElement(response);
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) ResultFilterByTarget(com.zimbra.cs.service.account.GetShareInfo.ResultFilterByTarget) GranteeChooser(com.zimbra.soap.type.GranteeChooser) GetShareInfoResponse(com.zimbra.soap.admin.message.GetShareInfoResponse) Provisioning(com.zimbra.cs.account.Provisioning) AccountBy(com.zimbra.common.account.Key.AccountBy) ResultFilter(com.zimbra.cs.service.account.GetShareInfo.ResultFilter) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) GetShareInfoRequest(com.zimbra.soap.admin.message.GetShareInfoRequest) ShareInfoVisitor(com.zimbra.cs.service.account.GetShareInfo.ShareInfoVisitor)

Aggregations

GranteeChooser (com.zimbra.soap.type.GranteeChooser)4 ServiceException (com.zimbra.common.service.ServiceException)2 Account (com.zimbra.cs.account.Account)2 Provisioning (com.zimbra.cs.account.Provisioning)2 OperationContext (com.zimbra.cs.mailbox.OperationContext)2 AccountBy (com.zimbra.common.account.Key.AccountBy)1 AccountStatus (com.zimbra.common.account.ZAttrProvisioning.AccountStatus)1 PublishedShareInfoVisitor (com.zimbra.cs.account.Provisioning.PublishedShareInfoVisitor)1 ShareInfo (com.zimbra.cs.account.ShareInfo)1 ResultFilter (com.zimbra.cs.service.account.GetShareInfo.ResultFilter)1 ResultFilterByTarget (com.zimbra.cs.service.account.GetShareInfo.ResultFilterByTarget)1 ShareInfoVisitor (com.zimbra.cs.service.account.GetShareInfo.ShareInfoVisitor)1 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)1 GetShareInfoRequest (com.zimbra.soap.account.message.GetShareInfoRequest)1 GetShareInfoResponse (com.zimbra.soap.account.message.GetShareInfoResponse)1 GetShareInfoRequest (com.zimbra.soap.admin.message.GetShareInfoRequest)1 GetShareInfoResponse (com.zimbra.soap.admin.message.GetShareInfoResponse)1 AccountSelector (com.zimbra.soap.type.AccountSelector)1