Skip to content

Commit

Permalink
Merge pull request #91 from ONLYOFFICE/develop
Browse files Browse the repository at this point in the history
Release/5.0.0
  • Loading branch information
LinneyS authored Jul 12, 2021
2 parents cef7de3 + 4dc2e65 commit ba9f59d
Show file tree
Hide file tree
Showing 57 changed files with 1,039 additions and 503 deletions.
4 changes: 4 additions & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Authors

* Ascensio System SIA: <[email protected]>

13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Change Log

# 5.0.0
## Added
- connection to the demo server
- support alfresco multi tenancy [#83](https://github.com/ONLYOFFICE/onlyoffice-alfresco/issues/83)
- conversion for macro-enabled document and document template
- preview for shared files [#62](https://github.com/ONLYOFFICE/onlyoffice-alfresco/issues/62)
- file conversion setting [#25](https://github.com/ONLYOFFICE/onlyoffice-alfresco/issues/25)

## Changed
- deleting thumbnail generation code
- improving JWT validation
- fixed search on the preview page [#63](https://github.com/ONLYOFFICE/onlyoffice-alfresco/issues/63)

## 4.3.0
## Added
- Opening not OOXML file formats for editing
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,12 @@ Installation process is described [here](https://maven.apache.org/install.html)
git clone https://github.com/onlyoffice/onlyoffice-alfresco.git
```
4. Compile packages in the `repo` and `share` directories:
4. Get a submodule:
```bash
git submodule update --init --recursive
```
5. Compile packages in the `repo` and `share` directories:
```bash
cd onlyoffice-alfresco/
mvn clean install
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.onlyoffice.alfresco</groupId>
<artifactId>onlyoffice-integration</artifactId>
<version>4.3.0</version>
<version>5.0.0</version>
<name>ONLYOFFICE Alfresco Integration</name>
<description>This Module integrates Alfresco Share with ONLYOFFICE</description>
<packaging>pom</packaging>
Expand Down
2 changes: 1 addition & 1 deletion repo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>com.onlyoffice.alfresco</groupId>
<artifactId>onlyoffice-integration</artifactId>
<version>4.3.0</version>
<version>5.0.0</version>
</parent>

<properties>
Expand Down
34 changes: 19 additions & 15 deletions repo/src/main/java/com/parashift/onlyoffice/CallBack.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.alfresco.model.ContentModel;
import org.alfresco.repo.policy.BehaviourFilter;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.repo.tenant.TenantContextHolder;
import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.repository.ContentData;
Expand Down Expand Up @@ -97,8 +98,8 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws
Boolean inBody = true;

if (token == null || token == "") {
String jwth = (String) configManager.getOrDefault("jwtheader", "");
String header = (String) request.getHeader(jwth.isEmpty() ? "Authorization" : jwth);
String jwth = jwtManager.getJwtHeader();
String header = request.getHeader(jwth);
token = (header != null && header.startsWith("Bearer ")) ? header.substring(7) : header;
inBody = false;
}
Expand All @@ -120,17 +121,6 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws
}
}

NodeRef nodeRef = new NodeRef(request.getParameter("nodeRef"));
String hash = null;
if (cociService.isCheckedOut(nodeRef)) {
hash = (String) nodeService.getProperty(cociService.getWorkingCopy(nodeRef), Util.EditingHashAspect);
}
String queryHash = request.getParameter("cb_key");

if (hash == null || queryHash == null || !hash.equals(queryHash)) {
throw new SecurityException("Security hash verification failed");
}

String username = null;

if (callBackJSon.has("users")) {
Expand All @@ -149,10 +139,23 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws

if (username != null) {
AuthenticationUtil.clearCurrentSecurityContext();
TenantContextHolder.setTenantDomain(AuthenticationUtil.getUserTenant(username).getSecond());
AuthenticationUtil.setRunAsUser(username);
} else {
throw new SecurityException("No user information");
}

NodeRef nodeRef = new NodeRef(request.getParameter("nodeRef"));
String hash = null;
if (cociService.isCheckedOut(nodeRef)) {
hash = (String) nodeService.getProperty(cociService.getWorkingCopy(nodeRef), Util.EditingHashAspect);
}
String queryHash = request.getParameter("cb_key");

if (hash == null || queryHash == null || !hash.equals(queryHash)) {
throw new SecurityException("Security hash verification failed");
}

Boolean reqNew = transactionService.isReadOnly();
transactionService.getRetryingTransactionHelper()
.doInTransaction(new ProccessRequestCallback(callBackJSon, nodeRef), reqNew, reqNew);
Expand All @@ -168,7 +171,7 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws

if (error != null) {
response.setStatus(code);
logger.error(ExceptionUtils.getFullStackTrace(error));
logger.error("Error execution script Callback", error);

response.getWriter().write("{\"error\":1, \"message\":\"" + error.getMessage() + "\"}");
} else {
Expand Down Expand Up @@ -231,7 +234,7 @@ public Object execute() throws Throwable {
return null;
}

logger.debug("Forcesave request (type: " + callBackJSon.getString("forcesavetype") + ")");
logger.debug("Forcesave request (type: " + callBackJSon.getInt("forcesavetype") + ")");
updateNode(wc, callBackJSon.getString("url"));

String hash = (String) nodeService.getProperty(wc, Util.EditingHashAspect);
Expand All @@ -244,6 +247,7 @@ public Object execute() throws Throwable {
cociService.checkin(wc, null, null, true);

AuthenticationUtil.clearCurrentSecurityContext();
TenantContextHolder.setTenantDomain(AuthenticationUtil.getUserTenant(lockOwner).getSecond());
AuthenticationUtil.setRunAsUser(lockOwner);

nodeService.setProperty(wc, Util.EditingHashAspect, hash);
Expand Down
3 changes: 3 additions & 0 deletions repo/src/main/java/com/parashift/onlyoffice/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,11 @@ protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, C
model.put("cert", getBoolAsAttribute("cert", "false"));
model.put("forcesave", getBoolAsAttribute("forcesave", "false"));
model.put("webpreview", getBoolAsAttribute("webpreview", "false"));
model.put("convertOriginal", getBoolAsAttribute("convertOriginal", "false"));

model.put("jwtsecret", configManager.getOrDefault("jwtsecret", ""));
model.put("demo", getBoolAsAttribute("demo", "false"));
model.put("demoAvailable", configManager.demoAvailable(true));

model.put("formatODT", getBoolAsAttribute("formatODT", "false"));
model.put("formatODS", getBoolAsAttribute("formatODS", "false"));
Expand Down
35 changes: 20 additions & 15 deletions repo/src/main/java/com/parashift/onlyoffice/ConfigCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
Expand Down Expand Up @@ -59,25 +60,29 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws

logger.debug(data.toString(3));

String docUrl = data.getString("url").trim();
String docInnerUrl = data.getString("innerurl").trim();
String alfUrl = data.getString("alfurl").trim();
String docUrl = AppendSlash(data.getString("url").trim());
String docInnerUrl = AppendSlash(data.getString("innerurl").trim());
String alfUrl = AppendSlash(data.getString("alfurl").trim());
String jwtSecret = data.getString("jwtsecret").trim();

docUrl = AppendSlash(docUrl);
docInnerUrl = AppendSlash(docInnerUrl);
alfUrl = AppendSlash(alfUrl);
configManager.selectDemo(data.getBoolean("demo"));

JSONObject formats = (JSONObject) data.get("formats");
if (configManager.demoActive()) {
docUrl = configManager.getDemo("url");
docInnerUrl = configManager.getDemo("url");
} else {
configManager.set("url", docUrl);
configManager.set("innerurl", docInnerUrl);
configManager.set("jwtsecret", jwtSecret);
}

configManager.set("url", docUrl);
configManager.set("innerurl", docInnerUrl);
configManager.set("alfurl", alfUrl);
configManager.set("cert", data.getString("cert"));
configManager.set("forcesave", data.getString("forcesave"));
configManager.set("webpreview", data.getString("webpreview"));
configManager.set("jwtsecret", jwtSecret);
configManager.set("convertOriginal", data.getString("convertOriginal"));

JSONObject formats = (JSONObject) data.get("formats");
configManager.set("formatODT", formats.getString("odt"));
configManager.set("formatODS", formats.getString("ods"));
configManager.set("formatODP", formats.getString("odp"));
Expand All @@ -92,22 +97,22 @@ public void execute(WebScriptRequest request, WebScriptResponse response) throws
return;
}

String docTestUrl = docInnerUrl.isEmpty() ? docUrl : docInnerUrl;
docInnerUrl = docInnerUrl.isEmpty() ? docUrl : docInnerUrl;
logger.debug("Checking docserv url");
if (!CheckDocServUrl(docTestUrl)) {
if (!CheckDocServUrl(docUrl)) {
response.getWriter().write("{\"success\": false, \"message\": \"docservunreachable\"}");
return;
}

try {
logger.debug("Checking docserv commandservice");
if (!CheckDocServCommandService(docTestUrl)) {
if (!CheckDocServCommandService(docInnerUrl)) {
response.getWriter().write("{\"success\": false, \"message\": \"docservcommand\"}");
return;
}

logger.debug("Checking docserv convert");
if (!CheckDocServConvert(docTestUrl)) {
if (!CheckDocServConvert(docInnerUrl)) {
response.getWriter().write("{\"success\": false, \"message\": \"docservconvert\"}");
return;
}
Expand Down Expand Up @@ -159,7 +164,7 @@ private Boolean CheckDocServCommandService(String url) throws SecurityException
payloadBody.put("payload", body);
String headerToken = jwtManager.createToken(body);
body.put("token", token);
request.setHeader((String) configManager.getOrDefault("jwtheader", "Authorization"), "Bearer " + headerToken);
request.setHeader(jwtManager.getJwtHeader(), "Bearer " + headerToken);
}

StringEntity requestEntity = new StringEntity(body.toString(), ContentType.APPLICATION_JSON);
Expand Down
82 changes: 78 additions & 4 deletions repo/src/main/java/com/parashift/onlyoffice/ConfigManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.Properties;
import java.util.Set;
import java.io.InputStream;
import java.text.ParseException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;

/*
Copyright (c) Ascensio System SIA 2021. All rights reserved.
Expand All @@ -23,6 +25,13 @@ public class ConfigManager {
@Qualifier("global-properties")
Properties globalProp;

private static Map<String, String> demoData = new HashMap<String, String>(){{
put("url", "https://onlinedocs.onlyoffice.com/");
put("header", "AuthorizationJWT");
put("secret", "sn2puSUF7muF5Jas");
put("trial", "30");
}};

public void set(String key, String value) {
attributeService.setAttribute(value == null || value.isEmpty() ? null : value, formKey(key));
}
Expand Down Expand Up @@ -60,7 +69,7 @@ public Boolean getAsBoolean(String key, Object defaultValue) {
return (value != null && ((String)value).equals("true")) ? true : false;
}

public Set<String> getEditableSet() {
public Set<String> getCustomizableEditableSet() {
Set<String> editableSet = new HashSet<>();
if (getAsBoolean("formatODT", "false")){
editableSet.add("application/vnd.oasis.opendocument.text");
Expand Down Expand Up @@ -88,5 +97,70 @@ public Set<String> getEditableSet() {
private String formKey(String key) {
return "onlyoffice." + key;
}

public boolean selectDemo(Boolean demo) {
set("demo", demo.toString());
if (demo) {
String demoStart = (String) getOrDefault("demoStart", null);
if (demoStart == null || demoStart.isEmpty()) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
Date date = new Date();
set("demoStart", dateFormat.format(date));
}
return true;
}
return false;
}

public Boolean demoEnabled() {
return getAsBoolean("demo", "false");
}

public Boolean demoAvailable(Boolean forActivate) {
String demoStart = (String) get("demoStart");
if (demoStart != null && !demoStart.isEmpty()) {
DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
Calendar date = Calendar.getInstance();
date.setTime(dateFormat.parse(demoStart));
date.add(Calendar.DATE, Integer.parseInt(demoData.get("trial")));
if (date.after(Calendar.getInstance())) {
return true;
} else {
return false;
}
} catch (ParseException e) {
return false;
}
}
return forActivate;
}

public Boolean demoActive() {
return demoEnabled() && demoAvailable(false);
}

public String getDemo(String key) {
return demoData.get(key);
}

private Properties getDefaultProperties() {
try {
Properties properties = new Properties();
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("onlyoffice-config.properties");
properties.load(inputStream);
return properties;
} catch (Exception e) {
return null;
}
}

public List<String> getListDefaultProperty(String nameProperty) {
Properties properties = getDefaultProperties();
String property = properties.getProperty(nameProperty);

return Arrays.asList(property.split("\\|"));
}

}

Loading

0 comments on commit ba9f59d

Please sign in to comment.