KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > table > TableItemActionMenuTree


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.table;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import com.sslexplorer.core.AvailableMenuItem;
25 import com.sslexplorer.core.MenuItem;
26 import com.sslexplorer.extensions.itemactions.DisableExtensionAction;
27 import com.sslexplorer.extensions.itemactions.EnableExtensionAction;
28 import com.sslexplorer.extensions.itemactions.ExtensionInformationAction;
29 import com.sslexplorer.extensions.itemactions.InstallExtensionAction;
30 import com.sslexplorer.extensions.itemactions.RemoveExtensionAction;
31 import com.sslexplorer.extensions.itemactions.StartExtensionAction;
32 import com.sslexplorer.extensions.itemactions.StopExtensionAction;
33 import com.sslexplorer.extensions.itemactions.UpdateExtensionAction;
34 import com.sslexplorer.navigation.MenuTree;
35 import com.sslexplorer.navigation.itemactions.RemoveFavoriteAction;
36 import com.sslexplorer.policyframework.Permission;
37 import com.sslexplorer.policyframework.PolicyConstants;
38 import com.sslexplorer.policyframework.ResourceType;
39 import com.sslexplorer.policyframework.itemactions.CloneResourceAction;
40 import com.sslexplorer.policyframework.itemactions.EditResourceAction;
41 import com.sslexplorer.policyframework.itemactions.RemovePolicyAction;
42 import com.sslexplorer.policyframework.itemactions.RemoveResourceAction;
43 import com.sslexplorer.properties.itemactions.RemoveProfileAction;
44 import com.sslexplorer.properties.itemactions.ViewProfileAction;
45 import com.sslexplorer.security.LogonController;
46 import com.sslexplorer.security.SessionInfo;
47 import com.sslexplorer.security.UserItem;
48 import com.sslexplorer.security.itemactions.DisableAuthenticationSchemeAction;
49 import com.sslexplorer.security.itemactions.EditAccountTableAction;
50 import com.sslexplorer.security.itemactions.EnableAuthenticationSchemeAction;
51 import com.sslexplorer.security.itemactions.MoveAuthenticationSchemeDownAction;
52 import com.sslexplorer.security.itemactions.MoveAuthenticationSchemeUpAction;
53
54 /**
55  * Extension of {@link com.sslexplorer.navigation.MenuTree} used for the main
56  * menu navigation (i.e. the bar on the left in the default UI).
57  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
58  */

