From 73ec57e9117fef0292b4bffb63c05881fb277c4d Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Tue, 24 Mar 2026 13:55:08 -0400 Subject: [PATCH] Avoid constructing a `Metadata.Key` for authentication on every server call --- .../auth/grpc/ProhibitAuthenticationInterceptor.java | 3 +-- .../auth/grpc/RequireAuthenticationInterceptor.java | 7 +++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/ProhibitAuthenticationInterceptor.java b/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/ProhibitAuthenticationInterceptor.java index 17ce00623..02b3c9faa 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/ProhibitAuthenticationInterceptor.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/ProhibitAuthenticationInterceptor.java @@ -8,7 +8,6 @@ import io.grpc.Metadata; import io.grpc.ServerCall; import io.grpc.ServerCallHandler; import io.grpc.ServerInterceptor; -import io.grpc.Status; import org.whispersystems.textsecuregcm.grpc.GrpcExceptions; import org.whispersystems.textsecuregcm.grpc.ServerInterceptorUtil; @@ -22,7 +21,7 @@ public class ProhibitAuthenticationInterceptor implements ServerInterceptor { @Override public ServerCall.Listener interceptCall(final ServerCall call, final Metadata headers, final ServerCallHandler next) { - final String authHeaderString = headers.get(Metadata.Key.of(RequireAuthenticationInterceptor.AUTHORIZATION_HEADER, Metadata.ASCII_STRING_MARSHALLER)); + final String authHeaderString = headers.get(RequireAuthenticationInterceptor.AUTHORIZATION_METADATA_KEY); if (authHeaderString != null) { return ServerInterceptorUtil.closeWithStatusException(call, GrpcExceptions.badAuthentication("The service forbids requests with an authentication header")); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/RequireAuthenticationInterceptor.java b/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/RequireAuthenticationInterceptor.java index 42331c5dc..3371f9051 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/RequireAuthenticationInterceptor.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/auth/grpc/RequireAuthenticationInterceptor.java @@ -11,7 +11,6 @@ import io.grpc.Metadata; import io.grpc.ServerCall; import io.grpc.ServerCallHandler; import io.grpc.ServerInterceptor; -import io.grpc.Status; import java.util.Optional; import org.whispersystems.textsecuregcm.auth.AccountAuthenticator; import org.whispersystems.textsecuregcm.grpc.GrpcExceptions; @@ -26,7 +25,8 @@ import org.whispersystems.textsecuregcm.util.HeaderUtils; */ public class RequireAuthenticationInterceptor implements ServerInterceptor { - static final String AUTHORIZATION_HEADER = "authorization"; + static final Metadata.Key AUTHORIZATION_METADATA_KEY = + Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER); private final AccountAuthenticator authenticator; @@ -37,8 +37,7 @@ public class RequireAuthenticationInterceptor implements ServerInterceptor { @Override public ServerCall.Listener interceptCall(final ServerCall call, final Metadata headers, final ServerCallHandler next) { - final String authHeaderString = headers.get( - Metadata.Key.of(AUTHORIZATION_HEADER, Metadata.ASCII_STRING_MARSHALLER)); + final String authHeaderString = headers.get(AUTHORIZATION_METADATA_KEY); if (authHeaderString == null) { return ServerInterceptorUtil.closeWithStatusException(call,