Search in sources :

Example 1 with FolderActionRequest

use of com.zimbra.soap.mail.message.FolderActionRequest in project zm-mailbox by Zimbra.

the class TestPurge method testFolderRetentionPolicy.

/**
     * Tests the SOAP API for setting retention policy on a folder.
     */
@Test
public void testFolderRetentionPolicy() throws Exception {
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    ZFolder folder = TestUtil.createFolder(mbox, "/" + NAME_PREFIX + "-testFolderRetentionPolicy");
    // Set user keep policy for folder.
    FolderActionSelector action = new FolderActionSelector(folder.getId(), "retentionpolicy");
    RetentionPolicy rp = new RetentionPolicy(Arrays.asList(Policy.newUserPolicy("30d")), null);
    action.setRetentionPolicy(rp);
    FolderActionRequest req = new FolderActionRequest(action);
    FolderActionResponse res = mbox.invokeJaxb(req);
    Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
    Assert.assertEquals(folder.getId(), res.getAction().getId());
    // Make sure that the retention policy is now set.
    folder = mbox.getFolderById(folder.getId());
    rp = folder.getRetentionPolicy();
    Assert.assertEquals(1, rp.getKeepPolicy().size());
    Assert.assertEquals(0, rp.getPurgePolicy().size());
    Policy p = rp.getKeepPolicy().get(0);
    Assert.assertEquals(Policy.Type.USER, p.getType());
    Assert.assertEquals("30d", p.getLifetime());
    // Turn off keep policy and set purge policy.
    action = new FolderActionSelector(folder.getId(), "retentionpolicy");
    rp = new RetentionPolicy(null, Arrays.asList(Policy.newUserPolicy("45d")));
    action.setRetentionPolicy(rp);
    req = new FolderActionRequest(action);
    res = mbox.invokeJaxb(req);
    Assert.assertEquals("retentionpolicy", res.getAction().getOperation());
    Assert.assertEquals(folder.getId(), res.getAction().getId());
    // Make sure that the retention policy is now set.
    folder = mbox.getFolderById(folder.getId());
    rp = folder.getRetentionPolicy();
    Assert.assertEquals(0, rp.getKeepPolicy().size());
    Assert.assertEquals(1, rp.getPurgePolicy().size());
    p = rp.getPurgePolicy().get(0);
    Assert.assertEquals(Policy.Type.USER, p.getType());
    Assert.assertEquals("45d", p.getLifetime());
    // Start a new session and make sure that the retention policy is still returned.
    mbox = TestUtil.getZMailbox(USER_NAME);
    folder = mbox.getFolderById(folder.getId());
    Assert.assertTrue(folder.getRetentionPolicy().isSet());
}
Also used : Policy(com.zimbra.soap.mail.type.Policy) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ZMailbox(com.zimbra.client.ZMailbox) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse) ZFolder(com.zimbra.client.ZFolder) RetentionPolicy(com.zimbra.soap.mail.type.RetentionPolicy) Test(org.junit.Test)

Example 2 with FolderActionRequest

use of com.zimbra.soap.mail.message.FolderActionRequest in project zm-mailbox by Zimbra.

the class TestJaxbProvisioning method grantAccess.

public void grantAccess(Account acct, String id, String granteeType, String granteeName, String perm) {
    FolderActionSelector selector = new FolderActionSelector(id, "grant");
    ActionGrantSelector grant = new ActionGrantSelector(perm, granteeType);
    grant.setDisplayName(granteeName);
    selector.setGrant(grant);
    FolderActionRequest req = new FolderActionRequest(selector);
    try {
        FolderActionResponse resp = prov.invokeJaxbOnTargetAccount(req, acct.getId());
        Assert.assertNotNull(String.format("FolderActionResponse for account %s", acct.getName()), resp);
    } catch (ServiceException e) {
        Assert.fail("Unexpected exception while granting access " + e);
    }
}
Also used : ActionGrantSelector(com.zimbra.soap.mail.type.ActionGrantSelector) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ServiceException(com.zimbra.common.service.ServiceException) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse)

Example 3 with FolderActionRequest