59 public class TableItemActionMenuTree extends MenuTree {
60     /**
61      * Menu tree name
62      */

63     public static final String JavaDoc MENU_TABLE_ITEM_ACTION_MENU_TREE = "tableItemAction";
64
65     /**
66      * Constructor.
67      */

68     public TableItemActionMenuTree() {
69         super(TableItemActionMenuTree.MENU_TABLE_ITEM_ACTION_MENU_TREE);
70         addFavorites();
71         addProfiles();
72         addPersonalProfiles();
73         addExtensions();
74         addAccessRights();
75         addUsers();
76         addAuthenticationSchemes();
77         addPolicies();
78     }
79     
80     private void addFavorites() {
81         addMenuItem(null, new MenuItem("favorites", "navigation", null, 100, false, SessionInfo.USER_CONSOLE_CONTEXT));
82         addMenuItem("favorites", new RemoveFavoriteAction());
83     }
84
85     private void addProfiles() {
86         addMenuItem(null, new MenuItem("profiles", "policyframework", null, 100, false, SessionInfo.ALL_CONTEXTS));
87         addMenuItem("profiles", new ViewProfileAction());
88         addMenuItem("profiles", new RemoveProfileAction());
89         addMenuItem("profiles", new EditResourceAction(SessionInfo.ALL_CONTEXTS, "properties"));
90         addMenuItem("profiles", new CloneResourceAction(SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, "properties"));
91     }
92
93     private void addPersonalProfiles() {
94         addMenuItem(null, new MenuItem("personalProfiles", "policyframework", null, 100, false, SessionInfo.ALL_CONTEXTS));
95         addMenuItem("personalProfiles", new ViewProfileAction());
96         addMenuItem("personalProfiles", new RemoveProfileAction());
97         addMenuItem("personalProfiles", new EditResourceAction(SessionInfo.USER_CONSOLE_CONTEXT, "properties"));
98         addMenuItem("personalProfiles", new CloneResourceAction(SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, "properties"));
99     }
100
101     private void addAuthenticationSchemes() {
102         addMenuItem(null, new MenuItem("authenticationSchemes", "security", null, 100, false, SessionInfo.ALL_CONTEXTS));
103         addMenuItem("authenticationSchemes", new RemoveResourceAction(SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, "security"));
104         addMenuItem("authenticationSchemes", new EditResourceAction(SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, "security"));
105         addMenuItem("authenticationSchemes", new EnableAuthenticationSchemeAction());
106         addMenuItem("authenticationSchemes", new DisableAuthenticationSchemeAction());
107         addMenuItem("authenticationSchemes", new MoveAuthenticationSchemeUpAction());
108         addMenuItem("authenticationSchemes", new MoveAuthenticationSchemeDownAction());
109     }
110
111     private void addPolicies() {
112         addMenuItem(null, new MenuItem("policies", "security", null, 100, false, SessionInfo.ALL_CONTEXTS));
113         addMenuItem("policies", new RemovePolicyAction(SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, "policyframework"));
114         addMenuItem("policies", new EditResourceAction(SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, "policyframework"));
115     }
116
117     private void addExtensions() {
118         addMenuItem(null, new MenuItem("extensionStore", "extensions", null, 100, false, SessionInfo.ALL_CONTEXTS));
119         addMenuItem("extensionStore", new InstallExtensionAction());
120         addMenuItem("extensionStore", new UpdateExtensionAction());
121         addMenuItem("extensionStore", new RemoveExtensionAction());
122         addMenuItem("extensionStore", new ExtensionInformationAction());
123         addMenuItem("extensionStore", new EnableExtensionAction());
124         addMenuItem("extensionStore", new DisableExtensionAction());
125         addMenuItem("extensionStore", new StartExtensionAction());
126         addMenuItem("extensionStore", new StopExtensionAction());
127     }
128
129     private void addUsers() {
130         addMenuItem(null, new MenuItem("accounts", null, null, 100, false, SessionInfo.ALL_CONTEXTS));
131         addMenuItem("accounts", getEditAccountAction());
132         addMenuItem("accounts", getDeleteAccountAction());
133         addMenuItem("accounts", getSetPasswordAction());
134         addMenuItem("accounts", getEnableAccountAction());
135         addMenuItem("accounts", getDisableAccountAction());
136         addMenuItem("accounts", getResetPrivateKey());
137         addMenuItem("accounts", getSendUserMessage());
138     }
139     private void addAccessRights() {
140         addMenuItem(null, new MenuItem("accessRights", "policyframework", null, 100, false, SessionInfo.ALL_CONTEXTS));
141         addMenuItem("accessRights", new EditResourceAction(SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, "policyframework"));
142         addMenuItem("accessRights", new RemoveResourceAction(SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, "policyframework"));
143     }
144     
145     private static TableItemAction getEditAccountAction() {
146         return new EditAccountTableAction("edit", 100, true, "/editAccount.do?actionTarget=edit&username={0}");
147     }
148     
149     private static TableItemAction getDeleteAccountAction() {
150         return new EditAccountTableAction("remove", 150, true, "/showAvailableAccounts.do?actionTarget=confirmAccountDeletion&username={0}", false, true) {
151             @Override JavaDoc
152             public Permission[] getPermissions(ResourceType resourceType) {
153                 return new Permission[] { resourceType.getPermission(PolicyConstants.PERM_DELETE_ID) };
154             }
155         };
156     }
157     
158     private static TableItemAction getSetPasswordAction() {
159         return new EditAccountTableAction("setPassword", 210, false, "/showAvailableAccounts.do?actionTarget=password&username={0}", true, false);
160     }
161
162     private static TableItemAction getEnableAccountAction() {
163         return new EditAccountTableAction("enable", 200, false, "/showAvailableAccounts.do?actionTarget=enable&username={0}") {
164             @Override JavaDoc
165             public boolean isEnabled(UserItem userItem) throws Exception JavaDoc {
166                 return LogonController.ACCOUNT_LOCKED == userItem.getStatus() || (LogonController.ACCOUNT_LOCKED != userItem.getStatus() && !userItem.getEnabled());
167             }
168         };
169     }
170
171     private static TableItemAction getDisableAccountAction() {
172         return new EditAccountTableAction("disable", 200, false, "/showAvailableAccounts.do?actionTarget=disable&username={0}") {
173             @Override JavaDoc
174             public boolean isEnabled(UserItem userItem) throws Exception JavaDoc {
175                 return LogonController.ACCOUNT_LOCKED != userItem.getStatus() && userItem.getEnabled();
176             }
177         };
178     }
179     
180     private static TableItemAction getResetPrivateKey() {
181         return new EditAccountTableAction("resetPrivateKey", 240, false, "/showAvailableAccounts.do?actionTarget=confirmResetPrivateKey&username={0}") {
182             @Override JavaDoc
183             public Permission[] getPermissions(ResourceType resourceType) {
184                 return new Permission[] {};
185             }
186         };
187     }
188     
189     private static TableItemAction getSendUserMessage() {
190         return new EditAccountTableAction("sendUserMessage", 290, false, "/showAvailableAccounts.do?actionTarget=sendMessage&username={0}") {
191             @Override JavaDoc
192             public Permission[] getPermissions(ResourceType resourceType) {
193                 return new Permission[] {};
194             }
195         };
196     }
197     
198     /*
199      * (non-Javadoc)
200      * @see com.sslexplorer.navigation.MenuTree#createAvailableMenuItem(com.sslexplorer.core.MenuItem, com.sslexplorer.core.AvailableMenuItem, javax.servlet.http.HttpServletRequest, java.lang.String, int, com.sslexplorer.security.SessionInfo)
201      */

202     public AvailableMenuItem createAvailableMenuItem(MenuItem item, AvailableMenuItem parent, HttpServletRequest JavaDoc request, String JavaDoc referer, int checkNavigationContext, SessionInfo info) {
203         return new AvailableTableItemAction(item, parent, request, referer, checkNavigationContext, info);
204     }
205 }
Popular Tags