001: /*
002: jGuard is a security framework based on top of jaas (java authentication and authorization security).
003: it is written for web applications, to resolve simply, access control problems.
004: version $Name$
005: http://sourceforge.net/projects/jguard/
006:
007: Copyright (C) 2004 Charles GAY
008:
009: This library is free software; you can redistribute it and/or
010: modify it under the terms of the GNU Lesser General Public
011: License as published by the Free Software Foundation; either
012: version 2.1 of the License, or (at your option) any later version.
013:
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018:
019: You should have received a copy of the GNU Lesser General Public
020: License along with this library; if not, write to the Free Software
021: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
022:
023:
024: jGuard project home page:
025: http://sourceforge.net/projects/jguard/
026:
027: */
028: package net.sf.jguard.ext.authentication.manager;
029:
030: import java.util.Map;
031: import java.util.logging.Logger;
032:
033: import net.sf.jguard.ext.authentication.AuthenticationException;
034:
035: /**
036: * build an AuthenticationManager implementation.
037: * @author <a href="mailto:diabolo512@users.sourceforge.net">Charles Gay</a>
038: */
039: public class AuthenticationManagerFactory {
040:
041: private static AuthenticationManager authenticationManager;
042: private static Logger logger = Logger
043: .getLogger(AuthenticationManagerFactory.class.getName());
044:
045: /**
046: * Convenience method that returns the current AuthenticationManager.
047: * implementation.
048: *
049: * @return authenticationManager or<code><strong>null</strong></code> when
050: * no authenticationManager is created.
051: */
052: public static AuthenticationManager getAuthenticationManager() {
053: return authenticationManager;
054: }
055:
056: /**
057: * initialize the DAO implementation.
058: * @param authenticationManagerImpl
059: * @param map
060: * @return <code>true</code> if AuthenticationManager is created successfully, <code>false</code> otherwise
061: * @throws AuthenticationException
062: */
063: public static boolean createAuthenticationManager(
064: String authenticationManagerImpl, Map map)
065: throws AuthenticationException {
066: if (authenticationManager != null) {
067: return false;
068: }
069: logger.info("authenticationManagerImpl="
070: + authenticationManagerImpl);
071: if (authenticationManagerImpl == null
072: || authenticationManagerImpl.equals("")) {
073: throw new AuthenticationException(
074: " authenticationManager implementation is null or empty "
075: + authenticationManagerImpl);
076: }
077: try {
078:
079: authenticationManager = (AuthenticationManager) Class
080: .forName(authenticationManagerImpl).newInstance();
081: authenticationManager.init(map);
082:
083: } catch (InstantiationException e) {
084: System.out.println("InstantiationException DAOImpl problem"
085: + e.getMessage());
086: throw new AuthenticationException(
087: " InstantiationException DAOImpl " + e.getMessage(),
088: e);
089: } catch (IllegalAccessException e) {
090: System.out.println("IllegalAccessException DAOImpl problem"
091: + e.getMessage());
092: throw new AuthenticationException(
093: " IllegalAccessException DAOImpl " + e.getMessage(),
094: e);
095: } catch (ClassNotFoundException e) {
096: System.out.println("ClassNotFoundException DAOImpl problem"
097: + e.getMessage());
098: throw new AuthenticationException(
099: " ClassNotFoundException DAOImpl " + e.getMessage(),
100: e);
101: }
102: return true;
103: }
104:
105: public static void setAuthenticationManager(
106: AuthenticationManager authenticationManager) {
107: AuthenticationManagerFactory.authenticationManager = authenticationManager;
108: }
109: }
|