001    /**
002     * Copyright (c) 2000-2010 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<?> classObj = Class.forName(
036                                    _CLASS_NAME, true, PortalClassLoaderUtil.getClassLoader());
037    
038                            _loginModule = (LoginModule)classObj.newInstance();
039                    }
040                    catch (Exception e) {
041                            _log.error(e);
042                    }
043            }
044    
045            public boolean abort() throws LoginException {
046                    return _loginModule.abort();
047            }
048    
049            public boolean commit() throws LoginException {
050                    return _loginModule.commit();
051            }
052    
053            public void initialize(
054                    Subject subject, CallbackHandler callbackHandler,
055                    Map<String, ?> sharedState, Map<String, ?> options) {
056    
057                    _loginModule.initialize(subject, callbackHandler, sharedState, options);
058            }
059    
060            public boolean login() throws LoginException {
061                    return _loginModule.login();
062            }
063    
064            public boolean logout() throws LoginException {
065                    return _loginModule.logout();
066            }
067    
068            private static final String _CLASS_NAME =
069                    "com.liferay.portal.security.jaas.PortalLoginModule";
070    
071            private static Log _log = LogFactoryUtil.getLog(PortalLoginModule.class);
072    
073            private LoginModule _loginModule;
074    
075    }