📄 showshutdowndispatchaction.java
字号:
/*
*/
package com.sslexplorer.setup.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.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.UserAccountForm;
import com.sslexplorer.setup.forms.ShutdownForm;
/**
* Action to shut the server down.
*/
public class ShowShutdownDispatchAction extends AuthenticatedDispatchAction {
final static Log log = LogFactory.getLog(ShowShutdownDispatchAction.class);
/**
* @param requiresAdministrator
*/
public ShowShutdownDispatchAction() {
super(PolicyConstants.SERVICE_CONTROL_RESOURCE_TYPE, new Permission[] { PolicyConstants.PERM_SHUTDOWN,
PolicyConstants.PERM_RESTART });
}
public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ShutdownForm shutdownForm = (ShutdownForm) form;
/*
* Hack to prevent getting in a loop if sending and message then
* cancelling
*/
String referer = CoreUtil.getReferer(request);
if (referer.indexOf("/sendMessage.do") == -1) {
shutdownForm.setReferer(referer);
}
int users = CoreServlet.getServlet().getLogonController().getActiveSessions().size();
if (users > 1) {
ActionMessages msgs = new ActionMessages();
msgs.add(Globals.MESSAGE_KEY, new ActionMessage("shutdown.userWarning", new Integer(users)));
saveMessages(request, msgs);
}
if (shutdownForm.getAlreadyPerforming()) {
return new ActionForward("/cancelShutdown.do");
} else {
return mapping.findForward("display");
}
}
public ActionForward shutdown(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
ShutdownForm shutdownForm = (ShutdownForm) form;
shutdownForm.setReferer(CoreUtil.getReferer(request));
if (shutdownForm.getShutdownType().equals(ShutdownForm.SHUTDOWN)) {
PolicyUtil.checkPermission(PolicyConstants.SERVICE_CONTROL_RESOURCE_TYPE, PolicyConstants.PERM_SHUTDOWN, request);
return mapping.findForward("shutdown");
} else {
PolicyUtil.checkPermission(PolicyConstants.SERVICE_CONTROL_RESOURCE_TYPE, PolicyConstants.PERM_RESTART, request);
return mapping.findForward("restart");
}
}
public int getNavigationContext(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
return SessionInfo.MANAGEMENT_CONSOLE_CONTEXT | SessionInfo.SETUP_CONSOLE_CONTEXT;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -