001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.kernel.security.jaas;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
020    
021    import java.util.Map;
022    
023    import javax.security.auth.Subject;
024    import javax.security.auth.callback.CallbackHandler;
025    import javax.security.auth.login.LoginException;
026    import javax.security.auth.spi.LoginModule;
027    
028    /**
029     * @author Brian Wing Shun Chan
030     */
031    public class PortalLoginModule implements LoginModule {
032    
033            public PortalLoginModule() {
034                    try {
035                            Class<?> clazz = Class.forName(
036                                    _CLASS_NAME, true, PortalClassLoaderUtil.getClassLoader());
037    
038                            _loginModule = (LoginModule)clazz.newInstance();
039                    }
040                    catch (Exception e) {
041                            _log.error(e);
042                    }
043            }
044    
045            @Override
046            public boolean abort() throws LoginException {
047                    return _loginModule.abort();
048            }
049    
050            @Override
051            public boolean commit() throws LoginException {
052                    return _loginModule.commit();
053            }
054    
055            @Override
056            public void initialize(
057                    Subject subject, CallbackHandler callbackHandler,
058                    Map<String, ?> sharedState, Map<String, ?> options) {
059    
060                    _loginModule.initialize(subject, callbackHandler, sharedState, options);
061            }
062    
063            @Override
064            public boolean login() throws LoginException {
065                    return _loginModule.login();
066            }
067    
068            @Override
069            public boolean logout() throws LoginException {
070                    return _loginModule.logout();
071            }
072    
073            private static final String _CLASS_NAME =
074                    "com.liferay.portal.security.jaas.PortalLoginModule";
075    
076            private static Log _log = LogFactoryUtil.getLog(PortalLoginModule.class);
077    
078            private LoginModule _loginModule;
079    
080    }