KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > navigation > NavigationBar


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.navigation;
21
22 import static com.sslexplorer.navigation.NavigationBar.log;
23
24 import javax.servlet.http.HttpServletRequest JavaDoc;
25
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import com.sslexplorer.agent.DefaultAgentManager;
30 import com.sslexplorer.core.CoreUtil;
31 import com.sslexplorer.core.MenuItem;
32 import com.sslexplorer.policyframework.Permission;
33 import com.sslexplorer.policyframework.PolicyConstants;
34 import com.sslexplorer.policyframework.PolicyDatabaseFactory;
35 import com.sslexplorer.policyframework.PolicyUtil;
36 import com.sslexplorer.policyframework.ResourceStack;
37 import com.sslexplorer.policyframework.ResourceType;
38 import com.sslexplorer.security.SessionInfo;
39
40 public class NavigationBar extends MenuTree {
41
42     public static final String JavaDoc NAV_BAR_MENU_TREE = "navBar";
43
44     final static Log log = LogFactory.getLog(NavigationBar.class);
45
46     public NavigationBar() {
47         super(NAV_BAR_MENU_TREE);
48         addMenuItem(null, new LaunchAgentMenuItem());
49         addMenuItem(null, new ShutdownAgentMenuItem());
50         addMenuItem(null, new MenuItem("home",
51                         "navigation",
52                         "/showHome.do",
53                         200,
54                         true,
55                         "_self",
56                         SessionInfo.USER_CONSOLE_CONTEXT | SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
57
58             public boolean isAvailable(int checkNavigationContext, SessionInfo info, HttpServletRequest JavaDoc request) {
59                 boolean available = super.isAvailable(checkNavigationContext, info, request);
60                 if (available) {
61                     try {
62                         available = PolicyUtil.canLogin(info.getUser());
63                     } catch (Exception JavaDoc e) {
64                         log.error("Failed to determine delegation rights.", e);
65                         available = false;
66                     }
67                 }
68                 return available;
69             }
70
71         });
72         addMenuItem(null, new MenuItem("togglePanelOptions",
73                         "navigation",
74                         "javascript: frameToggle('component_panelOptions');",
75                         0,
76                         true,
77                         "_self",
78                         0));
79
80         addMenuItem(null, new MenuItem("managementConsole",
81                         "navigation",
82                         "/managementConsole.do",
83                         300,
84                         true,
85                         "_self",
86                         SessionInfo.USER_CONSOLE_CONTEXT) {
87
88             public boolean isAvailable(int checkNavigationContext, SessionInfo info, HttpServletRequest JavaDoc request) {
89                 boolean available = super.isAvailable(checkNavigationContext, info, request);
90                 if (available) {
91                     try {
92                         available = PolicyDatabaseFactory.getInstance().isAnyAccessRightAllowed(info.getUser(), true, true, false) && CoreUtil.isMenuAvailable(request);
93                     } catch (Exception JavaDoc e) {
94                         log.error("Failed to determine delegation rights.", e);
95                         available = false;
96                     }
97                 }
98                 return available;
99             }
100
101         });
102         addMenuItem(null, new MenuItem("userConsole",
103                         "navigation",
104                         "/userConsole.do",
105                         300,
106                         true,
107                         "_self",
108                         SessionInfo.MANAGEMENT_CONSOLE_CONTEXT) {
109
110             public boolean isAvailable(int checkNavigationContext, SessionInfo info, HttpServletRequest JavaDoc request) {
111                 boolean available = super.isAvailable(checkNavigationContext, info, request);
112                 if (available) {
113                     try {
114                         available = PolicyDatabaseFactory.getInstance().isAnyAccessRightAllowed(info.getUser(), true, true, false) && CoreUtil.isMenuAvailable(request);
115                     } catch (Exception JavaDoc e) {
116                         log.error("Failed to determine delegation rights.", e);
117                         available = false;
118                     }
119                 }
120                 return available;
121             }
122
123         });
124         addMenuItem(null,
125             new MenuItem("help",
126                             "navigation",
127                             "javascript: this.blur(); windowRef = window.open('/help.do?source=help','help_win','left=20,top=20,width=480,height=640,toolbar=0,resizable=1,menubar=0,scrollbars=1'); windowRef.focus()",
128                             400,
129                             true,
130                             "_self",
131                             SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.USER_CONSOLE_CONTEXT
132                                 | SessionInfo.SETUP_CONSOLE_CONTEXT));
133         addMenuItem(null, new MenuItem("logoff",
134                         "navigation",
135                         "/logoff.do",
136                         500,
137                         true,
138                         "_self",
139                         SessionInfo.USER_CONSOLE_CONTEXT | SessionInfo.MANAGEMENT_CONSOLE_CONTEXT));
140     }
141
142     class LaunchAgentMenuItem extends MenuItem {
143         LaunchAgentMenuItem() {
144             super("launchAgent",
145                             "navigation",
146                             "/launchAgent.do",
147                             100,
148                             true,
149                             null,
150                             SessionInfo.USER_CONSOLE_CONTEXT | SessionInfo.MANAGEMENT_CONSOLE_CONTEXT,
151                             PolicyConstants.AGENT_RESOURCE_TYPE,
152                             new Permission[] { PolicyConstants.PERM_USE },
153                             (ResourceType) null);
154         }
155
156         public boolean isAvailable(int checkNavigationContext, SessionInfo info, HttpServletRequest JavaDoc request) {
157             boolean available = super.isAvailable(checkNavigationContext, info, request);
158             if (available) {
159                 available = !CoreUtil.isInWizard(request.getSession()) && !DefaultAgentManager.getInstance()
160                                 .hasActiveAgent(request)
161                     && CoreUtil.isMenuAvailable(request);
162             }
163             return available;
164         }
165     }
166
167     class ShutdownAgentMenuItem extends MenuItem {
168         ShutdownAgentMenuItem() {
169             super("shutdownAgent",
170                             "navigation",
171                             "/shutdownAgent.do",
172                             100,
173                             true,
174                             null,
175                             SessionInfo.USER_CONSOLE_CONTEXT | SessionInfo.MANAGEMENT_CONSOLE_CONTEXT,
176                             PolicyConstants.AGENT_RESOURCE_TYPE,
177                             new Permission[] { PolicyConstants.PERM_USE },
178                             null);
179         }
180
181         public boolean isAvailable(int checkNavigationContext, SessionInfo info, HttpServletRequest JavaDoc request) {
182             boolean available = super.isAvailable(checkNavigationContext, info, request);
183             if (available) {
184                 available = !CoreUtil.isInWizard(request.getSession()) && DefaultAgentManager.getInstance().hasActiveAgent(request)
185                     && CoreUtil.isMenuAvailable(request);
186             }
187             return available;
188         }
189     }
190 }
191
Popular Tags