use of com.zimbra.soap.mail.message.FolderActionRequest in project zm-mailbox by Zimbra.

the class ExternalUserProvServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String param = req.getParameter("p");
    if (param == null) {
        throw new ServletException("request missing param");
    }
    Map<Object, Object> tokenMap = validatePrelimToken(param);
    Map<String, String> reqHeaders = new HashMap<String, String>();
    String ownerId = (String) tokenMap.get("aid");
    String folderId = (String) tokenMap.get("fid");
    String extUserEmail = (String) tokenMap.get("email");
    Provisioning prov = Provisioning.getInstance();
    Account grantee;
    try {
        Account owner = prov.getAccountById(ownerId);
        Domain domain = prov.getDomain(owner);
        grantee = prov.getAccountByName(mapExtEmailToAcctName(extUserEmail, domain));
        if (grantee == null) {
            // external virtual account not created yet
            if (prov.isOctopus() && DebugConfig.skipVirtualAccountRegistrationPage) {
                // provision using 'null' password and display name
                // UI will ask the user to set these post provisioning
                provisionVirtualAccountAndRedirect(req, resp, null, null, ownerId, extUserEmail);
            } else {
                resp.addCookie(new Cookie("ZM_PRELIM_AUTH_TOKEN", param));
                req.setAttribute("extuseremail", extUserEmail);
                if (WebClientServiceUtil.isServerInSplitMode()) {
                    reqHeaders.put("extuseremail", extUserEmail);
                    reqHeaders.put("ZM_PRELIM_AUTH_TOKEN", param);
                    String htmlresp = WebClientServiceUtil.sendServiceRequestToOneRandomUiNode(EXT_USER_PROV_ON_UI_NODE, reqHeaders);
                    resp.getWriter().print(htmlresp);
                } else {
                    ServletContext context = getServletContext().getContext("/zimbra");
                    if (context != null) {
                        RequestDispatcher dispatcher = context.getRequestDispatcher(PUBLIC_EXTUSERPROV_JSP);
                        dispatcher.forward(req, resp);
                    } else {
                        logger.warn("Could not access servlet context url /zimbra");
                        throw ServiceException.TEMPORARILY_UNAVAILABLE();
                    }
                }
            }
        } else {
            // create a new mountpoint in the external user's mailbox if not already created
            String[] sharedItems = owner.getSharedItem();
            int sharedFolderId = Integer.valueOf(folderId);
            String sharedFolderPath = null;
            MailItem.Type sharedFolderView = null;
            for (String sharedItem : sharedItems) {
                ShareInfoData sid = AclPushSerializer.deserialize(sharedItem);
                if (sid.getItemId() == sharedFolderId && extUserEmail.equalsIgnoreCase(sid.getGranteeId())) {
                    sharedFolderPath = sid.getPath();
                    sharedFolderView = sid.getFolderDefaultViewCode();
                    break;
                }
            }
            if (sharedFolderPath == null) {
                throw new ServletException("share not found");
            }
            String mountpointName = getMountpointName(owner, grantee, sharedFolderPath);
            ZMailbox.Options options = new ZMailbox.Options();
            options.setNoSession(true);
            options.setAuthToken(AuthProvider.getAuthToken(grantee).toZAuthToken());
            options.setUri(AccountUtil.getSoapUri(grantee));
            ZMailbox zMailbox = new ZMailbox(options);
            ZMountpoint zMtpt = null;
            try {
                zMtpt = zMailbox.createMountpoint(String.valueOf(getMptParentFolderId(sharedFolderView, prov)), mountpointName, ZFolder.View.fromString(sharedFolderView.toString()), ZFolder.Color.DEFAULTCOLOR, null, ZMailbox.OwnerBy.BY_ID, ownerId, ZMailbox.SharedItemBy.BY_ID, folderId, false);
            } catch (ServiceException e) {
                logger.debug("Error in attempting to create mountpoint. Probably it already exists.", e);
            }
            if (zMtpt != null) {
                if (sharedFolderView == MailItem.Type.APPOINTMENT) {
                    // make sure that the mountpoint is checked in the UI by default
                    FolderActionSelector actionSelector = new FolderActionSelector(zMtpt.getId(), "check");
                    FolderActionRequest actionRequest = new FolderActionRequest(actionSelector);
                    try {
                        zMailbox.invokeJaxb(actionRequest);
                    } catch (ServiceException e) {
                        logger.warn("Error in invoking check action on calendar mountpoint", e);
                    }
                }
                HashSet<MailItem.Type> types = new HashSet<MailItem.Type>();
                types.add(sharedFolderView);
                enableAppFeatures(grantee, types);
            }
            // check if the external user is already logged-in
            String zAuthTokenCookie = null;
            javax.servlet.http.Cookie[] cookies = req.getCookies();
            if (cookies != null) {
                for (Cookie cookie : cookies) {
                    if (cookie.getName().equals("ZM_AUTH_TOKEN")) {
                        zAuthTokenCookie = cookie.getValue();
                        break;
                    }
                }
            }
            AuthToken zAuthToken = null;
            if (zAuthTokenCookie != null) {
                try {
                    zAuthToken = AuthProvider.getAuthToken(zAuthTokenCookie);
                } catch (AuthTokenException ignored) {
                // auth token is not valid
                }
            }
            if (zAuthToken != null && !zAuthToken.isExpired() && zAuthToken.isRegistered() && grantee.getId().equals(zAuthToken.getAccountId())) {
                // external virtual account already logged-in
                resp.sendRedirect("/");
            } else if (prov.isOctopus() && !grantee.isVirtualAccountInitialPasswordSet() && DebugConfig.skipVirtualAccountRegistrationPage) {
                // seems like the virtual user did not set his password during his last visit, after an account was
                // provisioned for him
                setCookieAndRedirect(req, resp, grantee);
            } else {
                req.setAttribute("virtualacctdomain", domain.getName());
                if (WebClientServiceUtil.isServerInSplitMode()) {
                    reqHeaders.put("virtualacctdomain", domain.getName());
                    String htmlresp = WebClientServiceUtil.sendServiceRequestToOneRandomUiNode(PUBLIC_LOGIN_ON_UI_NODE, reqHeaders);
                    resp.getWriter().print(htmlresp);
                } else {
                    RequestDispatcher dispatcher = getServletContext().getContext("/zimbra").getRequestDispatcher(PUBLIC_LOGIN_JSP);
                    dispatcher.forward(req, resp);
                }
            }
        }
    } catch (ServiceException e) {
        throw new ServletException(e);
    }
}
Also used : ZMountpoint(com.zimbra.client.ZMountpoint) GuestAccount(com.zimbra.cs.account.GuestAccount) Account(com.zimbra.cs.account.Account) SearchAccountsOptions(com.zimbra.cs.account.SearchAccountsOptions) HashMap(java.util.HashMap) Provisioning(com.zimbra.cs.account.Provisioning) ServletException(javax.servlet.ServletException) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ZMailbox(com.zimbra.client.ZMailbox) ServletContext(javax.servlet.ServletContext) HashSet(java.util.HashSet) Cookie(javax.servlet.http.Cookie) ShareInfoData(com.zimbra.cs.account.ShareInfoData) RequestDispatcher(javax.servlet.RequestDispatcher) ZMountpoint(com.zimbra.client.ZMountpoint) Mountpoint(com.zimbra.cs.mailbox.Mountpoint) MailItem(com.zimbra.cs.mailbox.MailItem) ServiceException(com.zimbra.common.service.ServiceException) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) AuthTokenException(com.zimbra.cs.account.AuthTokenException) AuthToken(com.zimbra.cs.account.AuthToken) Domain(com.zimbra.cs.account.Domain)

