1 19 20 package com.sslexplorer.navigation.forms; 21 22 import java.util.Iterator ; 23 import java.util.List ; 24 25 import javax.servlet.http.HttpServletRequest ; 26 import javax.servlet.http.HttpServletResponse ; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 import com.sslexplorer.core.CoreUtil; 32 import com.sslexplorer.navigation.AbstractFavoriteItem; 33 import com.sslexplorer.navigation.Favorite; 34 import com.sslexplorer.navigation.FavoriteResourceType; 35 import com.sslexplorer.navigation.WrappedFavoriteItem; 36 import com.sslexplorer.policyframework.NoPermissionException; 37 import com.sslexplorer.policyframework.PolicyDatabaseFactory; 38 import com.sslexplorer.policyframework.ResourceType; 39 import com.sslexplorer.policyframework.ResourceUtil; 40 import com.sslexplorer.security.Constants; 41 import com.sslexplorer.security.LogonControllerFactory; 42 import com.sslexplorer.security.SessionInfo; 43 import com.sslexplorer.security.SystemDatabaseFactory; 44 import com.sslexplorer.security.User; 45 import com.sslexplorer.table.AbstractTableItemTableModel; 46 import com.sslexplorer.table.forms.AbstractPagerForm; 47 import com.sslexplorer.util.TicketGenerator; 48 49 56 public class FavoritesForm extends AbstractPagerForm { 57 58 final static Log log = LogFactory.getLog(FavoritesForm.class); 59 60 private String selectedView; 61 62 65 public FavoritesForm() { 66 super(new FavoritesModel()); 67 } 68 69 75 public void initialize(HttpServletRequest request, String defaultSortColumnId) { 76 super.initialize(request.getSession(), defaultSortColumnId); 77 SessionInfo info = LogonControllerFactory.getInstance().getSessionInfo(request); 78 getModel().clear(); 79 try { 80 User user = LogonControllerFactory.getInstance().getUser(request); 81 for (Iterator i = PolicyDatabaseFactory.getInstance().getResourceTypes(null).iterator(); i.hasNext();) { 82 ResourceType rt = (ResourceType) i.next(); 83 if (rt instanceof FavoriteResourceType) { 84 FavoriteResourceType frt = (FavoriteResourceType) rt; 85 try { 86 List fl = SystemDatabaseFactory.getInstance().getFavorites(frt.getResourceTypeId(), user); 87 for (Iterator j = fl.iterator(); j.hasNext();) { 88 Favorite f = (Favorite) j.next(); 89 try { 90 WrappedFavoriteItem wfi = frt.createWrappedFavoriteItem(f.getFavoriteKey(), request, 91 AbstractFavoriteItem.USER_FAVORITE); 92 if (wfi == null) { 93 SystemDatabaseFactory.getInstance().removeFavorite(f.getType(), f.getFavoriteKey(), 94 f.getUsername()); 95 } 96 try { 97 ResourceUtil.checkResourceAccessRights(wfi.getFavoriteItem().getResource(), info); 98 getModel().addItem(wfi); 99 } catch (NoPermissionException npe) { 100 } 102 } catch (Exception e) { 103 log.error("Failed to add user favorite " + f.getFavoriteKey() + ".", e); 104 } 105 } 106 } catch (Exception e) { 107 log.error("Failed to create user favorites for resource type " + frt.getResourceTypeId()); 108 } 109 try { 110 for (Iterator iter = ResourceUtil.filterResourceIdsForGlobalFavorites( 111 PolicyDatabaseFactory.getInstance().getGrantedResourcesOfType(user, frt), rt).iterator(); iter 112 .hasNext();) { 113 Integer element = (Integer ) iter.next(); 114 try { 115 WrappedFavoriteItem wfi = frt.createWrappedFavoriteItem(element.intValue(), request, 116 AbstractFavoriteItem.GLOBAL_FAVORITE); 117 if (wfi == null) { 118 } else { 121 if (!getModel().contains(wfi)) { 122 try { 123 ResourceUtil.checkResourceAccessRights(wfi.getFavoriteItem().getResource(), info); 124 getModel().addItem(wfi); 125 } catch (NoPermissionException npe) { 126 } 128 } 129 } 130 } catch (Exception e) { 131 log.error("Failed to add policy favorite for resource " + element.intValue() + ".", e); 132 } 133 } 134 } catch (Exception e) { 135 log.error("Failed to create policy favorites for resource type " + frt.getResourceTypeId()); 136 } 137 138 } 139 } 140 } catch (Exception e) { 141 log.error("Failed to create favorite items.", e); 142 } 143 checkSort(); 144 getPager().rebuild(getFilterText()); 145 149 if (request.getSession().getAttribute(Constants.WEB_FOLDER_LAUNCH_TICKET) == null) { 150 request.getSession().setAttribute(Constants.WEB_FOLDER_LAUNCH_TICKET, 151 TicketGenerator.getInstance().generateUniqueTicket("W", 6)); 152 } 153 154 } 155 156 162 public void checkSelectedView(HttpServletRequest request, HttpServletResponse response) { 163 SessionInfo sessionInfo = (SessionInfo) request.getSession().getAttribute(Constants.SESSION_INFO); 164 String defaultView = CoreUtil.getUsersProfileProperty(request.getSession(), "ui.defaultUserConsoleViewType", sessionInfo 165 .getUser()); 166 selectedView = CoreUtil.getCookieValue("ui_view_" + getModel().getId() + "_" 167 + ((SessionInfo) request.getSession().getAttribute(Constants.SESSION_INFO)).getNavigationContext(), 168 request, defaultView); 169 } 170 171 179 public String getSelectedView() { 180 return selectedView; 181 } 182 183 191 public void setSelectedView(String selectedView) { 192 this.selectedView = selectedView; 193 } 194 195 197 static class FavoritesModel extends AbstractTableItemTableModel { 198 199 public int getColumnWidth(int col) { 200 return 0; 201 } 202 203 public String getId() { 204 return "favorites"; 205 } 206 207 public int getColumnCount() { 208 return 1; 209 } 210 211 public String getColumnName(int col) { 212 return "name"; 213 } 214 215 public Class getColumnClass(int col) { 216 return String .class; 217 } 218 219 } 220 221 } | Popular Tags |