1 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 ; 55 import java.util.HashMap ; 56 57 import org.mr.kernel.security.authorization.actions.MantaAction; 58 59 70 public class ActionFactory implements SecurityActionTypes { 71 private static ActionFactory _instance; 72 private static Map _names; 73 private Log _logger; 74 75 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 _names = new HashMap (); 93 _names.put(new Integer (ACTION_CREATE_CONSUMER_FOR_QUEUE), "org.mr.kernel.security.authorization.actions.CreateConsumerForQueueAction"); 94 _names.put(new Integer (ACTION_CREATE_PRODUCER_FOR_QUEUE), "org.mr.kernel.security.authorization.actions.CreateProducerForQueueAction"); 95 _names.put(new Integer (ACTION_CREATE_CONSUMER_FOR_TOPIC), "org.mr.kernel.security.authorization.actions.CreateConsumerForTopicAction"); 96 _names.put(new Integer (ACTION_CREATE_PRODUCER_FOR_TOPIC), "org.mr.kernel.security.authorization.actions.CreateProducerForTopicAction"); 97 _names.put(new Integer (ACTION_CREATE_BROSWER_FOR_QUEUE), "org.mr.kernel.security.authorization.actions.CreateBrowserForQueueAction"); 98 _names.put(new Integer (ACTION_SUBSCRIBE_DURABLE_ON_TOPIC), "org.mr.kernel.security.authorization.actions.SubscribeDurableOnTopicAction"); 99 _names.put(new Integer (ACTION_CREATE_GROUP), "org.mr.kernel.security.authorization.actions.management.CreateGroupAction"); 100 _names.put(new Integer (ACTION_CREATE_USER_IN_GROUP), "org.mr.kernel.security.authorization.actions.management.CreateUserInGroupAction"); 101 _names.put(new Integer (ACTION_RENAME_GROUP), "org.mr.kernel.security.authorization.actions.management.RenameGroupAction"); 102 _names.put(new Integer (ACTION_RENAME_USER), "org.mr.kernel.security.authorization.actions.management.RenameUserAction"); 103 _names.put(new Integer (ACTION_SET_GROUP_FOR_USER), "org.mr.kernel.security.authorization.actions.management.SetGroupForUserAction"); 104 _names.put(new Integer (ACTION_SET_PASSWORD_FOR_USER), "org.mr.kernel.security.authorization.actions.management.SetPasswordForUserAction"); 105 _names.put(new Integer (ACTION_CREATE_PERMISSIONS_FOR_GROUP), "org.mr.kernel.security.authorization.actions.management.CreatePermissionForGroupAction"); 106 _names.put(new Integer (ACTION_READ_PERMISSIONS_FOR_GROUP), "org.mr.kernel.security.authorization.actions.management.ReadPermissionForGroupAction"); 107 _names.put(new Integer (ACTION_DELETE_PERMISSIONS_FOR_GROUP), "org.mr.kernel.security.authorization.actions.management.DeletePermissionForGroupAction"); 108 _names.put(new Integer (ACTION_CREATE_PERMISSIONS_FOR_USER), "org.mr.kernel.security.authorization.actions.management.CreatePermissionForUserAction"); 109 _names.put(new Integer (ACTION_READ_PERMISSIONS_FOR_USER), "org.mr.kernel.security.authorization.actions.management.ReadPermissionForUserAction"); 110 _names.put(new Integer (ACTION_DELETE_PERMISSIONS_FOR_USER), "org.mr.kernel.security.authorization.actions.management.DeletePermissionForUserAction"); 111 _names.put(new Integer (ACTION_DELETE_USER), "org.mr.kernel.security.authorization.actions.management.DeleteUserAction"); 112 _names.put(new Integer (ACTION_DELETE_GROUP), "org.mr.kernel.security.authorization.actions.management.DeleteGroupAction"); 113 _names.put(new Integer (ACTION_CREATE_WHITE_LIST_ENTRY), "org.mr.kernel.security.authorization.actions.management.CreateWhiteListEntryAction"); 114 _names.put(new Integer (ACTION_DELETE_WHITE_LIST_ENTRY), "org.mr.kernel.security.authorization.actions.management.DeleteWhiteListEntryAction"); 115 _names.put(new Integer (ACTION_LIST_USERS), "org.mr.kernel.security.authorization.actions.management.ListUsersAction"); 116 _names.put(new Integer (ACTION_LIST_GROUPS), "org.mr.kernel.security.authorization.actions.management.ListGroupsAction"); 117 _names.put(new Integer (ACTION_LIST_WHITE_LIST), "org.mr.kernel.security.authorization.actions.management.ListWhiteListAction"); 118 } 119 120 128 public MantaAction getMantaAction(int actionType) throws MantaSecurityException { 129 String className = (String ) _names.get(new Integer (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 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 150 public Log getLogger(){ 151 if (_logger == null){ 152 _logger = LogFactory.getLog(getClass().getName()); 153 } 154 return _logger; 155 } 156 } 157 | Popular Tags |