Visiativ Document

Custom user synchronization

The default strategy is to synchronize all users between workplace and VIsiativ document. In some cases, it may be best to filter out and select only some users. To that end, you just need to create a custom class extending com.moovapps.document.strategy.BaseUserSync that you need to declare as a configuration parameter with this configuration key : com.moovapps.document.usersync=your.class.reference

Below is an exemple of a custom class filtering users with a group’s name and an organization’s name :

package com.moovapps.document.strategy;

import com.moovapps.document.sdk.usersync.strategies.BaseUserSyncStrategy;
import com.moovapps.document.triggers.MoovappsDocumentUserTrigger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.axemble.vdoc.sdk.Modules;
import com.axemble.vdoc.sdk.exceptions.DirectoryModuleException;
import com.axemble.vdoc.sdk.interfaces.IGroup;
import com.axemble.vdoc.sdk.interfaces.IOrganization;
import com.axemble.vdoc.sdk.interfaces.IUser;
import com.axemble.vdoc.sdk.modules.IDirectoryModule;

public class ExempleUserSync extends BaseUserSyncStrategy {

    private static final Logger LOG = LoggerFactory.getLogger(MoovappsDocumentUserTrigger.class);

    @Override
    public boolean checkIfEnabled(IUser user) {

        IDirectoryModule directoryModule = Modules.getDirectoryModule();

        try {
            IOrganization organization = directoryModule.getOrganization(directoryModule.getSysadminContext(), "exempleOrg");

            IGroup group = directoryModule.getGroup(directoryModule.getSysadminContext(), organization, "exempleGroup");
            return user.isMemberOf(group, true);

        } catch (DirectoryModuleException e) {
            LOG.error("Error when checking if a user should be synchronized for : " + user.getLogin(), e);
        } finally {
            Modules.releaseModule(directoryModule);
        }

        return false;
    }
}