mirror of
https://github.com/signalapp/Signal-Server.git
synced 2026-12-02 16:36:53 +00:00
Add an interceptor interface for WebSocket authentication
This commit is contained in:
1 parent
59d984e25d
commit
552079d3c2
5 files changed
+59
-1
No files matched your search
+3
@@ -76,6 +76,9 @@ public class WebSocketResourceProviderFactory<T extends Principal> extends Jetty
|
||||
authenticated = ReusableAuth.anonymous();
|
||||
}
|
||||
|
||||
Optional.ofNullable(environment.getAuthenticatedWebSocketUpgradeFilter())
|
||||
.ifPresent(filter -> filter.handleAuthentication(authenticated, request, response));
|
||||
|
||||
return new WebSocketResourceProvider<>(getRemoteAddress(request),
|
||||
remoteAddressPropertyName,
|
||||
this.jerseyApplicationHandler,
|
||||
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2025 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.whispersystems.websocket.auth;
|
||||
|
||||
import java.security.Principal;
|
||||
import org.eclipse.jetty.websocket.server.JettyServerUpgradeRequest;
|
||||
import org.eclipse.jetty.websocket.server.JettyServerUpgradeResponse;
|
||||
import org.whispersystems.websocket.ReusableAuth;
|
||||
|
||||
public interface AuthenticatedWebSocketUpgradeFilter<T extends Principal> {
|
||||
|
||||
void handleAuthentication(ReusableAuth<T> authenticated,
|
||||
JettyServerUpgradeRequest request,
|
||||
JettyServerUpgradeResponse response);
|
||||
}
|
||||
+13
@@ -11,11 +11,13 @@ import jakarta.validation.Validator;
|
||||
import java.security.Principal;
|
||||
import java.time.Duration;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
import org.whispersystems.websocket.auth.AuthenticatedWebSocketUpgradeFilter;
|
||||
import org.whispersystems.websocket.auth.WebSocketAuthenticator;
|
||||
import org.whispersystems.websocket.configuration.WebSocketConfiguration;
|
||||
import org.whispersystems.websocket.logging.WebsocketRequestLog;
|
||||
import org.whispersystems.websocket.messages.WebSocketMessageFactory;
|
||||
import org.whispersystems.websocket.messages.protobuf.ProtobufWebSocketMessageFactory;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class WebSocketEnvironment<T extends Principal> {
|
||||
|
||||
@@ -26,6 +28,7 @@ public class WebSocketEnvironment<T extends Principal> {
|
||||
private final Duration idleTimeout;
|
||||
|
||||
private WebSocketAuthenticator<T> authenticator;
|
||||
private AuthenticatedWebSocketUpgradeFilter<T> authenticatedWebSocketUpgradeFilter;
|
||||
private WebSocketMessageFactory messageFactory;
|
||||
private WebSocketConnectListener connectListener;
|
||||
|
||||
@@ -50,6 +53,7 @@ public class WebSocketEnvironment<T extends Principal> {
|
||||
return jerseyConfig;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public WebSocketAuthenticator<T> getAuthenticator() {
|
||||
return authenticator;
|
||||
}
|
||||
@@ -58,6 +62,15 @@ public class WebSocketEnvironment<T extends Principal> {
|
||||
this.authenticator = authenticator;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public AuthenticatedWebSocketUpgradeFilter<T> getAuthenticatedWebSocketUpgradeFilter() {
|
||||
return authenticatedWebSocketUpgradeFilter;
|
||||
}
|
||||
|
||||
public void setAuthenticatedWebSocketUpgradeFilter(final AuthenticatedWebSocketUpgradeFilter<T> authenticatedWebSocketUpgradeFilter) {
|
||||
this.authenticatedWebSocketUpgradeFilter = authenticatedWebSocketUpgradeFilter;
|
||||
}
|
||||
|
||||
public Duration getIdleTimeout() {
|
||||
return idleTimeout;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user