diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketAccountAuthenticator.java b/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketAccountAuthenticator.java index c7dc07497..460c5f498 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketAccountAuthenticator.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/websocket/WebSocketAccountAuthenticator.java @@ -12,6 +12,7 @@ import java.util.Optional; import org.eclipse.jetty.websocket.api.UpgradeRequest; import org.whispersystems.textsecuregcm.auth.AccountAuthenticator; import org.whispersystems.textsecuregcm.auth.AuthenticatedAccount; +import org.whispersystems.websocket.auth.AuthenticationException; import org.whispersystems.websocket.auth.WebSocketAuthenticator; @@ -24,7 +25,8 @@ public class WebSocketAccountAuthenticator implements WebSocketAuthenticator authenticate(UpgradeRequest request) { + public AuthenticationResult authenticate(UpgradeRequest request) + throws AuthenticationException { Map> parameters = request.getParameterMap(); List usernames = parameters.get("login"); List passwords = parameters.get("password"); @@ -37,7 +39,13 @@ public class WebSocketAccountAuthenticator implements WebSocketAuthenticator(accountAuthenticator.authenticate(credentials), true); + try { + return new AuthenticationResult<>(accountAuthenticator.authenticate(credentials), true); + } catch (final Exception e) { + // this will be handled and logged upstream + // the most likely exception is a transient error connecting to account storage + throw new AuthenticationException(e); + } } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnectionTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnectionTest.java index dbdc2a279..473a9cfe7 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnectionTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/websocket/WebSocketConnectionTest.java @@ -114,7 +114,7 @@ class WebSocketConnectionTest { } @Test - void testCredentials() { + void testCredentials() throws Exception { WebSocketAccountAuthenticator webSocketAuthenticator = new WebSocketAccountAuthenticator(accountAuthenticator); AuthenticatedConnectListener connectListener = new AuthenticatedConnectListener(receiptSender, messagesManager, mock(PushNotificationManager.class), mock(ClientPresenceManager.class),