diff --git a/imixs-adapters-wopi/README.md b/imixs-adapters-wopi/README.md index 45684c1..306c6c3 100644 --- a/imixs-adapters-wopi/README.md +++ b/imixs-adapters-wopi/README.md @@ -43,7 +43,7 @@ To setup the Imixs-WOPI Adapter the following environment variables must be set: | WOPI_PUBLIC_ENDPOINT | Public client endpoint to be called by the web appliacation. This endpoint should be SSL encrypted |https://libreoffice.foo.com/loleaflet/6a844e4/loleaflet.html? | WOPI_HOST_ENDPOINT | Internal Wopi Host endpoint is called by the Wopi Client to fetch and store file data. This endpoint should not be public accessible | http://my-app:8080/api/wopi/ | WOPI_DISCOVERY_ENDPOINT | Optional public discovery endpoint used by the Wopi Host implementation to resolve the public wopi endpoint dynamically. This variable should only be set if no WOPI_PUBLIC_ENDPOINT was defined! | http://localhost:9980/hosting/discovery - +| WOPI_FILE_EXTENSIONS | Optional comma separated list of file extensions to be supported. |.odt,.doc,.docx,.docm,.rtf,.ods,.xls,.xlsx,.odp,.ppt,.pptx,.odg,.dxf,.emf,.wmf,.vsd,.vsdx| The following example shows a setup for in a Docker Compose file running in a local dev environment: diff --git a/imixs-adapters-wopi/src/main/java/org/imixs/workflow/wopi/WopiController.java b/imixs-adapters-wopi/src/main/java/org/imixs/workflow/wopi/WopiController.java index afddbd3..76a230f 100644 --- a/imixs-adapters-wopi/src/main/java/org/imixs/workflow/wopi/WopiController.java +++ b/imixs-adapters-wopi/src/main/java/org/imixs/workflow/wopi/WopiController.java @@ -59,11 +59,17 @@ public class WopiController implements Serializable { private static Logger logger = Logger.getLogger(WopiController.class.getName()); private String accessToken = null; + private boolean enabled = false; @Inject - @ConfigProperty(name = "wopi.host.endpoint", defaultValue = "http://localhost:8080/api/wopi/") + @ConfigProperty(name = "wopi.host.endpoint", defaultValue="") String wopiHostEndpoint; + @Inject + @ConfigProperty(name = "wopi.file.extensions",defaultValue = ".odt,.doc,.docx,.docm,.rtf,.ods,.xls,.xlsx,.odp,.ppt,.pptx,.odg,.dxf,.emf,.wmf,.vsd,.vsdx") + String wopiFileExtensions; + + @Inject WopiAccessHandler wopiAccessHandler; @@ -76,10 +82,17 @@ public class WopiController implements Serializable { */ @PostConstruct void init() { - if (!wopiHostEndpoint.endsWith("/")) { - wopiHostEndpoint = wopiHostEndpoint + "/"; + if (wopiHostEndpoint != null && !wopiHostEndpoint.isEmpty()) { + enabled = true; } + } + /** + * Indicates if the wopi feature is enabled + * @return + */ + public boolean isEnabled() { + return enabled; } public String getAccessToken() { @@ -103,21 +116,39 @@ private String generateAccessToken(String userid, String username) { } /** - * Returns the access url for the wopi client. - *
The method creates an accessToken - * (JWT) including the username. + * Returns the access url for the wopi client. + *
+ * The method creates an accessToken (JWT) including the username. * * https://localhost:9980/{libreoffice-editor}.html?WOPISrc=http://wopi-app:8080/api/wopi/files/{your-file} * */ public String getWopiAccessURL(String uniqueid, String file, String userid, String username) { + if (!enabled) { + return null; + } + // compute the access base url String baseURL = wopiAccessHandler.getClientEndpointByFilename(file); if (baseURL == null) { logger.warning("...no wopi client endpoint found!"); return null; } + + // test file extension + String[] extensions = wopiFileExtensions.split(","); + boolean supported=false; + for (String ext: extensions) { + if (file.endsWith(ext)) { + supported=true; + break; + } + } + if (!supported) { + logger.fine("...filextension '" + file + "' is not supported."); + return null; + } // init query string.... if (!baseURL.contains("?")) { @@ -127,11 +158,10 @@ public String getWopiAccessURL(String uniqueid, String file, String userid, Stri baseURL = baseURL + "&"; } - String token=generateAccessToken(userid,username); - baseURL = baseURL + "WOPISrc=" + wopiHostEndpoint + uniqueid + "/files/" + file + "?access_token=" - + token; - - //baseURL = baseURL + "&NotWOPIButIframe=true"; + String token = generateAccessToken(userid, username); + baseURL = baseURL + "WOPISrc=" + wopiHostEndpoint + uniqueid + "/files/" + file + "?access_token=" + token; + + // baseURL = baseURL + "&NotWOPIButIframe=true"; if (baseURL.startsWith("http://")) { logger.warning("...WOPI Client is running without SSL - this is not recommended for production!"); @@ -151,7 +181,7 @@ public void updateFile() { logger.info("...update fileData..."); - FileData fileData = wopiAccessHandler.fetchFileData( getAccessToken()); + FileData fileData = wopiAccessHandler.fetchFileData(getAccessToken()); if (fileData != null) { fileUploadController.addAttachedFile(fileData); } else {