From 9faeed7b20f5eaf8a8459425ccbbfeeb4ff99ba1 Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Tue, 29 Jun 2021 18:20:21 -0400 Subject: [PATCH] Count E164 authentications versus UUID authentications. --- .../textsecuregcm/auth/BaseAccountAuthenticator.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java b/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java index ae49b06f8..4401b453d 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/auth/BaseAccountAuthenticator.java @@ -28,6 +28,7 @@ public class BaseAccountAuthenticator { private static final String AUTHENTICATION_SUCCEEDED_TAG_NAME = "succeeded"; private static final String AUTHENTICATION_FAILURE_REASON_TAG_NAME = "reason"; private static final String AUTHENTICATION_ENABLED_REQUIRED_TAG_NAME = "enabledRequired"; + private static final String AUTHENTICATION_CREDENTIAL_TYPE_TAG_NAME = "credentialType"; private static final String DAYS_SINCE_LAST_SEEN_DISTRIBUTION_NAME = name(BaseAccountAuthenticator.class, "daysSinceLastSeen"); private static final String IS_PRIMARY_DEVICE_TAG = "isPrimary"; @@ -48,11 +49,14 @@ public class BaseAccountAuthenticator { public Optional authenticate(BasicCredentials basicCredentials, boolean enabledRequired) { boolean succeeded = false; String failureReason = null; + String credentialType = null; try { AuthorizationHeader authorizationHeader = AuthorizationHeader.fromUserAndPassword(basicCredentials.getUsername(), basicCredentials.getPassword()); Optional account = accountsManager.get(authorizationHeader.getIdentifier()); + credentialType = authorizationHeader.getIdentifier().hasNumber() ? "e164" : "uuid"; + if (account.isEmpty()) { failureReason = "noSuchAccount"; return Optional.empty(); @@ -97,6 +101,10 @@ public class BaseAccountAuthenticator { tags = tags.and(AUTHENTICATION_FAILURE_REASON_TAG_NAME, failureReason); } + if (StringUtils.isNotBlank(credentialType)) { + tags = tags.and(AUTHENTICATION_CREDENTIAL_TYPE_TAG_NAME, credentialType); + } + Metrics.counter(AUTHENTICATION_COUNTER_NAME, tags).increment(); } }