Example 4 with FolderActionRequest

use of com.zimbra.soap.mail.message.FolderActionRequest in project zm-mailbox by Zimbra.

the class TestShareNotifications method testMultipleCalendarShareNotifications.

public void testMultipleCalendarShareNotifications() throws Exception {
    Account senderAccount = TestUtil.createAccount(SENDER_NAME);
    Account recipientAccount = TestUtil.createAccount(RECIPIENT_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(SENDER_NAME);
    // check that there are no share notifications in the recipient's mailbox
    ZMailbox recipientMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    List<ShareNotificationInfo> shares = waitForShareNotifications(recipientMbox, 0, 100);
    assertEquals("Recipient should have exactly 0 share notification", 0, shares.size());
    // create and share the first calendar
    ZFolder newCal = TestUtil.createFolder(mbox, CAL_NAME1, ZFolder.View.appointment);
    String calendarId = newCal.getId();
    FolderActionSelector action = new FolderActionSelector(calendarId, "grant");
    ActionGrantSelector grant = new ActionGrantSelector("r", "usr");
    grant.setDisplayName(recipientAccount.getName());
    grant.setPassword("");
    action.setGrant(grant);
    FolderActionRequest folderActionReq = new FolderActionRequest(action);
    FolderActionResponse folderActionResp = mbox.invokeJaxb(folderActionReq);
    assertNotNull("FolderActionResponse is null", folderActionResp);
    SendShareNotificationRequest shareNotificationReq = new SendShareNotificationRequest();
    shareNotificationReq.setItem(new com.zimbra.soap.type.Id(calendarId));
    shareNotificationReq.addEmailAddress(new EmailAddrInfo(recipientAccount.getMail()));
    SendShareNotificationResponse resp = mbox.invokeJaxb(shareNotificationReq);
    assertNotNull("ShareNotificationResponse is null", resp);
    // create and share the second calendar
    ZFolder newCal2 = TestUtil.createFolder(mbox, CAL_NAME2, ZFolder.View.appointment);
    String calendarId2 = newCal2.getId();
    action = new FolderActionSelector(calendarId2, "grant");
    grant = new ActionGrantSelector("r", "usr");
    grant.setDisplayName(recipientAccount.getName());
    grant.setPassword("");
    action.setGrant(grant);
    folderActionReq = new FolderActionRequest(action);
    folderActionResp = mbox.invokeJaxb(folderActionReq);
    assertNotNull("FolderActionResponse is null", folderActionResp);
    shareNotificationReq = new SendShareNotificationRequest();
    shareNotificationReq.setItem(new com.zimbra.soap.type.Id(calendarId2));
    shareNotificationReq.addEmailAddress(new EmailAddrInfo(recipientAccount.getMail()));
    resp = mbox.invokeJaxb(shareNotificationReq);
    assertNotNull("ShareNotificationResponse is null", resp);
    shares = waitForShareNotifications(recipientMbox, 2, 1000);
    assertEquals("should have exactly two share notification", 2, shares.size());
    assertNotNull("share grantor is null", shares.get(0).getGrantor());
    assertTrue("share grantor is not " + senderAccount.getMail(), senderAccount.getMail().equalsIgnoreCase(shares.get(0).getGrantor().getEmail()));
}
Also used : Account(com.zimbra.cs.account.Account) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse) SendShareNotificationResponse(com.zimbra.soap.mail.message.SendShareNotificationResponse) ActionGrantSelector(com.zimbra.soap.mail.type.ActionGrantSelector) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ZMailbox(com.zimbra.client.ZMailbox) ShareNotificationInfo(com.zimbra.soap.mail.type.ShareNotificationInfo) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) ZFolder(com.zimbra.client.ZFolder) SendShareNotificationRequest(com.zimbra.soap.mail.message.SendShareNotificationRequest)

