Skip to content

Commit 332e2a4

Browse files
committed
OnlyOffice machinery
1 parent 9689594 commit 332e2a4

File tree

16 files changed

+236
-80
lines changed

16 files changed

+236
-80
lines changed

logicaldoc-core/src/main/java/com/logicaldoc/core/security/SessionManager.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,8 @@ public synchronized Session newSession(String apikey, HttpServletRequest request
202202
}
203203

204204
/**
205-
* Creates a new session for the given user and stores it in
206-
* the pool of opened sessions
205+
* Creates a new session for the given user and stores it in the pool of
206+
* opened sessions
207207
*
208208
* @param username the username
209209
* @param key the secret key
@@ -466,7 +466,7 @@ public String getSessionId(HttpServletRequest request) {
466466
if (auth instanceof LDAuthenticationToken ldAuthenticationToken)
467467
return ldAuthenticationToken.getSid();
468468

469-
if (request != null) {
469+
if (request != null && Context.get().getProperties().getBoolean("security.useclientid", true)) {
470470
Client client = buildClient(request);
471471
Session session = getByClientId(client.getId());
472472
if (session != null && isOpen(session.getSid()))
@@ -586,11 +586,11 @@ public Client buildClient(HttpServletRequest request) {
586586
String authorization = request.getHeader("Authorization");
587587
String apiKey = request.getHeader(HEADER_APIKEY);
588588

589-
client.setId(String.format("%s-%s-%s-%s", StringUtils.defaultString(client.getUsername(), "0"),
589+
client.setId(String.format("%s-%s-%s-%s-%s", StringUtils.defaultString(client.getUsername(), "0"),
590590
StringUtils.isNotEmpty(authorization) ? Integer.toString(authorization.hashCode()) : "0",
591-
StringUtils.isNotEmpty(apiKey) ? Integer.toString(apiKey.hashCode()) : "0", request.getRemoteAddr()));
591+
StringUtils.isNotEmpty(apiKey) ? Integer.toString(apiKey.hashCode()) : "0", request.getRemoteAddr(),
592+
StringUtils.defaultString(request.getHeader("user-agent"))));
592593
return client;
593-
594594
}
595595

596596
private static String[] getBasicCredentials(HttpServletRequest req) {

logicaldoc-core/src/main/java/com/logicaldoc/core/store/AbstractStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ public String getResourceName(long docId, String fileVersion, String suffix) {
297297
}
298298

299299
protected String sanitizeResourceName(String resourceName) {
300-
return resourceName.replace("..", "").replace("/", "").replace("\\", "");
300+
return resourceName.replace("..", "").replaceAll("[^a-zA-Z0-9\\-\\\\.]", "");
301301
}
302302

303303
@Override

logicaldoc-core/src/test/java/com/logicaldoc/core/CoreWorkbench.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,14 @@
1010
import java.nio.channels.FileChannel;
1111
import java.nio.charset.StandardCharsets;
1212
import java.nio.file.Files;
13+
import java.text.DateFormat;
14+
import java.text.ParseException;
1315
import java.text.SimpleDateFormat;
1416
import java.util.ArrayList;
1517
import java.util.List;
18+
import java.util.Locale;
1619
import java.util.Map;
1720
import java.util.concurrent.Callable;
18-
import java.util.regex.Matcher;
19-
import java.util.regex.Pattern;
2021

2122
import javax.mail.MessagingException;
2223

@@ -42,12 +43,14 @@ public class CoreWorkbench {
4243
* Test sending e-mail with attachments
4344
*
4445
* @throws IOException
46+
* @throws ParseException
4547
*/
46-
public static void main(String[] args) throws IOException {
47-
String expression = "1.0-conversion-pdf";
48-
System.out.println(expression.replace("..", "").replace("/", "").replace("\\", "") );
49-
50-
48+
public static void main(String[] args) throws IOException, ParseException {
49+
50+
SimpleDateFormat df = new SimpleDateFormat("MMM dd , yyyy", Locale.ENGLISH);
51+
52+
System.out.println(df.parse("April 3 , 2020"));
53+
5154

5255
// OperatingSystemMXBean osBean = ManagementFactory.getPlatformMXBean(OperatingSystemMXBean.class);
5356
// // What % CPU load this current JVM is taking, from 0.0-1.0

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/Feature.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,8 @@ public class Feature {
220220
public static final int CHATGPT = 104;
221221

222222
public static final int GOOGLE_CALENDAR = 105;
223+
224+
public static final int ONLYOFFICE = 107;
223225

224226
private static Set<String> features = new HashSet<>();
225227

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/Menu.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public class Menu {
147147

148148
public static final long SHAREFILE = -2075;
149149

150-
public static final long GDOCS = -2080;
150+
public static final long GOOGLEDRIVE = -2080;
151151

152152
public static final long WEBCONTENT = -2100;
153153

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/beans/GUISecuritySettings.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ public class GUISecuritySettings implements Serializable {
4545
private boolean forceSsl = false;
4646

4747
private boolean allowSidInRequest = false;
48+
49+
private boolean allowClientId = true;
4850

4951
private boolean alertNewDevice = true;
5052

@@ -264,4 +266,12 @@ public String getCookiesSameSite() {
264266
public void setCookiesSameSite(String cookiesSameSite) {
265267
this.cookiesSameSite = cookiesSameSite;
266268
}
269+
270+
public boolean isAllowClientId() {
271+
return allowClientId;
272+
}
273+
274+
public void setAllowClientId(boolean allowClientId) {
275+
this.allowClientId = allowClientId;
276+
}
267277
}

logicaldoc-gui/src/main/java/com/logicaldoc/gui/common/client/widgets/preview/PreviewTile.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ private void initGUI() {
4646
HTMLFlow thumbnailImage = new HTMLFlow(html);
4747
thumbnailImage.addClickHandler(event -> {
4848
if (Session.get().isShowThumbnail()) {
49-
ImageLightbox lightbox = new ImageLightbox(docId, title);
50-
lightbox.show();
49+
new ImageLightbox(docId, title).show();
5150
}
5251
});
5352

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/menu/MainMenu.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,6 @@ private MenuItem getOfficeMenuItem(GUIFolder folder, final GUIDocument document)
556556
}
557557

558558
private MenuItem getOnlyOfficeMenuItem(GUIFolder folder, final GUIDocument document) {
559-
560559
Menu menu = new Menu();
561560
menu.setShowShadow(true);
562561
menu.setShadowDepth(3);
@@ -574,7 +573,7 @@ private MenuItem getOnlyOfficeMenuItem(GUIFolder folder, final GUIDocument docum
574573

575574
// This should be enabled only on PDF
576575
final MenuItem fillForms = new MenuItem("Fill in PDF forms");
577-
fillForms.addClickHandler(event -> {
576+
fillForms.addClickHandler(click -> {
578577
if (document == null)
579578
return;
580579

@@ -586,7 +585,6 @@ private MenuItem getOnlyOfficeMenuItem(GUIFolder folder, final GUIDocument docum
586585

587586
menu.setItems(edit, create, fillForms);
588587

589-
// TODO limit the editing only on supported file types
590588
edit.setEnabled(document != null && document.getImmutable() == 0 && folder != null && folder.isDownload()
591589
&& folder.isWrite());
592590

@@ -596,7 +594,7 @@ private MenuItem getOnlyOfficeMenuItem(GUIFolder folder, final GUIDocument docum
596594
fillForms.setEnabled(document != null && document.getImmutable() == 0 && folder != null && folder.isDownload()
597595
&& folder.isWrite() && (document.getType().toLowerCase().endsWith("pdf")));
598596

599-
MenuItem onlyOfficeItem = new MenuItem("OnlyOffice");
597+
MenuItem onlyOfficeItem = new MenuItem(I18N.message("onlyoffice"));
600598
onlyOfficeItem.setSubmenu(menu);
601599

602600
return onlyOfficeItem;
@@ -637,8 +635,11 @@ private void addItemsWhenFolderOrDocumentSelected(GUIFolder folder, GUIDocument
637635
&& com.logicaldoc.gui.common.client.Menu.enabled(com.logicaldoc.gui.common.client.Menu.SHAREFILE))
638636
menu.addItem(getShareFileMenuItem(folder));
639637
if (Feature.enabled(Feature.GOOGLE_DRIVE)
640-
&& com.logicaldoc.gui.common.client.Menu.enabled(com.logicaldoc.gui.common.client.Menu.GDOCS))
638+
&& com.logicaldoc.gui.common.client.Menu.enabled(com.logicaldoc.gui.common.client.Menu.GOOGLEDRIVE))
641639
menu.addItem(new DriveMenuItem(folder, document));
640+
if (Feature.enabled(Feature.ONLYOFFICE)
641+
&& com.logicaldoc.gui.common.client.Menu.enabled(com.logicaldoc.gui.common.client.Menu.ONLYOFFICE))
642+
menu.addItem(getOnlyOfficeMenuItem(folder, document));
642643
if (Feature.enabled(Feature.ZOHO)
643644
&& com.logicaldoc.gui.common.client.Menu.enabled(com.logicaldoc.gui.common.client.Menu.ZOHO))
644645
menu.addItem(new ZohoMenuItem(folder, document));
@@ -658,8 +659,6 @@ private void addTextAndWebContentItems(Menu menu, GUIDocument document, GUIFolde
658659
menu.addItem(getWebContentMenuItem(folder, document));
659660
if (com.logicaldoc.gui.common.client.Menu.enabled(com.logicaldoc.gui.common.client.Menu.TEXTCONTENT))
660661
menu.addItem(getTextContentMenuItem(folder, document));
661-
// if (com.logicaldoc.gui.common.client.Menu.enabled(com.logicaldoc.gui.common.client.Menu.ONLYOFFICE))
662-
// menu.addItem(getOnlyOfficeMenuItem(folder, document));
663662
}
664663

665664
private void addChatGPTItem(Menu menu) {

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/metadata/zonalocr/ZonalOCRTemplatesPanel.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,13 @@ private void refresh(Long templateId, Long ocrTemplateId) {
7575

7676
addSettingsButton(toolBar);
7777

78-
addDeleteButton(toolBar);
79-
8078
addSaveButton(toolBar);
8179

82-
toolBar.addSeparator();
83-
8480
addAddZoneButton(toolBar);
8581

8682
addDeleteZonesButton(toolBar);
83+
84+
addDeleteButton(toolBar);
8785

8886
toolBar.addSeparator();
8987

Lines changed: 64 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package com.logicaldoc.gui.frontend.client.onlyoffice;
22

33
import java.io.UnsupportedEncodingException;
4+
import java.util.Date;
45

56
import com.google.gwt.http.client.URL;
7+
import com.google.gwt.user.client.rpc.AsyncCallback;
68
import com.logicaldoc.gui.common.client.Session;
79
import com.logicaldoc.gui.common.client.beans.GUIDocument;
810
import com.logicaldoc.gui.common.client.i18n.I18N;
11+
import com.logicaldoc.gui.common.client.log.GuiLog;
912
import com.logicaldoc.gui.common.client.util.Util;
1013
import com.smartgwt.client.types.HeaderControls;
1114
import com.smartgwt.client.widgets.HTMLFlow;
@@ -16,7 +19,7 @@
1619
* This popup window is used to open the document in OnlyOffice editor.
1720
*
1821
* @author Alessandro Gasparini - LogicalDOC
19-
* @since 9.0
22+
* @since 9.0.1
2023
*/
2124
public class OnlyOfficeEditor extends Window {
2225

@@ -27,7 +30,7 @@ public class OnlyOfficeEditor extends Window {
2730
private GUIDocument document;
2831

2932
public OnlyOfficeEditor(final GUIDocument document) {
30-
33+
3134
setHeaderControls(HeaderControls.HEADER_LABEL, HeaderControls.CLOSE_BUTTON);
3235
if (document.getId() > 0)
3336
setTitle(I18N.message("editdoc") + ": " + document.getFileName());
@@ -44,32 +47,66 @@ public OnlyOfficeEditor(final GUIDocument document) {
4447
centerInPage();
4548
setMargin(2);
4649

47-
addCloseClickHandler(event -> destroy());
50+
addCloseClickHandler(event -> onClose());
4851

49-
addResizedHandler(event -> {
50-
reloadBody();
51-
});
52+
addResizedHandler(event -> reloadBody());
5253

5354
layout = new VLayout();
5455
layout.setMargin(1);
5556
layout.setWidth100();
5657
layout.setHeight100();
5758
addItem(layout);
5859

59-
reloadBody();
60+
if ("fillForms".equals(document.getComment())) {
61+
// the document is not being edited just used to produce another PDF
62+
reloadBody();
63+
} else {
64+
// the document is being edited, so declare the editing
65+
OnlyOfficeService.Instance.get().startEditing(document.getId(), new AsyncCallback<Void>() {
66+
67+
@Override
68+
public void onFailure(Throwable caught) {
69+
GuiLog.serverError(caught);
70+
}
71+
72+
@Override
73+
public void onSuccess(Void result) {
74+
reloadBody();
75+
}
76+
});
77+
}
78+
}
79+
80+
private void onClose() {
81+
if ("fillForms".equals(document.getComment())) {
82+
// the document is not being edited just used to produce another PDF
83+
destroy();
84+
} else {
85+
// the document is being edited, so declare the end of editing
86+
OnlyOfficeService.Instance.get().endEditing(document.getId(), new AsyncCallback<Void>() {
87+
88+
@Override
89+
public void onFailure(Throwable caught) {
90+
GuiLog.serverError(caught);
91+
}
92+
93+
@Override
94+
public void onSuccess(Void result) {
95+
destroy();
96+
}
97+
});
98+
}
6099
}
61100

62101
/**
63102
* Reloads a preview.
64-
* @throws UnsupportedEncodingException
103+
*
104+
* @throws UnsupportedEncodingException
65105
*/
66106
private void reloadBody() {
67-
68-
String url = getOnlyOfficeEditorUrl();
107+
String iframe = "<iframe src='" + getOnlyOfficeEditorUrl() + "' style='border: 0px solid white; width:"
108+
+ (getWidth() - 18) + "px; height:" + (getHeight() - 68) + "px' scrolling='no'></iframe>";
69109

70-
String iframe = "<iframe src='" + url + "' style='border: 0px solid white; width:" + (getWidth() - 18)
71-
+ "px; height:" + (getHeight() - 68) + "px' scrolling='no'></iframe>";
72-
73110
html = new HTMLFlow();
74111
html.setWidth100();
75112
html.setHeight100();
@@ -78,27 +115,27 @@ private void reloadBody() {
78115

79116
layout.setMembers(html);
80117
}
81-
118+
82119
private String getOnlyOfficeEditorUrl() {
83-
84120
String finalUrl;
85-
121+
86122
if (document.getId() > 0) {
87-
finalUrl = Util.contextPath() + "onlyoffice/editor?docId=" + document.getId()
88-
+ "&fileName=" + URL.encode(document.getFileName()) + "&sid=" + Session.get().getSid();
89-
123+
finalUrl = Util.contextPath() + "onlyoffice/editor?docId=" + document.getId() + "&fileName="
124+
+ URL.encode(document.getFileName());
125+
90126
// fillforms mode
91127
if ((document.getComment() != null) && document.getComment().equals("fillForms")) {
92-
finalUrl = Util.contextPath() + "onlyoffice/editor?docId=" + document.getId()
93-
+ "&fileName=" + URL.encode(document.getFileName())
94-
+ "&mode=fillForms"
95-
+ "&sid=" + Session.get().getSid();
128+
finalUrl = Util.contextPath() + "onlyoffice/editor?docId=" + document.getId() + "&fileName="
129+
+ URL.encode(document.getFileName()) + "&mode=fillForms";
96130
}
97131
} else {
98-
finalUrl = Util.contextPath() + "onlyoffice/editor?docId=" + document.getId()
99-
+ "&fileName=" + URL.encode(document.getFileName()) + "&fileExt=" +document.getType() +"&folderId=" +document.getFolder().getId() + "&sid=" + Session.get().getSid();
132+
finalUrl = Util.contextPath() + "onlyoffice/editor?docId=" + document.getId() + "&fileName="
133+
+ URL.encode(document.getFileName()) + "&fileExt=" + document.getType() + "&folderId="
134+
+ document.getFolder().getId();
100135
}
101-
136+
137+
finalUrl += "&sid=" + Session.get().getSid() + "&rd=" + new Date().getTime();
138+
102139
return finalUrl;
103-
}
140+
}
104141
}

0 commit comments

Comments
 (0)