001/*
002 * (C) Copyright 2006-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.service;
022
023import java.io.Serializable;
024import java.util.Map;
025import java.util.Set;
026
027import org.nuxeo.ecm.core.api.NuxeoException;
028import org.nuxeo.ecm.core.api.NuxeoPrincipal;
029import org.nuxeo.usermapper.extension.UserMapper;
030
031/**
032 * This service allows to map Nuxeo Users with users coming from external system like SSO or IDM.
033 *
034 * @author tiry
035 * @since 7.4
036 */
037public interface UserMapperService {
038
039    /**
040     * Should retrieve (create if needed) and update the NuxeoPrincipal according to the given userObject
041     *
042     * @param mappingName the name of the contributed mapping to use
043     * @param userObject the native userObject
044     * @return the matching {@link NuxeoPrincipal}
045     * @throws NuxeoException
046     */
047    NuxeoPrincipal getOrCreateAndUpdateNuxeoPrincipal(String mappingName, Object userObject) throws NuxeoException;
048
049    /**
050     * Should retrieve (create if needed) and update the NuxeoPrincipal according to the given userObject
051     *
052     * @param mappingName the name of the contributed mapping to use
053     * @param userObject the native userObject
054     * @param createIfNeeded flag to allow creation (default is true)
055     * @param update flag to run update (default is true)
056     * @return the matching {@link NuxeoPrincipal}
057     * @throws NuxeoException
058     */
059    NuxeoPrincipal getOrCreateAndUpdateNuxeoPrincipal(String mappingName, Object userObject, boolean createIfNeeded,
060            boolean update, Map<String, Serializable> params) throws NuxeoException;
061
062    /**
063     * Wrap the {@link NuxeoPrincipal} as the userObject used in the external authentication system *
064     *
065     * @param mappingName the name of the contributed mapping to use
066     * @param principal the {@link NuxeoPrincipal} to wrap
067     * @param nativePrincipal the principal Object in the target system (can be null)
068     * @throws NuxeoException
069     */
070    Object wrapNuxeoPrincipal(String mappingName, NuxeoPrincipal principal, Object nativePrincipal,
071            Map<String, Serializable> params) throws NuxeoException;
072
073    /**
074     * Gives access to the contributed Mapping names
075     */
076    Set<String> getAvailableMappings();
077
078    /**
079     * returns the named mapper is any
080     *
081     * @param mappingName
082     */
083    UserMapper getMapper(String mappingName) throws NuxeoException;
084}