1   /**
2    * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
3    *
4    * Permission is hereby granted, free of charge, to any person obtaining a copy
5    * of this software and associated documentation files (the "Software"), to deal
6    * in the Software without restriction, including without limitation the rights
7    * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    * copies of the Software, and to permit persons to whom the Software is
9    * furnished to do so, subject to the following conditions:
10   *
11   * The above copyright notice and this permission notice shall be included in
12   * all copies or substantial portions of the Software.
13   *
14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20   * SOFTWARE.
21   */
22  
23  package com.liferay.portal.security.jaas;
24  
25  import com.liferay.portal.kernel.util.ServerDetector;
26  import com.liferay.portal.kernel.util.Validator;
27  import com.liferay.portal.util.PropsValues;
28  
29  import java.util.Map;
30  
31  import javax.security.auth.Subject;
32  import javax.security.auth.callback.CallbackHandler;
33  import javax.security.auth.login.LoginException;
34  import javax.security.auth.spi.LoginModule;
35  
36  import org.apache.commons.logging.Log;
37  import org.apache.commons.logging.LogFactory;
38  
39  /**
40   * <a href="PortalLoginModule.java.html"><b><i>View Source</i></b></a>
41   *
42   * @author Brian Wing Shun Chan
43   *
44   */
45  public class PortalLoginModule implements LoginModule {
46  
47      public PortalLoginModule() {
48          if (Validator.isNotNull(PropsValues.PORTAL_JAAS_IMPL)) {
49              try {
50                  _loginModule = (LoginModule)Class.forName(
51                      PropsValues.PORTAL_JAAS_IMPL).newInstance();
52              }
53              catch (Exception e) {
54                  _log.error(e);
55              }
56          }
57  
58          if (_loginModule == null) {
59  
60              // Check application servers
61  
62              if (ServerDetector.isJBoss()) {
63                  _loginModule =
64                      new com.liferay.portal.security.jaas.ext.jboss.PortalLoginModule();
65              }
66              else if (ServerDetector.isJOnAS()) {
67                  _loginModule =
68                      new com.liferay.portal.security.jaas.ext.jonas.PortalLoginModule();
69              }
70              else if (ServerDetector.isResin()) {
71                  _loginModule =
72                      new com.liferay.portal.security.jaas.ext.resin.PortalLoginModule();
73              }
74              else if (ServerDetector.isWebLogic()) {
75                  _loginModule =
76                      new com.liferay.portal.security.jaas.ext.weblogic.PortalLoginModule();
77              }
78  
79              // Check servlet containers
80  
81              else if (ServerDetector.isJetty()) {
82                  _loginModule =
83                      new com.liferay.portal.security.jaas.ext.jetty.PortalLoginModule();
84              }
85              else if (ServerDetector.isTomcat()) {
86                  _loginModule =
87                      new com.liferay.portal.security.jaas.ext.tomcat.PortalLoginModule();
88              }
89          }
90  
91          if (_log.isDebugEnabled()) {
92              _log.debug(_loginModule.getClass().getName());
93          }
94      }
95  
96      public boolean abort() throws LoginException {
97          return _loginModule.abort();
98      }
99  
100     public boolean commit() throws LoginException {
101         return _loginModule.commit();
102     }
103 
104     public void initialize(
105         Subject subject, CallbackHandler callbackHandler, Map sharedState,
106         Map options) {
107 
108         _loginModule.initialize(subject, callbackHandler, sharedState, options);
109     }
110 
111     public boolean login() throws LoginException {
112         return _loginModule.login();
113     }
114 
115     public boolean logout() throws LoginException {
116         return _loginModule.logout();
117     }
118 
119     private static Log _log = LogFactory.getLog(PortalLoginModule.class);
120 
121     private LoginModule _loginModule;
122 
123 }