001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.security.ldap;
016    
017    import com.liferay.portal.model.User;
018    import com.liferay.registry.Registry;
019    import com.liferay.registry.RegistryUtil;
020    import com.liferay.registry.ServiceTracker;
021    
022    import javax.naming.directory.Attributes;
023    import javax.naming.ldap.LdapContext;
024    
025    /**
026     * @author Michael C. Han
027     */
028    public class LDAPUserImporterUtil {
029    
030            public static User importUser(
031                            long ldapServerId, long companyId, LdapContext ldapContext,
032                            Attributes attributes, String password)
033                    throws Exception {
034    
035                    return _getInstance().importUser(
036                            ldapServerId, companyId, ldapContext, attributes, password);
037            }
038    
039            private static LDAPUserImporter _getInstance() {
040                    return _instance._serviceTracker.getService();
041            }
042    
043            private LDAPUserImporterUtil() {
044                    Registry registry = RegistryUtil.getRegistry();
045    
046                    _serviceTracker = registry.trackServices(LDAPUserImporter.class);
047    
048                    _serviceTracker.open();
049            }
050    
051            private static final LDAPUserImporterUtil _instance =
052                    new LDAPUserImporterUtil();
053    
054            private final ServiceTracker<LDAPUserImporter, LDAPUserImporter>
055                    _serviceTracker;
056    
057    }