KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mr > kernel > security > authorization > ActionFactory


1 /*
2  * Copyright 2002 by
3  * <a HREF="http://www.coridan.com">Coridan</a>
4  * <a HREF="mailto: support@coridan.com ">support@coridan.com</a>
5  *
6  * The contents of this file are subject to the Mozilla Public License Version
7  * 1.1 (the "License"); you may not use this file except in compliance with the
8  * License. You may obtain a copy of the License at
9  * http://www.mozilla.org/MPL/
10  *
11  * Software distributed under the License is distributed on an "AS IS" basis,
12  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13  * for the specific language governing rights and limitations under the
14  * License.
15  *
16  * The Original Code is "MantaRay" (TM).
17  *
18  * The Initial Developer of the Original Code is Shirley Sasson.
19  * Portions created by the Initial Developer are Copyright (C) 2006
20  * Coridan Inc. All Rights Reserved.
21  *
22  * Contributor(s): all the names of the contributors are added in the source
23  * code where applicable.
24  *
25  * Alternatively, the contents of this file may be used under the terms of the
26  * LGPL license (the "GNU LESSER GENERAL PUBLIC LICENSE"), in which case the
27  * provisions of LGPL are applicable instead of those above. If you wish to
28  * allow use of your version of this file only under the terms of the LGPL
29  * License and not to allow others to use your version of this file under
30  * the MPL, indicate your decision by deleting the provisions above and
31  * replace them with the notice and other provisions required by the LGPL.
32  * If you do not delete the provisions above, a recipient may use your version
33  * of this file under either the MPL or the GNU LESSER GENERAL PUBLIC LICENSE.
34
35  *
36  * This library is free software; you can redistribute it and/or modify it
37  * under the terms of the MPL as stated above or under the terms of the GNU
38  * Lesser General Public License as published by the Free Software Foundation;
39  * either version 2.1 of the License, or any later version.
40  *
41  * This library is distributed in the hope that it will be useful, but WITHOUT
42  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
44  * License for more details.
45  */

46
47 package org.mr.kernel.security.authorization;
48
49 import org.mr.kernel.security.MantaSecurityException;
50 import org.mr.kernel.security.SecurityActionTypes;
51 import org.apache.commons.logging.Log;
52 import org.apache.commons.logging.LogFactory;
53
54 import java.util.Map JavaDoc;
55 import java.util.HashMap JavaDoc;
56
57 import org.mr.kernel.security.authorization.actions.MantaAction;
58
59 /**
60  * This class is a factory class for secured actions. It creates an instance of
61  * MantaAction object according to the action type integer supplied.
62  *
63  * This class is a singltone.
64  *
65  * @version 1.0
66  * @since May 9, 2006
67  * @author Shirley Sasson
68  *
69  */

