Skip to content

Commit

Permalink
documentation, environment variables
Browse files Browse the repository at this point in the history
Issue #108
  • Loading branch information
rsoika committed May 12, 2021
1 parent 9195325 commit 49057d4
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 13 deletions.
2 changes: 1 addition & 1 deletion imixs-adapters-wopi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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() {
Expand All @@ -103,21 +116,39 @@ private String generateAccessToken(String userid, String username) {
}

/**
* Returns the access url for the wopi client.
* <p>The method creates an accessToken
* (JWT) including the username.
* Returns the access url for the wopi client.
* <p>
* 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("?")) {
Expand All @@ -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!");
Expand All @@ -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 {
Expand Down

0 comments on commit 49057d4

Please sign in to comment.