1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * The contents of this file are subject to the terms of the Liferay Enterprise
5    * Subscription License ("License"). You may not use this file except in
6    * compliance with the License. You can obtain a copy of the License by
7    * contacting Liferay, Inc. See the License for the specific language governing
8    * permissions and limitations under the License, including but not limited to
9    * distribution rights of the Software.
10   *
11   *
12   *
13   */
14  
15  package com.liferay.portal.security.jaas;
16  
17  import com.liferay.portal.kernel.log.Log;
18  import com.liferay.portal.kernel.log.LogFactoryUtil;
19  import com.liferay.portal.kernel.util.InstanceFactory;
20  import com.liferay.portal.kernel.util.ServerDetector;
21  import com.liferay.portal.kernel.util.Validator;
22  import com.liferay.portal.util.PropsValues;
23  
24  import java.util.Map;
25  
26  import javax.security.auth.Subject;
27  import javax.security.auth.callback.CallbackHandler;
28  import javax.security.auth.login.LoginException;
29  import javax.security.auth.spi.LoginModule;
30  
31  /**
32   * <a href="PortalLoginModule.java.html"><b><i>View Source</i></b></a>
33   *
34   * @author Brian Wing Shun Chan
35   */
36  public class PortalLoginModule implements LoginModule {
37  
38      public PortalLoginModule() {
39          if (Validator.isNotNull(PropsValues.PORTAL_JAAS_IMPL)) {
40              try {
41                  _loginModule = (LoginModule)InstanceFactory.newInstance(
42                      PropsValues.PORTAL_JAAS_IMPL);
43              }
44              catch (Exception e) {
45                  _log.error(e, e);
46              }
47          }
48  
49          if (_loginModule == null) {
50              if (ServerDetector.isJBoss()) {
51                  _loginModule =
52                      new com.liferay.portal.security.jaas.ext.jboss.
53                          PortalLoginModule();
54              }
55              else if (ServerDetector.isJetty()) {
56                  _loginModule =
57                      new com.liferay.portal.security.jaas.ext.jetty.
58                          PortalLoginModule();
59              }
60              else if (ServerDetector.isJOnAS()) {
61                  _loginModule =
62                      new com.liferay.portal.security.jaas.ext.jonas.
63                          PortalLoginModule();
64              }
65              else if (ServerDetector.isResin()) {
66                  _loginModule =
67                      new com.liferay.portal.security.jaas.ext.resin.
68                          PortalLoginModule();
69              }
70              else if (ServerDetector.isTomcat()) {
71                  _loginModule =
72                      new com.liferay.portal.security.jaas.ext.tomcat.
73                          PortalLoginModule();
74              }
75              else if (ServerDetector.isWebLogic()) {
76                  _loginModule =
77                      new com.liferay.portal.security.jaas.ext.weblogic.
78                          PortalLoginModule();
79              }
80          }
81  
82          if (_log.isDebugEnabled()) {
83              _log.debug(_loginModule.getClass().getName());
84          }
85      }
86  
87      public boolean abort() throws LoginException {
88          return _loginModule.abort();
89      }
90  
91      public boolean commit() throws LoginException {
92          return _loginModule.commit();
93      }
94  
95      public void initialize(
96          Subject subject, CallbackHandler callbackHandler,
97          Map<String, ?> sharedState, Map<String, ?> options) {
98  
99          _loginModule.initialize(subject, callbackHandler, sharedState, options);
100     }
101 
102     public boolean login() throws LoginException {
103         return _loginModule.login();
104     }
105 
106     public boolean logout() throws LoginException {
107         return _loginModule.logout();
108     }
109 
110     private static Log _log = LogFactoryUtil.getLog(PortalLoginModule.class);
111 
112     private LoginModule _loginModule;
113 
114 }