1   /**
2    * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3    *
4    * This library is free software; you can redistribute it and/or modify it under
5    * the terms of the GNU Lesser General Public License as published by the Free
6    * Software Foundation; either version 2.1 of the License, or (at your option)
7    * any later version.
8    *
9    * This library is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11   * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12   * details.
13   */
14  
15  package com.liferay.portal.kernel.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.PortalClassLoaderUtil;
20  
21  import java.util.Map;
22  
23  import javax.security.auth.Subject;
24  import javax.security.auth.callback.CallbackHandler;
25  import javax.security.auth.login.LoginException;
26  import javax.security.auth.spi.LoginModule;
27  
28  /**
29   * <a href="PortalLoginModule.java.html"><b><i>View Source</i></b></a>
30   *
31   * @author Brian Wing Shun Chan
32   */
33  public class PortalLoginModule implements LoginModule {
34  
35      public PortalLoginModule() {
36          try {
37              Class<?> classObj = Class.forName(
38                  _CLASS_NAME, true, PortalClassLoaderUtil.getClassLoader());
39  
40              _loginModule = (LoginModule)classObj.newInstance();
41          }
42          catch (Exception e) {
43              _log.error(e);
44          }
45      }
46  
47      public boolean abort() throws LoginException {
48          return _loginModule.abort();
49      }
50  
51      public boolean commit() throws LoginException {
52          return _loginModule.commit();
53      }
54  
55      public void initialize(
56          Subject subject, CallbackHandler callbackHandler,
57          Map<String, ?> sharedState, Map<String, ?> options) {
58  
59          _loginModule.initialize(subject, callbackHandler, sharedState, options);
60      }
61  
62      public boolean login() throws LoginException {
63          return _loginModule.login();
64      }
65  
66      public boolean logout() throws LoginException {
67          return _loginModule.logout();
68      }
69  
70      private static final String _CLASS_NAME =
71          "com.liferay.portal.security.jaas.PortalLoginModule";
72  
73      private static Log _log = LogFactoryUtil.getLog(PortalLoginModule.class);
74  
75      private LoginModule _loginModule;
76  
77  }