KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > core > CoreMenuTree


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.core;
21
22 import javax.servlet.http.HttpServletRequest JavaDoc;
23
24 import com.sslexplorer.navigation.MenuTree;
25 import com.sslexplorer.policyframework.Permission;
26 import com.sslexplorer.policyframework.PolicyConstants;
27 import com.sslexplorer.policyframework.PolicyUtil;
28 import com.sslexplorer.security.LogonControllerFactory;
29 import com.sslexplorer.security.SessionInfo;
30
31
32 /**
33  * Extension of {@link com.sslexplorer.navigation.MenuTree} used for the main
34  * menu navigation (i.e. the bar on the left in the default UI).
35  *
36  * @author Brett Smith <a HREF="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
37  */

38 public class CoreMenuTree extends MenuTree {
39     /**
40      * Menu tree name
41      */

42     public static final String JavaDoc MENU_ITEM_MENU_TREE = "menuItem";
43
44     /**
45      * Constructor. *
46      */

47     public CoreMenuTree() {
48         super(CoreMenuTree.MENU_ITEM_MENU_TREE);
49
50         // Menu Bar
51

52         addMenuItem(null, new MenuItem("myAccount", "navigation", null, 100, false, SessionInfo.USER_CONSOLE_CONTEXT));
53         addMenuItem(null, new MenuItem("resources", "navigation", null, 200, false, SessionInfo.USER_CONSOLE_CONTEXT));
54
55         // My Account Menu
56

57         addMenuItem("myAccount", new MenuItem("favorites", "navigation", "/showFavorites.do", 100, true, null,
58             SessionInfo.USER_CONSOLE_CONTEXT, PolicyConstants.FAVORITES_RESOURCE_TYPE, new Permission[] {
59                 PolicyConstants.PERM_USE
60             }, null));
61
62         addMenuItem("myAccount", new ShowChangePasswordMenuItem());
63
64         addMenuItem("myAccount", new MenuItem("userAttributes",
65                 "navigation", "/userAttributes.do", 500, true, null,
66                 SessionInfo.USER_CONSOLE_CONTEXT,
67                 PolicyConstants.PERSONAL_DETAILS_RESOURCE_TYPE,
68                 new Permission[] { PolicyConstants.PERM_CHANGE }, null));
69         
70         // Resources menu
71

72         addMenuItem("resources", new MenuItem("userProfiles", "navigation", "/showUserProfiles.do", 100, true, null,
73             SessionInfo.USER_CONSOLE_CONTEXT, PolicyConstants.PERSONAL_PROFILE_RESOURCE_TYPE, new Permission[] {
74                 PolicyConstants.PERM_MAINTAIN
75             }, PolicyConstants.PROFILE_RESOURCE_TYPE));
76
77         // Administration
78

79         addMenuItem(null, new MenuItem("configuration", "navigation", null, 100, false, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT));
80         addMenuItem(null, new MenuItem("accessControl", "navigation", null, 200, false, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT));
81         addMenuItem(null, new MenuItem("globalResources", "navigation", null, 300, false, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT));
82         addMenuItem(null, new MenuItem("system", "navigation", null, 300, false, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT));
83         
84         
85         // System menu
86
addMenuItem("system", new MenuItem("status", "navigation", "/status.do", 100, true, null,
87             SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.STATUS_TYPE_RESOURCE_TYPE, new Permission[] {
88                 PolicyConstants.PERM_VIEW
89             }, null));
90         addMenuItem("system", new MenuItem("messageQueue", "navigation", "/messageQueue.do", 200, true, null,
91             SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.MESSAGE_QUEUE_RESOURCE_TYPE, new Permission[] {
92                             PolicyConstants.PERM_VIEW, PolicyConstants.PERM_CONTROL, PolicyConstants.PERM_CLEAR,
93                             PolicyConstants.PERM_SEND
94             }, null));
95         addMenuItem("system", new MenuItem("shutdown", "navigation", "/showShutdown.do", 300, true, null,
96             SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.SERVICE_CONTROL_RESOURCE_TYPE, new Permission[] {
97                             PolicyConstants.PERM_SHUTDOWN, PolicyConstants.PERM_RESTART
98             }, null));
99
100         // Configuration
101

102         addMenuItem("configuration", new MenuItem("systemConfiguration", "navigation", "/showSystemConfiguration.do", 100,
103             true, null, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.SYSTEM_CONFIGURATION_RESOURCE_TYPE,
104             new Permission[] {
105                 PolicyConstants.PERM_CHANGE
106             }, null));
107
108         addMenuItem("configuration", new MenuItem("extensionStore", "navigation", "/showExtensionStore.do?actionTarget=list", 200,
109              true, null, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.EXTENSIONS_RESOURCE_TYPE,
110             new Permission[] {PolicyConstants.PERM_CHANGE}, null));
111
112         addMenuItem("configuration", new MenuItem("keyStore", "navigation", "/showKeyStore.do", 300, true, null,
113                 SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.KEYSTORE_RESOURCE_TYPE, new Permission[] {
114                     PolicyConstants.PERM_CHANGE
115                 }, null));
116         
117         addMenuItem("configuration", new MenuItem("attributeDefinitions", "navigation", "/showAttributeDefinitions.do", 700,
118             true, null, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.ATTRIBUTE_DEFINITIONS_RESOURCE_TYPE,
119             new Permission[] {
120                 PolicyConstants.PERM_MAINTAIN
121             }, null));
122
123         // Access Control
124

125         addMenuItem("accessControl", new MenuItem("authorizedPrincipals", "navigation", "/showAvailableAccounts.do", 100,
126             true, null, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE,
127             new Permission[] {
128                             PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_DELETE
129             }, null));
130
131         addMenuItem("accessControl", new MenuItem("availableRoles", "navigation", "/showAvailableRoles.do", 200, true, null,
132             SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.ACCOUNTS_AND_GROUPS_RESOURCE_TYPE, new Permission[] {
133                             PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_DELETE
134             }, null));
135         addMenuItem("accessControl", new MenuItem("policies", "navigation", "/policies.do", 300, true, null,
136             SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.POLICY_RESOURCE_TYPE, new Permission[] {
137                             PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_EDIT_AND_ASSIGN, PolicyConstants.PERM_DELETE, PolicyConstants.PERM_ASSIGN
138                             
139             }, null));
140         
141         addMenuItem("accessControl", new AccessRightsListMenuItem());
142         
143         addMenuItem("accessControl", new MenuItem("authenticationSchemes", "navigation", "/showAuthenticationSchemes.do", 500,
144                 true, null, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.AUTHENTICATION_SCHEMES_RESOURCE_TYPE,
145                new Permission[] {
146                                PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_EDIT_AND_ASSIGN, PolicyConstants.PERM_DELETE,
147                                PolicyConstants.PERM_ASSIGN
148                }, null));
149         
150         addMenuItem("accessControl", new MenuItem("ipRestrictions", "navigation", "/showAvailableIpRestrictions.do", 600, true, null,
151             SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.IP_RESTRICTIONS_RESOURCE_TYPE, new Permission[] {
152                             PolicyConstants.PERM_CREATE, PolicyConstants.PERM_DELETE
153             }, null));
154
155         // Global Resources
156
addMenuItem("globalResources", new MenuItem("globalProfiles", "navigation", "/showGlobalProfiles.do", 500, true,
157                 null, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.PROFILE_RESOURCE_TYPE, new Permission[] {
158                                 PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_EDIT_AND_ASSIGN,
159                                 PolicyConstants.PERM_DELETE, PolicyConstants.PERM_ASSIGN
160                 }));
161         
162         // Help
163

164         addMenuItem(null, new MenuItem("help", "navigation", null, 100, false, SessionInfo.HELP_CONTEXT));
165
166         addMenuItem("help", new MenuItem("about", "navigation", "/showAbout.do", 200, true, SessionInfo.HELP_CONTEXT));
167
168         addMenuItem("help", new MenuItem("referenceGuidePDF", "navigation", "http://3sp.com/products/ssl-explorer/documentation/SSL-Explorer_Administrators_Guide.pdf", 300, true, "_blank", SessionInfo.HELP_CONTEXT));
169         
170         addMenuItem("help", new MenuItem("referenceGuideHTML", "navigation", "http://3sp.com/products/ssl-explorer/documentation/html/w2wfrm.htm", 300, true, "_blank", SessionInfo.HELP_CONTEXT));
171         
172         // Documentation
173
addMenuItem("help", new MenuItem("knowledgeBase", "navigation", "http://3sp.com/kb", 400, true, "_blank",
174             SessionInfo.HELP_CONTEXT));
175
176         addMenuItem("help", new MenuItem("support", "navigation", "http://3sp.com/showSslExplorer.do", 500, true, "_blank", SessionInfo.HELP_CONTEXT));
177         
178         
179         addMenuItem("help", new MenuItem("forums", "navigation", "http://3sp.com/forums", 600, true, "_blank",
180                 SessionInfo.HELP_CONTEXT));
181
182
183         addMenuItem("help", new MenuItem("communityWiki", "navigation", "http://3sp.com/", 700, true, "_blank",SessionInfo.HELP_CONTEXT));
184     }
185     
186     class ShowChangePasswordMenuItem extends MenuItem {
187         ShowChangePasswordMenuItem() {
188             super("changePassword", "navigation", "/showChangePassword.do", 300, true, null,
189             SessionInfo.USER_CONSOLE_CONTEXT, PolicyConstants.PASSWORD_RESOURCE_TYPE, new Permission[] {
190                 PolicyConstants.PERM_CHANGE
191             }, null);
192         }
193          
194         public boolean isAvailable(int checkNavigationContext, SessionInfo info, HttpServletRequest JavaDoc request) {
195             boolean available = super.isAvailable(checkNavigationContext, info, request);
196             if(available) {
197                 try {
198                     available = UserDatabaseManager.getInstance().getUserDatabase(info.getUser().getRealm()).supportsPasswordChange();
199                 } catch (Exception JavaDoc e) {
200                     log.error("Failed to initialise database.", e);
201                 }
202             }
203             return available;
204         }
205         
206     }
207     
208     class AccessRightsListMenuItem extends MenuItem {
209         AccessRightsListMenuItem() {
210             super("accessRightsList", "navigation", "/accessRightsList.do", 400, true,
211                 null, SessionInfo.MANAGEMENT_CONSOLE_CONTEXT, PolicyConstants.ACCESS_RIGHTS_RESOURCE_TYPE, new Permission[] {
212                                 PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN, PolicyConstants.PERM_EDIT_AND_ASSIGN,
213                                 PolicyConstants.PERM_DELETE, PolicyConstants.PERM_ASSIGN
214                 });
215         }
216          
217         public boolean isAvailable(int checkNavigationContext, SessionInfo info, HttpServletRequest JavaDoc request) {
218             boolean available = super.isAvailable(checkNavigationContext, info, request);
219             if (available) {
220                 if (LogonControllerFactory.getInstance().isAdministrator(info.getUser())) {
221                     available = true;
222                 } else {
223                     try {
224                         PolicyUtil.checkPermissions(PolicyConstants.ACCESS_RIGHTS_RESOURCE_TYPE, new Permission[] {
225                                 PolicyConstants.PERM_CREATE_EDIT_AND_ASSIGN,
226                                 PolicyConstants.PERM_EDIT_AND_ASSIGN,
227                                 PolicyConstants.PERM_DELETE,
228                                 PolicyConstants.PERM_ASSIGN }, request);
229         available = true;
230                     } catch (Exception JavaDoc e1) {
231                         available = false;
232                     }
233                 }
234             }
235             return available;
236         }
237         
238     }
239 }
240
Popular Tags