Search in sources :

Example 1 with ShareLocator

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

Example 2 with ShareLocator

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);
    }
}
Also used : ZMutableEntry(com.zimbra.cs.ldap.ZMutableEntry) LdapEntryAlreadyExistException(com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException) AccountServiceException(com.zimbra.cs.account.AccountServiceException) ZLdapContext(com.zimbra.cs.ldap.ZLdapContext) AccountServiceException(com.zimbra.cs.account.AccountServiceException) AuthFailedServiceException(com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException) ServiceException(com.zimbra.common.service.ServiceException) CallbackContext(com.zimbra.cs.account.callback.CallbackContext) LdapException(com.zimbra.cs.ldap.LdapException) LdapShareLocator(com.zimbra.cs.account.ldap.entry.LdapShareLocator) ShareLocator(com.zimbra.cs.account.ShareLocator)

Example 3 with ShareLocator

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;
    }
}
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 4 with ShareLocator

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);
}
Also used : TimerTask(java.util.TimerTask) Provisioning(com.zimbra.cs.account.Provisioning) ShareLocator(com.zimbra.cs.account.ShareLocator)

Example 5 with ShareLocator

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);
}
Also used : TimerTask(java.util.TimerTask) HashMap(java.util.HashMap) Provisioning(com.zimbra.cs.account.Provisioning) ShareLocator(com.zimbra.cs.account.ShareLocator)

Aggregations

ShareLocator (com.zimbra.cs.account.ShareLocator)5 Provisioning (com.zimbra.cs.account.Provisioning)3 LdapShareLocator (com.zimbra.cs.account.ldap.entry.LdapShareLocator)2 TimerTask (java.util.TimerTask)2 ZFolder (com.zimbra.client.ZFolder)1 ZMailbox (com.zimbra.client.ZMailbox)1 Options (com.zimbra.client.ZMailbox.Options)1 ZAuthToken (com.zimbra.common.auth.ZAuthToken)1 ServiceException (com.zimbra.common.service.ServiceException)1 Account (com.zimbra.cs.account.Account)1 AccountServiceException (com.zimbra.cs.account.AccountServiceException)1 AuthFailedServiceException (com.zimbra.cs.account.AccountServiceException.AuthFailedServiceException)1 AuthToken (com.zimbra.cs.account.AuthToken)1 CallbackContext (com.zimbra.cs.account.callback.CallbackContext)1 LdapException (com.zimbra.cs.ldap.LdapException)1 LdapEntryAlreadyExistException (com.zimbra.cs.ldap.LdapException.LdapEntryAlreadyExistException)1 ZLdapContext (com.zimbra.cs.ldap.ZLdapContext)1 ZMutableEntry (com.zimbra.cs.ldap.ZMutableEntry)1 ParsedMessageOptions (com.zimbra.cs.mime.ParsedMessageOptions)1 CreateMountpoint (com.zimbra.cs.redolog.op.CreateMountpoint)1