Example 5 with FolderActionRequest

use of com.zimbra.soap.mail.message.FolderActionRequest in project zm-mailbox by Zimbra.

the class TestShareNotifications method testCalendarShareNotification.

public void testCalendarShareNotification() throws Exception {
    Account senderAccount = TestUtil.createAccount(SENDER_NAME);
    Account recipientAccount = TestUtil.createAccount(RECIPIENT_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(SENDER_NAME);
    // check that there are no share notifications in the recipient's mailbox
    ZMailbox recipientMbox = TestUtil.getZMailbox(RECIPIENT_NAME);
    List<ShareNotificationInfo> shares = waitForShareNotifications(recipientMbox, 0, 100);
    assertEquals("Recipient should have exactly 0 share notification", 0, shares.size());
    ZFolder newCal = TestUtil.createFolder(mbox, CAL_NAME1, ZFolder.View.appointment);
    String calendarId = newCal.getId();
    FolderActionSelector action = new FolderActionSelector(calendarId, "grant");
    ActionGrantSelector grant = new ActionGrantSelector("r", "usr");
    grant.setDisplayName(recipientAccount.getName());
    grant.setPassword("");
    action.setGrant(grant);
    FolderActionRequest folderActionReq = new FolderActionRequest(action);
    FolderActionResponse folderActionResp = mbox.invokeJaxb(folderActionReq);
    assertNotNull("FolderActionResponse is null", folderActionResp);
    SendShareNotificationRequest shareNotificationReq = new SendShareNotificationRequest();
    shareNotificationReq.setItem(new com.zimbra.soap.type.Id(calendarId));
    shareNotificationReq.addEmailAddress(new EmailAddrInfo(recipientAccount.getMail()));
    SendShareNotificationResponse resp = mbox.invokeJaxb(shareNotificationReq);
    assertNotNull("ShareNotificationResponse is null", resp);
    shares = waitForShareNotifications(recipientMbox, 1, 1000);
    assertTrue("should have exactly one share notification", shares.size() == 1);
    assertNotNull("share grantor is null", shares.get(0).getGrantor());
    assertTrue("share grantor is not " + senderAccount.getMail(), senderAccount.getMail().equalsIgnoreCase(shares.get(0).getGrantor().getEmail()));
}
Also used : Account(com.zimbra.cs.account.Account) FolderActionResponse(com.zimbra.soap.mail.message.FolderActionResponse) SendShareNotificationResponse(com.zimbra.soap.mail.message.SendShareNotificationResponse) ActionGrantSelector(com.zimbra.soap.mail.type.ActionGrantSelector) FolderActionSelector(com.zimbra.soap.mail.type.FolderActionSelector) ZMailbox(com.zimbra.client.ZMailbox) ShareNotificationInfo(com.zimbra.soap.mail.type.ShareNotificationInfo) FolderActionRequest(com.zimbra.soap.mail.message.FolderActionRequest) EmailAddrInfo(com.zimbra.soap.mail.type.EmailAddrInfo) ZFolder(com.zimbra.client.ZFolder) SendShareNotificationRequest(com.zimbra.soap.mail.message.SendShareNotificationRequest)

Aggregations

FolderActionRequest (com.zimbra.soap.mail.message.FolderActionRequest)8 FolderActionSelector (com.zimbra.soap.mail.type.FolderActionSelector)8 ZMailbox (com.zimbra.client.ZMailbox)7 FolderActionResponse (com.zimbra.soap.mail.message.FolderActionResponse)7 Account (com.zimbra.cs.account.Account)6 ActionGrantSelector (com.zimbra.soap.mail.type.ActionGrantSelector)6 ZFolder (com.zimbra.client.ZFolder)5 SendShareNotificationRequest (com.zimbra.soap.mail.message.SendShareNotificationRequest)4 SendShareNotificationResponse (com.zimbra.soap.mail.message.SendShareNotificationResponse)4 EmailAddrInfo (com.zimbra.soap.mail.type.EmailAddrInfo)4 ShareNotificationInfo (com.zimbra.soap.mail.type.ShareNotificationInfo)4 ServiceException (com.zimbra.common.service.ServiceException)2 ZMessage (com.zimbra.client.ZMessage)1 ZMountpoint (com.zimbra.client.ZMountpoint)1 AuthToken (com.zimbra.cs.account.AuthToken)1 AuthTokenException (com.zimbra.cs.account.AuthTokenException)1 Domain (com.zimbra.cs.account.Domain)1 GuestAccount (com.zimbra.cs.account.GuestAccount)1 Provisioning (com.zimbra.cs.account.Provisioning)1 SearchAccountsOptions (com.zimbra.cs.account.SearchAccountsOptions)1