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.kernel.security.jaas;
016    
017    import com.liferay.portal.kernel.util.PortalClassLoaderUtil;
018    
019    import java.util.Map;
020    
021    import javax.security.auth.Subject;
022    import javax.security.auth.callback.CallbackHandler;
023    import javax.security.auth.login.LoginException;
024    import javax.security.auth.spi.LoginModule;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class PortalLoginModule implements LoginModule {
030    
031            public PortalLoginModule() {
032                    try {
033                            Class<?> clazz = Class.forName(
034                                    _CLASS_NAME, true, PortalClassLoaderUtil.getClassLoader());
035    
036                            _loginModule = (LoginModule)clazz.newInstance();
037                    }
038                    catch (Exception e) {
039                            throw new AssertionError(e);
040                    }
041            }
042    
043            @Override
044            public boolean abort() throws LoginException {
045                    return _loginModule.abort();
046            }
047    
048            @Override
049            public boolean commit() throws LoginException {
050                    return _loginModule.commit();
051            }
052    
053            @Override
054            public void initialize(
055                    Subject subject, CallbackHandler callbackHandler,
056                    Map<String, ?> sharedState, Map<String, ?> options) {
057    
058                    _loginModule.initialize(subject, callbackHandler, sharedState, options);
059            }
060    
061            @Override
062            public boolean login() throws LoginException {
063                    return _loginModule.login();
064            }
065    
066            @Override
067            public boolean logout() throws LoginException {
068                    return _loginModule.logout();
069            }
070    
071            private static final String _CLASS_NAME =
072                    "com.liferay.portal.security.jaas.PortalLoginModule";
073    
074            private final LoginModule _loginModule;
075    
076    }