001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl-2.1.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Nuxeo - initial API and implementation
016 *
017 */
018
019package org.nuxeo.usermapper.extension;
020
021import java.io.Serializable;
022import java.util.Map;
023
024import org.nuxeo.ecm.core.api.NuxeoPrincipal;
025import org.nuxeo.usermapper.service.UserMapperService;
026
027/**
028 * Interface for class providing a named implementation for the {@link UserMapperService}
029 *
030 * @author tiry
031 * @since 7.4
032 */
033public interface UserMapper {
034
035    /**
036     * Should retrieve (create if needed) and update the NuxeoPrincipal according to the given userObject
037     *
038     * @param userObject the object representing the user in the external system
039     */
040    NuxeoPrincipal getOrCreateAndUpdateNuxeoPrincipal(Object userObject);
041
042    /**
043     * Should retrieve (create if needed) and update the NuxeoPrincipal according to the given userObject
044     *
045     * @param userObject the object representing the user in the external system
046     * @param createIfNeeded flag to allow creation (default is true)
047     * @param update flag to run update (default is true)
048     */
049
050    NuxeoPrincipal getOrCreateAndUpdateNuxeoPrincipal(Object userObject, boolean createIfNeeded, boolean update,
051            Map<String, Serializable> params);
052
053    /**
054     * Wrap the {@link NuxeoPrincipal} as the userObject used in the external authentication system
055     *
056     * @param principal the NuxeoPrincipal
057     * @param nativePrincipal the native object to represent the principal in the target system
058     */
059    Object wrapNuxeoPrincipal(NuxeoPrincipal principal, Object nativePrincipal, Map<String, Serializable> params);
060
061    /**
062     * Init callback to receive the parameters set inside the descriptor
063     *
064     * @param params
065     * @throws Exception
066     */
067    void init(Map<String, String> params) throws Exception;
068
069    /**
070     * Release callback : called when the plugin is about to be unloaded
071     */
072    void release();
073}