Compare commits

...

10 Commits

9 changed files with 58 additions and 19 deletions

View File

@ -1,9 +0,0 @@
FROM ubuntu:16.04
RUN apt-get update && apt-get install -y software-properties-common \
python-software-properties
RUN add-apt-repository -y ppa:webupd8team/java
RUN echo "oracle-java8-installer shared/accepted-oracle-license-v1-1 select true" | debconf-set-selections
RUN apt-get update && apt-get install -y oracle-java8-installer \
maven
COPY . /java
CMD mvn -f /java package

View File

@ -55,7 +55,6 @@ files.docservice.url.preloader=https://documentserver/web-apps/apps/api/document
Run next command in java example directory:
```
docker build . -t java-example
docker run -it -v $PWD/target:/java/target java-example
docker-compose up
```
After it, all bin files will be passed to `./target` folder

View File

@ -0,0 +1,7 @@
version: '3'
services:
build:
image: maven:3.6
volumes:
- .:/java
command: mvn -f /java package

View File

@ -27,6 +27,7 @@
package controllers;
import helpers.ConfigManager;
import helpers.DocumentManager;
import helpers.ServiceConverter;
import java.io.File;
@ -35,6 +36,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.util.LinkedHashMap;
import java.util.Scanner;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
@ -54,6 +56,8 @@ import org.primeframework.jwt.domain.JWT;
@MultipartConfig
public class IndexServlet extends HttpServlet
{
private static final String DocumentJwtHeader = ConfigManager.GetProperty("files.docservice.header");
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String action = request.getParameter("type");
@ -255,6 +259,11 @@ public class IndexServlet extends HttpServlet
{
String token = (String) jsonObj.get("token");
if (token == null) {
String header = (String) request.getHeader(DocumentJwtHeader == "" ? "Authorization" : DocumentJwtHeader);
token = header.startsWith("Bearer ") ? header.substring(7) : header;
}
JWT jwt = DocumentManager.ReadToken(token);
if (jwt == null)
{
@ -262,6 +271,19 @@ public class IndexServlet extends HttpServlet
return;
}
if (jwt.getObject("payload") != null) {
try {
@SuppressWarnings("unchecked") LinkedHashMap<String, Object> payload =
(LinkedHashMap<String, Object>)jwt.getObject("payload");
jwt.claims = payload;
}
catch (Exception ex) {
writer.write("Wrong payload");
return;
}
}
status = jwt.getInteger("status");
downloadUri = jwt.getString("url");
}

View File

@ -49,6 +49,7 @@ public class ServiceConverter
{
private static int ConvertTimeout = 120000;
private static final String DocumentConverterUrl = ConfigManager.GetProperty("files.docservice.url.converter");
private static final String DocumentJwtHeader = ConfigManager.GetProperty("files.docservice.header");
public static class ConvertBody
{
@ -96,6 +97,26 @@ public class ServiceConverter
if (isAsync)
body.async = true;
String headerToken = "";
if (DocumentManager.TokenEnabled())
{
HashMap<String, Object> map = new HashMap<String, Object>();
map.put("url", body.url);
map.put("outputtype", body.outputtype);
map.put("filetype", body.filetype);
map.put("title", body.title);
map.put("key", body.key);
if (isAsync)
map.put("async", body.async);
String token = DocumentManager.CreateToken(map);
body.token = token;
Map<String, Object> payloadMap = new HashMap<String, Object>();
payloadMap.put("payload", map);
headerToken = DocumentManager.CreateToken(payloadMap);
}
Gson gson = new Gson();
String bodyString = gson.toJson(body);
@ -112,10 +133,7 @@ public class ServiceConverter
if (DocumentManager.TokenEnabled())
{
Map<String, Object> map = new HashMap<>();
map.put("payload", body);
String token = DocumentManager.CreateToken(map);
connection.setRequestProperty("Authorization", "Bearer " + token);
connection.setRequestProperty(DocumentJwtHeader == "" ? "Authorization" : DocumentJwtHeader, "Bearer " + headerToken);
}
connection.connect();

View File

@ -11,3 +11,4 @@ files.docservice.url.tempstorage=https://documentserver/ResourceService.ashx
files.docservice.url.api=https://documentserver/web-apps/apps/api/documents/api.js
files.docservice.url.preloader=https://documentserver/web-apps/apps/api/documents/cache-scripts.html
files.docservice.secret=
files.docservice.header=Authorization

View File

@ -71,7 +71,7 @@
};
var сonnectEditor = function () {
var config = <%= FileModel.Serialize(Model) %>;
var config = JSON.parse('<%= FileModel.Serialize(Model) %>');
config.width = "100%";
config.height = "100%";
config.events = {

View File

@ -132,7 +132,7 @@ app.get("/download", function(req, res) {
res.setHeader("Content-Length", fileSystem.statSync(path).size);
res.setHeader("Content-Type", mime.lookup(path));
res.setHeader("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
res.setHeader("Content-Disposition", "attachment; filename*=UTF-8\'\'" + encodeURIComponent(fileName));
var filestream = fileSystem.createReadStream(path);
filestream.pipe(res);

View File

@ -93,13 +93,14 @@ documentService.getConvertedUri = function (documentUri, fromExtension, toExtens
};
documentService.generateRevisionId = function (expectedKey) {
if (expectedKey.length > 20) {
let maxKeyLength = 128;
if (expectedKey.length > maxKeyLength) {
expectedKey = expectedKey.hashCode().toString();
}
var key = expectedKey.replace(new RegExp("[^0-9-.a-zA-Z_=]", "g"), "_");
return key.substring(0, Math.min(key.length, 20));
return key.substring(0, Math.min(key.length, maxKeyLength));
};
documentService.processConvertServiceResponceError = function (errorCode) {