📄 getapplicationfileaction.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.extensions.actions;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
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.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.sslexplorer.boot.ContextHolder;
import com.sslexplorer.boot.KeyStoreManager;
import com.sslexplorer.boot.Util;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.actions.XMLOutputAction;
import com.sslexplorer.extensions.ExtensionDescriptor;
import com.sslexplorer.extensions.store.ExtensionStore;
import com.sslexplorer.security.Constants;
import com.sslexplorer.security.SessionInfo;
import com.sslexplorer.security.VPNSession;
public class GetApplicationFileAction extends XMLOutputAction {
final static Log log = LogFactory.getLog(GetApplicationFileAction.class);
public GetApplicationFileAction() {
}
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setAttribute(Constants.REQ_ATTR_COMPRESS, Boolean.FALSE);
String application = request.getParameter("name");
String file = request.getParameter("file").replace('\\', '/');
String ticket = request.getParameter("ticket");
if(file.equalsIgnoreCase("sslexplorer.cert")) {
processApplicationCertRequest(application, ticket, response);
} else {
processApplicationFileRequest(application,
file,
ticket,
response);
}
return null;
}
protected void processApplicationCertRequest(String application,
String ticket,
HttpServletResponse response)
throws Exception {
byte[] cert = KeyStoreManager.getInstance(KeyStoreManager.DEFAULT_KEY_STORE).getCertificate(ContextHolder.getContext().getContextProperty("webServer.alias")).getEncoded();
/**
* If the ticket is a pending VPN session ticket (Agent) then process
*/
if (!CoreServlet.getServlet().getLogonController().verifyPendingVPNAuthorization(ticket) && !application.equals("VPN Client")) {
VPNSession session = CoreServlet.getServlet().getLogonController().getVPNSessionByTicket(ticket);
if (session == null) {
SessionInfo info = CoreServlet.getServlet().getLogonController().getAuthorizationTicket(ticket);
if(info==null) {
sendError("Invalid ticket", response);
return;
}
}
}
sendFile(new ByteArrayInputStream(cert), cert.length, response);
}
protected void processApplicationFileRequest(String application, String file, String ticket, HttpServletResponse response)
throws Exception {
/**
* If the ticket is a pending VPN session ticket (Agent) then process
*/
if (!CoreServlet.getServlet().getLogonController().verifyPendingVPNAuthorization(ticket) && !application.equals("VPN Client")) {
VPNSession session = CoreServlet.getServlet().getLogonController().getVPNSessionByTicket(ticket);
if (session == null) {
SessionInfo info = CoreServlet.getServlet().getLogonController().getAuthorizationTicket(ticket);
if(info==null) {
sendError("Invalid ticket", response);
return;
}
}
}
ExtensionDescriptor app = ExtensionStore.getInstance().getExtensionDescriptor(application);
if(app==null)
app = ExtensionStore.getInstance().getAgentApplication();
if (!app.containsFile(file)) {
log.error("SSL-Explorer Agent requested a file that does not exist (" + file + ").");
sendError(file + " not found", response);
} else {
sendFile(app.getFile(file), response);
}
}
private void sendFile(File file, HttpServletResponse response) throws
IOException {
sendFile(new FileInputStream(file), file.length(), response);
}
private void sendFile(InputStream in, long length, HttpServletResponse response) throws IOException {
Util.noCache(response);
response.setHeader("Content-type", "application/octet-stream");
response.setContentLength((int)length);
try {
Util.copy(in, response.getOutputStream());
}
catch (IOException ex) {
}
finally {
Util.closeStream(in);
Util.closeStream(response.getOutputStream());
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -