Skip to content

Commit 7ab158c

Browse files
committed
handle Bearer interception gracefully
1 parent e6d85c9 commit 7ab158c

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<modelVersion>4.0.0</modelVersion>
1212
<artifactId>websocket-server</artifactId>
13-
<version>1.0.10</version>
13+
<version>1.0.12</version>
1414
<name>WebsocketServer</name>
1515
<packaging>jar</packaging>
1616

src/main/java/info/unterrainer/websocketserver/WsHandlerBase.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ public abstract class WsHandlerBase {
1010

1111
public abstract void onConnect(WsConnectContext ctx) throws Exception;
1212

13-
public abstract void onMessage(WsMessageContext ctx) throws Exception;
13+
public abstract void onMsg(WsMessageContext ctx) throws Exception;
1414

1515
public abstract void onBinaryMessage(WsBinaryMessageContext ctx) throws Exception;
1616

src/main/java/info/unterrainer/websocketserver/WsOauthHandlerBase.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ public void onConnect(WsConnectContext ctx) throws Exception {
7474
}
7575

7676
@Override
77-
public void onMessage(WsMessageContext ctx) throws Exception {
77+
public void onMsg(WsMessageContext ctx) throws Exception {
78+
}
79+
80+
public final void onMessage(WsMessageContext ctx) throws Exception {
7881
log.debug("Received from [{}]: [{}]", ctx.session.getRemoteAddress(), ctx.message());
7982
if (isQuarantined(ctx.session)) {
8083
log.warn("Client [{}] is quarantined, checking message for standard authorization-bearer-token.",
@@ -93,12 +96,14 @@ public void onMessage(WsMessageContext ctx) throws Exception {
9396
ctx.session.getRemoteAddress());
9497
clientsQuarantined.removeIf(c -> c.session.equals(ctx.session));
9598
clientsConnected.add(client);
99+
return;
96100
} catch (Exception e) {
97101
log.debug("Token validation failed for client [{}]. Disconnecting.", ctx.session.getRemoteAddress(), e);
98102
ctx.session.close(1000, "Unauthorized access with invalid token");
99103
return;
100104
}
101105
}
106+
onMsg(ctx);
102107
}
103108

104109
@Override

src/test/java/info/unterrainer/websocketserver/AiComm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
public class AiComm extends WsOauthHandlerBase {
99

1010
@Override
11-
public void onMessage(WsMessageContext ctx) throws Exception {
11+
public void onMsg(WsMessageContext ctx) throws Exception {
1212
super.onMessage(ctx);
1313

1414
// Broadcast to all connected WS clients.

0 commit comments

Comments
 (0)