use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class ZimbraMailAdapter method isMountpoint.
private static boolean isMountpoint(Mailbox mbox, String folderPath) throws ServiceException {
Pair<Folder, String> pair = mbox.getFolderByPathLongestMatch(null, Mailbox.ID_FOLDER_USER_ROOT, folderPath);
Folder f = pair.getFirst();
return f != null && f instanceof Mountpoint;
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class InQuery method compile.
@Override
public QueryOperation compile(Mailbox mbox, boolean bool) {
if (specialTarget != null) {
if (specialTarget == In.NONE) {
return new NoResultsQueryOperation();
} else if (specialTarget == In.ANY) {
DBQueryOperation op = new DBQueryOperation();
op.addAnyFolder(evalBool(bool));
return op;
} else {
if (evalBool(bool)) {
if (specialTarget == In.REMOTE) {
DBQueryOperation dbop = new DBQueryOperation();
dbop.addIsRemoteClause();
return dbop;
} else {
assert (specialTarget == In.LOCAL);
DBQueryOperation dbop = new DBQueryOperation();
dbop.addIsLocalClause();
return dbop;
}
} else {
if (specialTarget == In.REMOTE) {
DBQueryOperation dbop = new DBQueryOperation();
dbop.addIsLocalClause();
return dbop;
} else {
assert (specialTarget == In.LOCAL);
DBQueryOperation dbop = new DBQueryOperation();
dbop.addIsRemoteClause();
return dbop;
}
}
}
}
DBQueryOperation dbOp = new DBQueryOperation();
if (folder != null) {
if (includeSubfolders) {
List<Folder> subFolders = folder.getSubfolderHierarchy();
if (evalBool(bool)) {
// (A or B or C)
UnionQueryOperation union = new UnionQueryOperation();
for (Folder sub : subFolders) {
DBQueryOperation dbop = new DBQueryOperation();
union.add(dbop);
if (sub instanceof Mountpoint) {
Mountpoint mpt = (Mountpoint) sub;
if (!mpt.isLocal()) {
dbop.addInRemoteFolder(mpt.getTarget(), "", includeSubfolders, evalBool(bool));
} else {
// TODO FIXME handle local mountpoints. Don't forget to check for infinite recursion!
}
} else {
dbop.addInFolder(sub, evalBool(bool));
}
}
return union;
} else {
// -(A or B or C) ==> -A and -B and -C
IntersectionQueryOperation iop = new IntersectionQueryOperation();
for (Folder f : subFolders) {
DBQueryOperation dbop = new DBQueryOperation();
iop.addQueryOp(dbop);
if (f instanceof Mountpoint) {
Mountpoint mpt = (Mountpoint) f;
if (!mpt.isLocal()) {
dbop.addInRemoteFolder(mpt.getTarget(), "", includeSubfolders, evalBool(bool));
} else {
// TODO FIXME handle local mountpoints. Don't forget to check for infinite recursion!
}
} else {
dbop.addInFolder(f, evalBool(bool));
}
}
return iop;
}
} else {
dbOp.addInFolder(folder, evalBool(bool));
}
} else if (remoteId != null) {
dbOp.addInRemoteFolder(remoteId, subfolderPath, includeSubfolders, evalBool(bool));
} else {
assert (false);
}
return dbOp;
}
use of com.zimbra.cs.mailbox.Mountpoint 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(AccountConstants.P_ACCOUNT_ID);
String folderId = (String) tokenMap.get(AccountConstants.P_FOLDER_ID);
String extUserEmail = (String) tokenMap.get(AccountConstants.P_EMAIL);
String addressVerification = (String) tokenMap.get(AccountConstants.P_ADDRESS_VERIFICATION);
if ("1".equals(addressVerification)) {
Boolean expired = false;
if (tokenMap.get(EXPIRED) != null) {
expired = (Boolean) tokenMap.get(EXPIRED);
}
Map<String, String> attributes = handleAddressVerification(req, resp, ownerId, extUserEmail, expired);
redirectRequest(req, resp, attributes, EXT_USER_PROV_ON_UI_NODE, PUBLIC_ADDRESS_VERIFICATION_JSP);
} else {
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));
Map<String, String> attrs = new HashMap<String, String>();
attrs.put("extuseremail", extUserEmail);
reqHeaders.put("ZM_PRELIM_AUTH_TOKEN", param);
redirectRequest(req, resp, attrs, reqHeaders, EXT_USER_PROV_ON_UI_NODE, PUBLIC_EXTUSERPROV_JSP);
}
} 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 {
Map<String, String> attrs = new HashMap<String, String>();
attrs.put("virtualacctdomain", domain.getName());
redirectRequest(req, resp, attrs, PUBLIC_LOGIN_ON_UI_NODE, PUBLIC_LOGIN_JSP);
}
}
} catch (ServiceException e) {
Map<String, String> errorAttrs = new HashMap<String, String>();
errorAttrs.put(ERROR_CODE, e.getCode());
errorAttrs.put(ERROR_MESSAGE, e.getMessage());
redirectRequest(req, resp, errorAttrs, EXT_USER_PROV_ON_UI_NODE, PUBLIC_EXTUSERPROV_JSP);
} catch (Exception e) {
Map<String, String> errorAttrs = new HashMap<String, String>();
errorAttrs.put(ERROR_CODE, ServiceException.FAILURE);
errorAttrs.put(ERROR_MESSAGE, e.getMessage());
redirectRequest(req, resp, errorAttrs, EXT_USER_PROV_ON_UI_NODE, PUBLIC_EXTUSERPROV_JSP);
}
}
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class ExternalUserProvServlet method provisionVirtualAccountAndRedirect.
private static void provisionVirtualAccountAndRedirect(HttpServletRequest req, HttpServletResponse resp, String displayName, String password, String grantorId, String extUserEmail) throws ServiceException {
Provisioning prov = Provisioning.getInstance();
try {
Account owner = prov.getAccountById(grantorId);
Domain domain = prov.getDomain(owner);
Account grantee = prov.getAccountByName(mapExtEmailToAcctName(extUserEmail, domain));
if (grantee != null) {
throw AccountServiceException.ACCOUNT_EXISTS(extUserEmail);
}
// search all shares accessible to the external user
SearchAccountsOptions searchOpts = new SearchAccountsOptions(domain, new String[] { Provisioning.A_zimbraId, Provisioning.A_displayName, Provisioning.A_zimbraSharedItem });
// get all groups extUserEmail belongs to
GuestAccount guestAcct = new GuestAccount(extUserEmail, null);
List<String> groupIds = prov.getGroupMembership(guestAcct, false).groupIds();
List<String> grantees = Lists.newArrayList(extUserEmail);
grantees.addAll(groupIds);
searchOpts.setFilter(ZLdapFilterFactory.getInstance().accountsByGrants(grantees, false, false));
List<NamedEntry> accounts = prov.searchDirectory(searchOpts);
if (accounts.isEmpty()) {
throw AccountServiceException.NO_SHARE_EXISTS();
}
// create external account
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraIsExternalVirtualAccount, ProvisioningConstants.TRUE);
attrs.put(Provisioning.A_zimbraExternalUserMailAddress, extUserEmail);
attrs.put(Provisioning.A_zimbraMailHost, prov.getLocalServer().getServiceHostname());
if (!StringUtil.isNullOrEmpty(displayName)) {
attrs.put(Provisioning.A_displayName, displayName);
}
attrs.put(Provisioning.A_zimbraHideInGal, ProvisioningConstants.TRUE);
attrs.put(Provisioning.A_zimbraMailStatus, Provisioning.MailStatus.disabled.toString());
if (!StringUtil.isNullOrEmpty(password)) {
attrs.put(Provisioning.A_zimbraVirtualAccountInitialPasswordSet, ProvisioningConstants.TRUE);
}
// create external account mailbox
Mailbox granteeMbox;
try {
grantee = prov.createAccount(mapExtEmailToAcctName(extUserEmail, domain), password, attrs);
granteeMbox = MailboxManager.getInstance().getMailboxByAccount(grantee);
} catch (ServiceException e) {
// the next attempt
if (grantee != null) {
prov.deleteAccount(grantee.getId());
}
throw e;
}
// create mountpoints
Set<MailItem.Type> viewTypes = new HashSet<MailItem.Type>();
for (NamedEntry ne : accounts) {
Account account = (Account) ne;
String[] sharedItems = account.getSharedItem();
for (String sharedItem : sharedItems) {
ShareInfoData shareData = AclPushSerializer.deserialize(sharedItem);
if (!granteeMatchesShare(shareData, grantee)) {
continue;
}
String sharedFolderPath = shareData.getPath();
String mountpointName = getMountpointName(account, grantee, sharedFolderPath);
MailItem.Type viewType = shareData.getFolderDefaultViewCode();
Mountpoint mtpt = granteeMbox.createMountpoint(null, getMptParentFolderId(viewType, prov), mountpointName, account.getId(), shareData.getItemId(), shareData.getItemUuid(), viewType, 0, MailItem.DEFAULT_COLOR, false);
if (viewType == MailItem.Type.APPOINTMENT) {
// make sure that the mountpoint is checked in the UI by default
granteeMbox.alterTag(null, mtpt.getId(), mtpt.getType(), Flag.FlagInfo.CHECKED, true, null);
}
viewTypes.add(viewType);
}
}
enableAppFeatures(grantee, viewTypes);
setCookieAndRedirect(req, resp, grantee);
} catch (ServiceException e) {
ZimbraLog.account.debug("Exception while creating virtual account for %s", extUserEmail, e);
throw e;
} catch (Exception e) {
ZimbraLog.account.debug("Exception while creating virtual account for %s", extUserEmail, e);
throw ServiceException.TEMPORARILY_UNAVAILABLE();
}
}
use of com.zimbra.cs.mailbox.Mountpoint in project zm-mailbox by Zimbra.
the class UserServlet method proxyIfMountpoint.
protected boolean proxyIfMountpoint(HttpServletRequest req, HttpServletResponse resp, UserServletContext context, MailItem item) throws IOException, ServiceException, UserServletException {
if (!(item instanceof Mountpoint))
return false;
if (context.format != null && context.format.equals("html"))
return false;
Mountpoint mpt = (Mountpoint) item;
String uri = SERVLET_PATH + "/~/?" + QP_ID + '=' + HttpUtil.urlEscape(mpt.getOwnerId()) + "%3A" + mpt.getRemoteId();
if (context.format != null)
uri += '&' + QP_FMT + '=' + HttpUtil.urlEscape(context.format.toString());
if (context.extraPath != null)
uri += '&' + QP_NAME + '=' + HttpUtil.urlEscape(context.extraPath);
for (Map.Entry<String, String> entry : HttpUtil.getURIParams(req).entrySet()) {
String qp = entry.getKey();
if (!qp.equals(QP_ID) && !qp.equals(QP_FMT))
uri += '&' + HttpUtil.urlEscape(qp) + '=' + HttpUtil.urlEscape(entry.getValue());
}
Provisioning prov = Provisioning.getInstance();
Account targetAccount = prov.get(AccountBy.id, mpt.getOwnerId());
if (targetAccount == null)
throw new UserServletException(HttpServletResponse.SC_BAD_REQUEST, L10nUtil.getMessage(MsgKey.errNoSuchAccount, req));
try {
proxyServletRequest(req, resp, prov.getServer(targetAccount), uri, getProxyAuthToken(context));
} catch (HttpException e) {
throw new IOException("Unknown error", e);
}
return true;
}
Aggregations