Wrap runtime exceptions during WebSocket auth into AuthenticationException
This commit is contained in:
parent
39d9fd0317
commit
391aa9c518
|
@ -12,6 +12,7 @@ import java.util.Optional;
|
||||||
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
import org.eclipse.jetty.websocket.api.UpgradeRequest;
|
||||||
import org.whispersystems.textsecuregcm.auth.AccountAuthenticator;
|
import org.whispersystems.textsecuregcm.auth.AccountAuthenticator;
|
||||||
import org.whispersystems.textsecuregcm.auth.AuthenticatedAccount;
|
import org.whispersystems.textsecuregcm.auth.AuthenticatedAccount;
|
||||||
|
import org.whispersystems.websocket.auth.AuthenticationException;
|
||||||
import org.whispersystems.websocket.auth.WebSocketAuthenticator;
|
import org.whispersystems.websocket.auth.WebSocketAuthenticator;
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,7 +25,8 @@ public class WebSocketAccountAuthenticator implements WebSocketAuthenticator<Aut
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public AuthenticationResult<AuthenticatedAccount> authenticate(UpgradeRequest request) {
|
public AuthenticationResult<AuthenticatedAccount> authenticate(UpgradeRequest request)
|
||||||
|
throws AuthenticationException {
|
||||||
Map<String, List<String>> parameters = request.getParameterMap();
|
Map<String, List<String>> parameters = request.getParameterMap();
|
||||||
List<String> usernames = parameters.get("login");
|
List<String> usernames = parameters.get("login");
|
||||||
List<String> passwords = parameters.get("password");
|
List<String> passwords = parameters.get("password");
|
||||||
|
@ -37,7 +39,13 @@ public class WebSocketAccountAuthenticator implements WebSocketAuthenticator<Aut
|
||||||
BasicCredentials credentials = new BasicCredentials(usernames.get(0).replace(" ", "+"),
|
BasicCredentials credentials = new BasicCredentials(usernames.get(0).replace(" ", "+"),
|
||||||
passwords.get(0).replace(" ", "+"));
|
passwords.get(0).replace(" ", "+"));
|
||||||
|
|
||||||
return new AuthenticationResult<>(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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -114,7 +114,7 @@ class WebSocketConnectionTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testCredentials() {
|
void testCredentials() throws Exception {
|
||||||
WebSocketAccountAuthenticator webSocketAuthenticator = new WebSocketAccountAuthenticator(accountAuthenticator);
|
WebSocketAccountAuthenticator webSocketAuthenticator = new WebSocketAccountAuthenticator(accountAuthenticator);
|
||||||
AuthenticatedConnectListener connectListener = new AuthenticatedConnectListener(receiptSender, messagesManager,
|
AuthenticatedConnectListener connectListener = new AuthenticatedConnectListener(receiptSender, messagesManager,
|
||||||
mock(PushNotificationManager.class), mock(ClientPresenceManager.class),
|
mock(PushNotificationManager.class), mock(ClientPresenceManager.class),
|
||||||
|
|
Loading…
Reference in New Issue