001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.security.jaas;
022:
023: import com.liferay.portal.kernel.util.ServerDetector;
024: import com.liferay.portal.kernel.util.Validator;
025: import com.liferay.portal.util.PropsValues;
026:
027: import java.util.Map;
028:
029: import javax.security.auth.Subject;
030: import javax.security.auth.callback.CallbackHandler;
031: import javax.security.auth.login.LoginException;
032: import javax.security.auth.spi.LoginModule;
033:
034: import org.apache.commons.logging.Log;
035: import org.apache.commons.logging.LogFactory;
036:
037: /**
038: * <a href="PortalLoginModule.java.html"><b><i>View Source</i></b></a>
039: *
040: * @author Brian Wing Shun Chan
041: *
042: */
043: public class PortalLoginModule implements LoginModule {
044:
045: public PortalLoginModule() {
046: if (Validator.isNotNull(PropsValues.PORTAL_JAAS_IMPL)) {
047: try {
048: _loginModule = (LoginModule) Class.forName(
049: PropsValues.PORTAL_JAAS_IMPL).newInstance();
050: } catch (Exception e) {
051: _log.error(e);
052: }
053: }
054:
055: if (_loginModule == null) {
056:
057: // Check application servers
058:
059: if (ServerDetector.isJBoss()) {
060: _loginModule = new com.liferay.portal.security.jaas.ext.jboss.PortalLoginModule();
061: } else if (ServerDetector.isJOnAS()) {
062: _loginModule = new com.liferay.portal.security.jaas.ext.jonas.PortalLoginModule();
063: } else if (ServerDetector.isResin()) {
064: _loginModule = new com.liferay.portal.security.jaas.ext.resin.PortalLoginModule();
065: } else if (ServerDetector.isWebLogic()) {
066: _loginModule = new com.liferay.portal.security.jaas.ext.weblogic.PortalLoginModule();
067: }
068:
069: // Check servlet containers
070:
071: else if (ServerDetector.isJetty()) {
072: _loginModule = new com.liferay.portal.security.jaas.ext.jetty.PortalLoginModule();
073: } else if (ServerDetector.isTomcat()) {
074: _loginModule = new com.liferay.portal.security.jaas.ext.tomcat.PortalLoginModule();
075: }
076: }
077:
078: if (_log.isDebugEnabled()) {
079: _log.debug(_loginModule.getClass().getName());
080: }
081: }
082:
083: public boolean abort() throws LoginException {
084: return _loginModule.abort();
085: }
086:
087: public boolean commit() throws LoginException {
088: return _loginModule.commit();
089: }
090:
091: public void initialize(Subject subject,
092: CallbackHandler callbackHandler, Map sharedState,
093: Map options) {
094:
095: _loginModule.initialize(subject, callbackHandler, sharedState,
096: options);
097: }
098:
099: public boolean login() throws LoginException {
100: return _loginModule.login();
101: }
102:
103: public boolean logout() throws LoginException {
104: return _loginModule.logout();
105: }
106:
107: private static Log _log = LogFactory
108: .getLog(PortalLoginModule.class);
109:
110: private LoginModule _loginModule;
111:
112: }
|