001    /**
002     * Copyright (c) 2000-2013 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.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    }