1 19 20 package com.sslexplorer.navigation.actions; 21 22 import javax.servlet.http.HttpServletRequest ; 23 import javax.servlet.http.HttpServletResponse ; 24 25 import org.apache.struts.action.ActionForm; 26 import org.apache.struts.action.ActionForward; 27 import org.apache.struts.action.ActionMapping; 28 29 import com.sslexplorer.boot.Util; 30 import com.sslexplorer.core.CoreUtil; 31 import com.sslexplorer.navigation.FavoriteResourceType; 32 import com.sslexplorer.navigation.forms.FavoritesForm; 33 import com.sslexplorer.policyframework.Permission; 34 import com.sslexplorer.policyframework.PolicyConstants; 35 import com.sslexplorer.policyframework.PolicyDatabaseFactory; 36 import com.sslexplorer.policyframework.Resource; 37 import com.sslexplorer.policyframework.ResourceType; 38 import com.sslexplorer.policyframework.ResourceUtil; 39 import com.sslexplorer.policyframework.forms.AbstractResourcesForm; 40 import com.sslexplorer.security.Constants; 41 import com.sslexplorer.security.SessionInfo; 42 import com.sslexplorer.security.SystemDatabaseFactory; 43 import com.sslexplorer.table.actions.AbstractPagerAction; 44 45 52 public class ShowFavoritesAction extends AbstractPagerAction { 53 54 57 public ShowFavoritesAction() { 58 super(PolicyConstants.FAVORITES_RESOURCE_TYPE, new Permission[] { 59 PolicyConstants.PERM_USE 60 }); 61 } 62 63 73 public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, 74 HttpServletResponse response) throws Exception { 75 Util.noCache(response); 76 ((FavoritesForm) form).initialize(request, "name"); 77 ((FavoritesForm) form).checkSelectedView(request, response); 78 return mapping.findForward("display"); 79 } 80 81 91 public ActionForward confirmRemove(ActionMapping mapping, ActionForm form, HttpServletRequest request, 92 HttpServletResponse response) throws Exception { 93 return mapping.findForward("confirmRemove"); 94 } 95 96 106 public ActionForward remove(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 107 throws Exception { 108 String id = ((FavoritesForm) form).getSelectedItem(); 109 int idx = id.indexOf('_'); 110 int type = Integer.parseInt(id.substring(0, idx)); 111 int key = Integer.parseInt(id.substring(idx + 1)); 112 ResourceType ty = PolicyDatabaseFactory.getInstance().getResourceType(type); 113 if(ty != null && ty instanceof FavoriteResourceType) { 114 FavoriteResourceType frt = (FavoriteResourceType)ty; 115 Resource r = frt.getResourceById(key); 116 if(ResourceUtil.isResourceGlobalFavorite(r)) { 117 throw new Exception ("Cannot remove policy favorites here."); 118 } 119 else { 120 ResourceUtil.checkResourceAccessRights(r, getSessionInfo(request)); 121 } 122 SystemDatabaseFactory.getInstance().removeFavorite(type, key, getSessionInfo(request).getUser().getPrincipalName()); 123 } 124 return mapping.findForward("refresh"); 125 } 126 127 137 public ActionForward information(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 138 throws Exception { 139 String id = ((FavoritesForm) form).getSelectedItem(); 140 int idx = id.indexOf('_'); 141 int type = Integer.parseInt(id.substring(0, idx)); 142 int key = Integer.parseInt(id.substring(idx + 1)); 143 ResourceType ty = PolicyDatabaseFactory.getInstance().getResourceType(type); 144 if(ty != null && ty instanceof FavoriteResourceType) { 145 FavoriteResourceType frt = (FavoriteResourceType)ty; 146 Resource r = frt.getResourceById(key); 147 request.setAttribute(Constants.REQ_ATTR_INFO_RESOURCE, r); 148 } 149 return mapping.findForward("resourceInformation"); 150 } 151 152 163 public ActionForward viewIcons(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 164 throws Exception { 165 ((FavoritesForm) form).setSelectedView(AbstractResourcesForm.ICONS_VIEW); 166 CoreUtil.storeUIState("ui_view_favorites_" + getSessionInfo(request).getNavigationContext(), AbstractResourcesForm.ICONS_VIEW, request, response); 167 return mapping.findForward("display"); 168 } 169 170 181 public ActionForward viewList(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 182 throws Exception { 183 ((FavoritesForm) form).setSelectedView(AbstractResourcesForm.LIST_VIEW); 184 CoreUtil.storeUIState("ui_view_favorites" + getSessionInfo(request).getNavigationContext(), AbstractResourcesForm.LIST_VIEW, request, response); 185 return mapping.findForward("display"); 186 } 187 188 196 public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) { 197 return SessionInfo.USER_CONSOLE_CONTEXT; 198 } 199 } 200 | Popular Tags |