/** * Move an IP restriction up in priority by swapping the priority with the restriction above the * one selected. * * @param mapping mapping * @param form form * @param request request * @param response response * @return ActionForward forward * @throws Exception on any error */ public ActionForward moveUp( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { PolicyUtil.checkPermission( PolicyConstants.IP_RESTRICTIONS_RESOURCE_TYPE, PolicyConstants.PERM_EDIT, request); int id = Integer.parseInt(request.getParameter("id")); SystemDatabase database = SystemDatabaseFactory.getInstance(); IpRestriction restriction1 = database.getIpRestriction(id); String ipAddress = restriction1.getAddress(); String ipPermission = restriction1.getAllowed() ? "Allowed" : "Denied"; try { List<IpRestriction> restrictions = Arrays.asList(database.getIpRestrictions()); database.swapIpRestrictions( restriction1, restrictions.get(restrictions.indexOf(restriction1) - 1)); fireCoreEvent( request, CoreEventConstants.IP_RESTRICTION_MOVE_UP, ipAddress, ipPermission, CoreEvent.STATE_SUCCESSFUL); } catch (Exception e) { fireCoreEvent( request, CoreEventConstants.IP_RESTRICTION_MOVE_UP, ipAddress, ipPermission, CoreEvent.STATE_UNSUCCESSFUL); throw e; } return mapping.findForward("refresh"); }
private void deleteIpRestriction(HttpServletRequest request, IpRestriction restriction) throws Exception { String ipAddress = restriction.getAddress(); String ipPermission = restriction.getAllowed() ? "Allowed" : "Denied"; try { SystemDatabase database = SystemDatabaseFactory.getInstance(); database.removeIpRestriction(restriction.getID()); fireCoreEvent( request, CoreEventConstants.DELETE_IP_RESTRICTION, ipAddress, ipPermission, CoreEvent.STATE_SUCCESSFUL); } catch (Exception e) { fireCoreEvent( request, CoreEventConstants.DELETE_IP_RESTRICTION, ipAddress, ipPermission, CoreEvent.STATE_UNSUCCESSFUL); throw e; } }
private static IpRestriction findIpRestriction(IpRestriction[] restrictions, int id) { for (IpRestriction restriction : restrictions) { if (restriction.getID() == id) return restriction; } return null; }