Skip to content

Commit

Permalink
Update webx-relay and allow connections using a sessionId only.
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartcaunt committed Mar 6, 2025
1 parent daf44af commit b70d25e
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 20 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>eu.ill</groupId>
<artifactId>webx-relay</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>
</dependency>

<dependency>
Expand Down
51 changes: 32 additions & 19 deletions src/main/java/eu/ill/webxdemo/ws/WebSocketTunnelListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class WebSocketTunnelListener implements WebSocketListener {
private static final Logger logger = LoggerFactory.getLogger(WebSocketTunnelListener.class);
private static final String WEBX_HOST_PARAM = "webxhost";
private static final String WEBX_PORT_PARAM = "webxport";
private static final String WEBX_SESSION_ID_PARAM = "sessionid";
private static final String TOKEN_PARAM = "token";
private static final String WIDTH_PARAM = "width";
private static final String HEIGHT_PARAM = "height";
Expand Down Expand Up @@ -52,26 +53,38 @@ public void onWebSocketConnect(final Session session) {
String hostname = this.getStringParam(params, WEBX_HOST_PARAM);
webXConfiguration = new WebXConfiguration(hostname, port, false);

String token = this.getStringParam(params, TOKEN_PARAM);
Credentials credentials = AuthService.instance().getCredentials(token);
if (!credentials.isValid()) {
logger.warn("Connection credentials are invalid. Disconnecting");
session.close();
return;

String sessionId = this.getStringParam(params, WEBX_SESSION_ID_PARAM);
if (sessionId != null) {
if (sessionId.length() != 32) {
logger.error("SessionId {} is invalid", sessionId);
session.close();
return;
}
clientInformation = new WebXClientInformation(sessionId);

} else {
String token = this.getStringParam(params, TOKEN_PARAM);
Credentials credentials = AuthService.instance().getCredentials(token);
if (!credentials.isValid()) {
logger.warn("Connection credentials are invalid. Disconnecting");
session.close();
return;
}
String username = credentials.getUsername();
String password = credentials.getPassword();

Integer width = this.getIntegerParam(params, WIDTH_PARAM);
Integer height = this.getIntegerParam(params, HEIGHT_PARAM);
String keyboard = this.getStringParam(params, KEYBOARD_PARAM);

clientInformation = new WebXClientInformation(
username,
password,
width != null ? width : configuration.getDefaultScreenWidth(),
height != null ? height : configuration.getDefaultScreenHeight(),
keyboard != null ? keyboard : configuration.getDefaultKeyboardLayout());
}
String username = credentials.getUsername();
String password = credentials.getPassword();

Integer width = this.getIntegerParam(params, WIDTH_PARAM);
Integer height = this.getIntegerParam(params, HEIGHT_PARAM);
String keyboard = this.getStringParam(params, KEYBOARD_PARAM);

clientInformation = new WebXClientInformation(
username,
password,
width != null ? width : configuration.getDefaultScreenWidth(),
height != null ? height : configuration.getDefaultScreenHeight(),
keyboard != null ? keyboard : configuration.getDefaultKeyboardLayout());
}


Expand Down

0 comments on commit b70d25e

Please sign in to comment.