001/*
002 * (C) Copyright 2015 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Nuxeo - initial API and implementation
018 *
019 */
020
021package org.nuxeo.usermapper.extension;
022
023import java.io.Serializable;
024import java.util.Map;
025
026import org.nuxeo.ecm.core.api.NuxeoPrincipal;
027import org.nuxeo.usermapper.service.UserMapperService;
028
029/**
030 * Interface for class providing a named implementation for the {@link UserMapperService}
031 *
032 * @author tiry
033 * @since 7.4
034 */
035public interface UserMapper {
036
037    /**
038     * Should retrieve (create if needed) and update the NuxeoPrincipal according to the given userObject
039     *
040     * @param userObject the object representing the user in the external system
041     */
042    NuxeoPrincipal getOrCreateAndUpdateNuxeoPrincipal(Object userObject);
043
044    /**
045     * Should retrieve (create if needed) and update the NuxeoPrincipal according to the given userObject
046     *
047     * @param userObject the object representing the user in the external system
048     * @param createIfNeeded flag to allow creation (default is true)
049     * @param update flag to run update (default is true)
050     */
051
052    NuxeoPrincipal getOrCreateAndUpdateNuxeoPrincipal(Object userObject, boolean createIfNeeded, boolean update,
053            Map<String, Serializable> params);
054
055    /**
056     * Wrap the {@link NuxeoPrincipal} as the userObject used in the external authentication system
057     *
058     * @param principal the NuxeoPrincipal
059     * @param nativePrincipal the native object to represent the principal in the target system
060     */
061    Object wrapNuxeoPrincipal(NuxeoPrincipal principal, Object nativePrincipal, Map<String, Serializable> params);
062
063    /**
064     * Init callback to receive the parameters set inside the descriptor
065     */
066    void init(Map<String, String> params) throws Exception;
067
068    /**
069     * Release callback : called when the plugin is about to be unloaded
070     */
071    void release();
072}