70 public class ActionFactory implements SecurityActionTypes {
71     private static ActionFactory _instance;
72     private static Map JavaDoc _names;
73     private Log _logger;
74
75     /**
76       * Returns the single instance of ActionFactory.
77       *
78       * @return the single instance of ActionFactory
79       */

80     public static ActionFactory getInstance() {
81         if (_instance == null){
82             synchronized(ActionFactory.class){
83                 if (_instance == null)
84                     _instance = new ActionFactory();
85             }
86         }
87         return _instance;
88     }
89
90     private ActionFactory(){
91         // initialize the map
92
_names = new HashMap JavaDoc();
93         _names.put(new Integer JavaDoc(ACTION_CREATE_CONSUMER_FOR_QUEUE), "org.mr.kernel.security.authorization.actions.CreateConsumerForQueueAction");
94         _names.put(new Integer JavaDoc(ACTION_CREATE_PRODUCER_FOR_QUEUE), "org.mr.kernel.security.authorization.actions.CreateProducerForQueueAction");
95         _names.put(new Integer JavaDoc(ACTION_CREATE_CONSUMER_FOR_TOPIC), "org.mr.kernel.security.authorization.actions.CreateConsumerForTopicAction");
96         _names.put(new Integer JavaDoc(ACTION_CREATE_PRODUCER_FOR_TOPIC), "org.mr.kernel.security.authorization.actions.CreateProducerForTopicAction");
97         _names.put(new Integer JavaDoc(ACTION_CREATE_BROSWER_FOR_QUEUE), "org.mr.kernel.security.authorization.actions.CreateBrowserForQueueAction");
98         _names.put(new Integer JavaDoc(ACTION_SUBSCRIBE_DURABLE_ON_TOPIC), "org.mr.kernel.security.authorization.actions.SubscribeDurableOnTopicAction");
99         _names.put(new Integer JavaDoc(ACTION_CREATE_GROUP), "org.mr.kernel.security.authorization.actions.management.CreateGroupAction");
100         _names.put(new Integer JavaDoc(ACTION_CREATE_USER_IN_GROUP), "org.mr.kernel.security.authorization.actions.management.CreateUserInGroupAction");
101         _names.put(new Integer JavaDoc(ACTION_RENAME_GROUP), "org.mr.kernel.security.authorization.actions.management.RenameGroupAction");
102         _names.put(new Integer JavaDoc(ACTION_RENAME_USER), "org.mr.kernel.security.authorization.actions.management.RenameUserAction");
103         _names.put(new Integer JavaDoc(ACTION_SET_GROUP_FOR_USER), "org.mr.kernel.security.authorization.actions.management.SetGroupForUserAction");
104         _names.put(new Integer JavaDoc(ACTION_SET_PASSWORD_FOR_USER), "org.mr.kernel.security.authorization.actions.management.SetPasswordForUserAction");
105         _names.put(new Integer JavaDoc(ACTION_CREATE_PERMISSIONS_FOR_GROUP), "org.mr.kernel.security.authorization.actions.management.CreatePermissionForGroupAction");
106         _names.put(new Integer JavaDoc(ACTION_READ_PERMISSIONS_FOR_GROUP), "org.mr.kernel.security.authorization.actions.management.ReadPermissionForGroupAction");
107         _names.put(new Integer JavaDoc(ACTION_DELETE_PERMISSIONS_FOR_GROUP), "org.mr.kernel.security.authorization.actions.management.DeletePermissionForGroupAction");
108         _names.put(new Integer JavaDoc(ACTION_CREATE_PERMISSIONS_FOR_USER), "org.mr.kernel.security.authorization.actions.management.CreatePermissionForUserAction");
109         _names.put(new Integer JavaDoc(ACTION_READ_PERMISSIONS_FOR_USER), "org.mr.kernel.security.authorization.actions.management.ReadPermissionForUserAction");
110         _names.put(new Integer JavaDoc(ACTION_DELETE_PERMISSIONS_FOR_USER), "org.mr.kernel.security.authorization.actions.management.DeletePermissionForUserAction");
111         _names.put(new Integer JavaDoc(ACTION_DELETE_USER), "org.mr.kernel.security.authorization.actions.management.DeleteUserAction");
112         _names.put(new Integer JavaDoc(ACTION_DELETE_GROUP), "org.mr.kernel.security.authorization.actions.management.DeleteGroupAction");
113         _names.put(new Integer JavaDoc(ACTION_CREATE_WHITE_LIST_ENTRY), "org.mr.kernel.security.authorization.actions.management.CreateWhiteListEntryAction");
114         _names.put(new Integer JavaDoc(ACTION_DELETE_WHITE_LIST_ENTRY), "org.mr.kernel.security.authorization.actions.management.DeleteWhiteListEntryAction");
115         _names.put(new Integer JavaDoc(ACTION_LIST_USERS), "org.mr.kernel.security.authorization.actions.management.ListUsersAction");
116         _names.put(new Integer JavaDoc(ACTION_LIST_GROUPS), "org.mr.kernel.security.authorization.actions.management.ListGroupsAction");
117         _names.put(new Integer JavaDoc(ACTION_LIST_WHITE_LIST), "org.mr.kernel.security.authorization.actions.management.ListWhiteListAction");
118     }
119
120     /**
121      * Returns an instance of MantaAction according to the action type.
122      *
123      * @param actionType
124      * an integer specifying the action type
125      * @return a list of permissions to be searched
126      * @throws MantaSecurityException if an error occured
127      */

128     public MantaAction getMantaAction(int actionType) throws MantaSecurityException {
129         String JavaDoc className = (String JavaDoc) _names.get(new Integer JavaDoc(actionType));
130         MantaAction action;
131         try {
132             action = (MantaAction) Class.forName(className).newInstance();
133
134             if (getLogger().isDebugEnabled())
135                 getLogger().debug("[getMantaAction] Class " + className + " was instantiated");
136         }
137         catch (Exception JavaDoc e){
138             if (getLogger().isErrorEnabled())
139                 getLogger().error("[getMantaAction] Error instantiating MantaAction class: " + className);
140             throw new MantaSecurityException("Error instantiating MantaAction class: " + className);
141         }
142         return action;
143     }
144
145     /**
146      * Returns the instance of the logger for this class
147      *
148      * @return the instance of the logger
149      */

150     public Log getLogger(){
151         if (_logger == null){
152             _logger = LogFactory.getLog(getClass().getName());
153         }
154         return _logger;
155     }
156 }
157
Popular Tags