Commit b5f5272d by Lenovo Committed by zhangyu

添加下载路径限制

parent df85cc9b
...@@ -79,6 +79,7 @@ public class SecurityPropertyPlaceholderConfigurer extends PropertyPlaceholderCo ...@@ -79,6 +79,7 @@ public class SecurityPropertyPlaceholderConfigurer extends PropertyPlaceholderCo
public static void main(String[] args) { public static void main(String[] args) {
System.out.println(DES3Utils.encrypt("foctest", CONF_DESC_KEY)); System.out.println(DES3Utils.encrypt("foctest", CONF_DESC_KEY));
System.out.println(DES3Utils.decrypt("69872b2310ba9b30470ce46682151021e825c3909c394aa5f4387123bdbfa67e", CONF_DESC_KEY)); System.out.println(DES3Utils.decrypt("35824f37e331a42e669a52e248d88ffb6474030c906ec914", CONF_DESC_KEY));
System.out.println(DES3Utils.decrypt("6f2237c231b1464c6474030c906ec914", CONF_DESC_KEY));
} }
} }
...@@ -38,11 +38,10 @@ import java.util.List; ...@@ -38,11 +38,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* @team IT Team
* @author renmb * @author renmb
* @version 1.0 * @version 1.0
* @team IT Team
* @time 2016-03-22 * @time 2016-03-22
*
*/ */
@Controller @Controller
@RequestMapping(value = "/api/upload") @RequestMapping(value = "/api/upload")
...@@ -54,12 +53,12 @@ public class UploadController { ...@@ -54,12 +53,12 @@ public class UploadController {
/** /**
* 使用BASE64上传文件 * 使用BASE64上传文件
* *
* @author renmb
* @time 2016年11月1日
* @param request * @param request
* @param requestBean * @param requestBean
* @return * @return
* @author renmb
* @time 2016年11月1日
*/ */
@ResponseBody @ResponseBody
@RequestMapping("/base64") @RequestMapping("/base64")
...@@ -135,7 +134,7 @@ public class UploadController { ...@@ -135,7 +134,7 @@ public class UploadController {
@ResponseBody @ResponseBody
@RequestMapping("/files") @RequestMapping("/files")
public ResponseBean files(HttpServletRequest request, @RequestParam("file") CommonsMultipartFile[] files, public ResponseBean files(HttpServletRequest request, @RequestParam("file") CommonsMultipartFile[] files,
RequestBean requestBean) { RequestBean requestBean) {
ResponseBean responseBean = new ResponseBean(); ResponseBean responseBean = new ResponseBean();
List<UploadFileBean> uploadFiles = null; List<UploadFileBean> uploadFiles = null;
...@@ -279,12 +278,16 @@ public class UploadController { ...@@ -279,12 +278,16 @@ public class UploadController {
@RequestMapping("download") @RequestMapping("download")
public void download(RequestBean requestBean, HttpServletResponse response, HttpServletRequest request) throws JsonParseException, JsonMappingException, IOException { public void download(RequestBean requestBean, HttpServletResponse response, HttpServletRequest request) throws JsonParseException, JsonMappingException, IOException {
FileBean bean = requestBean.getObjectBean(FileBean.class); FileBean bean = requestBean.getObjectBean(FileBean.class);
// File baseUploadDir = new File(GConstants.FILE_UPLOAD_DIR, filepath); // File baseUploadDir = new File(GConstants.FILE_UPLOAD_DIR, filepath);
InputStream in = null; InputStream in = null;
OutputStream out = null; OutputStream out = null;
try { try {
if (bean.getPath() != null) {
if (bean.getPath().indexOf("../") != -1) {
return;
}
}
// 设置文件MIME类型 // 设置文件MIME类型
response.setContentType("application/form-data;charset=utf-8"); response.setContentType("application/form-data;charset=utf-8");
// String downloadFileName=Encodes.urlEncode(bean.getName()); // String downloadFileName=Encodes.urlEncode(bean.getName());
...@@ -294,16 +297,16 @@ public class UploadController { ...@@ -294,16 +297,16 @@ public class UploadController {
downloadFileName = "=?UTF-8?B?" + (new String(Base64.encodeBase64(bean.getName().getBytes("UTF-8")))) downloadFileName = "=?UTF-8?B?" + (new String(Base64.encodeBase64(bean.getName().getBytes("UTF-8"))))
+ "?="; + "?=";
} /* } /*
* else{ downloadFileName = URLDecoder.decode(bean.getName(), * else{ downloadFileName = URLDecoder.decode(bean.getName(),
* "UTF-8"); } * "UTF-8"); }
*/ */
// 设置Content-Disposition // 设置Content-Disposition
response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\""); response.setHeader("Content-Disposition", "attachment; filename=\"" + downloadFileName + "\"");
// 获取目标文件的绝对路径 // 获取目标文件的绝对路径
// String fullFileName = GConstants.FILE_UPLOAD_DIR + bean.getPath(); // String fullFileName = GConstants.FILE_UPLOAD_DIR + bean.getPath();
File downloadFile = new File(GConstants.FILE_UPLOAD_DIR, bean.getPath()); File downloadFile = new File(GConstants.FILE_UPLOAD_DIR, bean.getPath());
LOG.error("文件下载地址:"+downloadFile.getAbsolutePath()); LOG.error("文件下载地址:" + downloadFile.getAbsolutePath());
System.out.println("文件下载地址:"+downloadFile.getAbsolutePath()); System.out.println("文件下载地址:" + downloadFile.getAbsolutePath());
// 读取文件 // 读取文件
in = new FileInputStream(downloadFile); in = new FileInputStream(downloadFile);
out = response.getOutputStream(); out = response.getOutputStream();
...@@ -323,8 +326,8 @@ public class UploadController { ...@@ -323,8 +326,8 @@ public class UploadController {
IOUtils.closeQuietly(out); IOUtils.closeQuietly(out);
} }
} }
// public static String GetImageStr(String imgFile) // public static String GetImageStr(String imgFile)
// {//将图片文件转化为字节数组字符串,并对其进行Base64编码处理 // {//将图片文件转化为字节数组字符串,并对其进行Base64编码处理
//// String imgFile = "d://test.jpg";//待处理的图片 //// String imgFile = "d://test.jpg";//待处理的图片
// InputStream in = null; // InputStream in = null;
...@@ -400,12 +403,12 @@ public class UploadController { ...@@ -400,12 +403,12 @@ public class UploadController {
@RequestMapping("/verifFile") @RequestMapping("/verifFile")
public ResponseBean verifFile(HttpServletRequest request, RequestBean requestBean) { public ResponseBean verifFile(HttpServletRequest request, RequestBean requestBean) {
ResponseBean responseBean = new ResponseBean(); ResponseBean responseBean = new ResponseBean();
String stream=request.getParameter("fileStream"); String stream = request.getParameter("fileStream");
String filePath=request.getParameter("filePath"); String filePath = request.getParameter("filePath");
String fileDir=request.getParameter("fileDir"); String fileDir = request.getParameter("fileDir");
ByteArrayInputStream bais = null; ByteArrayInputStream bais = null;
FileOutputStream ostream = null; FileOutputStream ostream = null;
try{ try {
byte buf[] = stream.getBytes("utf-8"); byte buf[] = stream.getBytes("utf-8");
bais = new ByteArrayInputStream(buf); bais = new ByteArrayInputStream(buf);
POIFSFileSystem poifs = new POIFSFileSystem(); POIFSFileSystem poifs = new POIFSFileSystem();
...@@ -413,12 +416,11 @@ public class UploadController { ...@@ -413,12 +416,11 @@ public class UploadController {
directory.createDocument("WordDocument", bais); directory.createDocument("WordDocument", bais);
// 文件保存地址 // 文件保存地址
File uploadFilePath = new File(GConstants.FILE_UPLOAD_DIR,filePath); File uploadFilePath = new File(GConstants.FILE_UPLOAD_DIR, filePath);
if(uploadFilePath.exists()) if (uploadFilePath.exists()) {
{
return responseBean; return responseBean;
} }
File baseUploadDir = new File(GConstants.FILE_UPLOAD_DIR,fileDir); File baseUploadDir = new File(GConstants.FILE_UPLOAD_DIR, fileDir);
if (!baseUploadDir.exists()) {// 如果文件夹不存在则创建 if (!baseUploadDir.exists()) {// 如果文件夹不存在则创建
baseUploadDir.mkdirs(); baseUploadDir.mkdirs();
} }
...@@ -434,6 +436,6 @@ public class UploadController { ...@@ -434,6 +436,6 @@ public class UploadController {
responseBean.setStatus(ErrorCode.STATUS_CODE_2000); responseBean.setStatus(ErrorCode.STATUS_CODE_2000);
responseBean.setMessage(GConstants.OK); responseBean.setMessage(GConstants.OK);
return responseBean; return responseBean;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment