1 19 20 package com.sslexplorer.navigation; 21 22 import static com.sslexplorer.navigation.NavigationBar.log; 23 24 import javax.servlet.http.HttpServletRequest ; 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 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 request) { 59 boolean available = super.isAvailable(checkNavigationContext, info, request); 60 if (available) { 61 try { 62 available = PolicyUtil.canLogin(info.getUser()); 63 } catch (Exception 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 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 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 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 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 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 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 |