use of com.zimbra.cs.account.ShareLocator in project zm-mailbox by Zimbra.
the class LdapProvisioning method getShareLocatorById.
private ShareLocator getShareLocatorById(String id, ZLdapContext zlc, boolean nocache) throws ServiceException {
if (id == null)
return null;
ShareLocator shloc = null;
if (!nocache)
shloc = shareLocatorCache.getById(id);
if (shloc == null) {
shloc = getShareLocatorByQuery(filterFactory.shareLocatorById(id), zlc);
shareLocatorCache.put(shloc);
}
return shloc;
}
use of com.zimbra.cs.account.ShareLocator in project zm-mailbox by Zimbra.
the class LdapProvisioning method createShareLocator.
@Override
public ShareLocator createShareLocator(String id, Map<String, Object> attrs) throws ServiceException {
CallbackContext callbackContext = new CallbackContext(CallbackContext.Op.CREATE);
AttributeManager.getInstance().preModify(attrs, null, callbackContext, true);
ZLdapContext zlc = null;
try {
zlc = LdapClient.getContext(LdapServerType.MASTER, LdapUsage.CREATE_SHARELOCATOR);
ZMutableEntry entry = LdapClient.createMutableEntry();
entry.mapToAttrs(attrs);
Set<String> ocs = LdapObjectClass.getShareLocatorObjectClasses(this);
entry.addAttr(A_objectClass, ocs);
entry.setAttr(A_cn, id);
String dn = mDIT.shareLocatorIdToDN(id);
entry.setDN(dn);
zlc.createEntry(entry);
ShareLocator shloc = getShareLocatorById(id, zlc, true);
AttributeManager.getInstance().postModify(attrs, shloc, callbackContext);
return shloc;
} catch (LdapEntryAlreadyExistException nabe) {
throw AccountServiceException.SHARE_LOCATOR_EXISTS(id);
} catch (LdapException e) {
throw e;
} catch (AccountServiceException e) {
throw e;
} catch (ServiceException e) {
throw ServiceException.FAILURE("unable to create share locator: " + id, e);
} finally {
LdapClient.closeContext(zlc);
}
}
use of com.zimbra.cs.account.ShareLocator 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.ShareLocator in project zm-mailbox by Zimbra.
the class ShareStartStopListener method stopShare.
// Remove the share locator entry for this folder.
private void stopShare(Folder folder) {
final String me = folder.getMailbox().getAccountId();
final String uuid = folder.getUuid();
TimerTask t = new TimerTask() {
@Override
public void run() {
try {
Provisioning prov = Provisioning.getInstance();
ShareLocator shloc = prov.getShareLocatorById(uuid);
if (shloc != null) {
// Get the latest value from ldap master to avoid race condition during share relocation.
prov.reload(shloc, true);
// Delete locator only if it's not claimed by another account. (i.e. share moved)
if (me.equalsIgnoreCase(shloc.getShareOwnerAccountId())) {
prov.deleteShareLocator(uuid);
}
}
} catch (Throwable t) {
//don't let exceptions kill the timer
ZimbraLog.share.warn("error while processing share stop notification", t);
}
}
};
// run in separate thread to avoid ldap communication inside mailbox lock
Zimbra.sTimer.schedule(t, 0);
}
use of com.zimbra.cs.account.ShareLocator in project zm-mailbox by Zimbra.
the class ShareStartStopListener method startShare.
// Add the share locator entry for this folder.
private void startShare(Folder folder) {
final String me = folder.getMailbox().getAccountId();
final String uuid = folder.getUuid();
TimerTask t = new TimerTask() {
@Override
public void run() {
try {
Provisioning prov = Provisioning.getInstance();
ShareLocator shloc = prov.getShareLocatorById(uuid);
if (shloc == null) {
prov.createShareLocator(uuid, me);
} else {
// Get the latest value from ldap master to avoid race condition during share relocation.
prov.reload(shloc, true);
// Skip if locator already points to this account.
if (!me.equalsIgnoreCase(shloc.getShareOwnerAccountId())) {
// Change owner to this account.
Map<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraShareOwnerAccountId, me);
prov.modifyAttrs(shloc, attrs);
}
}
} catch (Throwable t) {
//don't let exceptions kill the timer
ZimbraLog.share.warn("error while processing share start notification", t);
}
}
};
// run in separate thread to avoid ldap communication inside mailbox lock
Zimbra.sTimer.schedule(t, 0);
}
Aggregations