KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jguard > ext > authorization > AuthorizationManagerFactory


1 /*
2 jGuard is a security framework based on top of jaas (java authentication and authorization security).
3 it is written for web applications, to resolve simply, access control problems.
4 version $Name$
5 http://sourceforge.net/projects/jguard/
6
7 Copyright (C) 2004 Charles GAY
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
23
24 jGuard project home page:
25 http://sourceforge.net/projects/jguard/
26
27 */

28 package net.sf.jguard.ext.authorization;
29
30 import java.util.Map JavaDoc;
31 import java.util.logging.Level JavaDoc;
32 import java.util.logging.Logger JavaDoc;
33
34 import net.sf.jguard.ext.SecurityConstants;
35 import net.sf.jguard.ext.authorization.manager.AuthorizationManager;
36
37
38
39 /**
40  * permission manager factory, which returns the AuthorizationManager implementation.
41  * this class is loaded by the jvm classloader. we cannot used commons-logging library
42  * loaded by the application sevrer classloader.
43  * @author <a HREF="mailto:diabolo512@users.sourceforge.net ">Charles Gay</a>
44  *
45  */

46 public class AuthorizationManagerFactory {
47     /** Logger for this class */
48     private static final Logger JavaDoc logger = Logger.getLogger(AuthorizationManagerFactory.class.getName());
49     private static AuthorizationManager authorizationManager = null;
50
51
52     /**
53      * define the AuthorizationManager implementation and return it.
54      * @param authorizationManagerOptions
55      * @return <strong>true</strong> if creation succeed,
56      * <strong>false</strong> if one
57      * @throws AuthorizationException
58      */

59     public static boolean createAuthorizationManager(Map JavaDoc authorizationManagerOptions) throws AuthorizationException {
60         if(authorizationManager!= null){
61             return false;
62         }
63         Class JavaDoc clazz = null;
64         try {
65                String JavaDoc authorizationManagerImplName =(String JavaDoc)authorizationManagerOptions.get(SecurityConstants.AUTHORIZATION_MANAGER);
66                ClassLoader JavaDoc cl = AuthorizationManagerFactory.class.getClassLoader();
67                clazz = Class.forName(authorizationManagerImplName,true,cl);
68
69                authorizationManager = (AuthorizationManager)clazz.newInstance();
70                logger.log(Level.FINEST,"authorizationManagerOptions="+authorizationManagerOptions);
71                authorizationManager.init(authorizationManagerOptions);
72
73         } catch (InstantiationException JavaDoc e1) {
74             if (logger.isLoggable(Level.FINEST)) {
75                 logger.log(Level.FINEST,"getPermissionManager() - dao Implementation cannot be instantiated : InstantiationException");
76             }
77             throw new AuthorizationException(" dao Implementation cannot be instantiated : InstantiationException",e1);
78         } catch (IllegalAccessException JavaDoc e1) {
79             if (logger.isLoggable(Level.FINEST)) {
80                 logger.log(Level.FINEST,"getPermissionManager() - dao Implementation cannot be accessed : IllegalAccessException");
81             }
82             throw new AuthorizationException(" dao Implementation cannot be accessed: IllegalAccessException",e1);
83         } catch (ClassNotFoundException JavaDoc e) {
84             if (logger.isLoggable(Level.FINEST)) {
85                 logger.log(Level.FINEST,"getPermissionManager() - dao Implementation cannot be found: ClassNotFoundException");
86             }
87             throw new AuthorizationException(" dao Implementation cannot be found: ClassNotFoundException",e);
88         }
89         return true;
90
91     }
92
93
94     /**
95      * @return authorizationManager or <code><strong>null</strong></code> when no authorizationManager is already created
96      */

97     public static AuthorizationManager getAuthorizationManager() {
98         return authorizationManager;
99     }
100
101
102 }
103
Popular Tags