📄 showiprestrictiondispatchaction.java
字号:
/*
* SSL-Explorer
*
* Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package com.sslexplorer.security.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;
import com.sslexplorer.boot.Util;
import com.sslexplorer.core.CoreAttributeConstants;
import com.sslexplorer.core.CoreEvent;
import com.sslexplorer.core.CoreEventConstants;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.CoreUtil;
import com.sslexplorer.core.actions.AuthenticatedDispatchAction;
import com.sslexplorer.policyframework.Permission;
import com.sslexplorer.policyframework.PolicyConstants;
import com.sslexplorer.policyframework.PolicyUtil;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.security.forms.IpRestrictionForm;
/**
* Implementation of a {@link com.sslexplorer.core.actions.AuthenticatedDispatchAction}
* that allows an administrator to create an <i>IP Restrictions</i>.
*
* @author P.J.King <a href="mailto:peter@3sp.com"><peter@3sp.com></a>
*
*/
public class ShowIpRestrictionDispatchAction extends AuthenticatedDispatchAction {
/**
* Constructor.
*/
public ShowIpRestrictionDispatchAction() {
super(PolicyConstants.IP_RESTRICTIONS_RESOURCE_TYPE, new Permission[] { PolicyConstants.PERM_CREATE,
PolicyConstants.PERM_DELETE });
}
public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
return mapping.findForward("display");
}
/**
* This will setup the IP Restriction Form.
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward create(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
PolicyUtil.checkPermission(PolicyConstants.IP_RESTRICTIONS_RESOURCE_TYPE, PolicyConstants.PERM_CREATE, request);
((IpRestrictionForm) form).initialize();
((IpRestrictionForm) form).setReferer(CoreUtil.getReferer(request));
CoreUtil.addRequiredFieldMessage(this, request);
return mapping.findForward("display");
}
/**
* This will attempt to write the IP Restriction to the database.
*
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
* @throws Exception
*/
public ActionForward commit(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
// Test if access is allowed
PolicyUtil.checkPermission(PolicyConstants.ROLES_RESOURCE_TYPE, PolicyConstants.PERM_CREATE, request);
String restriction = Util.decodeRequestString(request, request.getParameter("ipAddress").trim());
// Declare local variables
boolean type = "allow".equals(request.getParameter("type"));
ActionMessages mesgs = new ActionMessages();
// Make call to write to database
try {
CoreServlet.getServlet().getSystemDatabase().addIpRestriction(restriction, type);
mesgs.add(Globals.MESSAGE_KEY, new ActionMessage("availableRoles.roleCreated", restriction));
saveMessages(request, mesgs);
} catch (Exception ex) {
throw ex;
}
return cancel(mapping, form, request, response);
}
/* (non-Javadoc)
* @see com.sslexplorer.core.actions.CoreAction#getNavigationContext(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -