diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java index e241efe91..64e643bf5 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/WhisperServerService.java @@ -294,7 +294,7 @@ public class WhisperServerService extends Application Set.of(); // TODO: Provide an actual implementation. + ProfileBadgeConverter profileBadgeConverter = (acceptableLanguages, accountBadges) -> Set.of(); // TODO: Provide an actual implementation. JdbiFactory jdbiFactory = new JdbiFactory(DefaultNameStrategy.CHECK_EMPTY); Jdbi accountJdbi = jdbiFactory.build(environment, config.getAccountsDatabaseConfiguration(), "accountdb"); diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/badges/ProfileBadgeConverter.java b/service/src/main/java/org/whispersystems/textsecuregcm/badges/ProfileBadgeConverter.java index de6d4da37..e981964b2 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/badges/ProfileBadgeConverter.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/badges/ProfileBadgeConverter.java @@ -5,8 +5,9 @@ package org.whispersystems.textsecuregcm.badges; +import java.util.List; +import java.util.Locale; import java.util.Set; -import javax.ws.rs.core.Request; import org.whispersystems.textsecuregcm.entities.Badge; import org.whispersystems.textsecuregcm.storage.AccountBadge; @@ -14,9 +15,7 @@ public interface ProfileBadgeConverter { /** * Converts the {@link AccountBadge}s for an account into the objects - * that can be returned on a profile fetch. This requires returning - * localized strings given the user's locale which will be retrieved from - * the {@link Request} object passed in. + * that can be returned on a profile fetch. */ - Set convert(Request request, Set accountBadges); + Set convert(List acceptableLanguages, Set accountBadges); } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java index 42ea03d64..b02fb0da4 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java @@ -10,6 +10,8 @@ import io.dropwizard.auth.Auth; import java.security.SecureRandom; import java.time.ZoneOffset; import java.time.ZonedDateTime; +import java.util.List; +import java.util.Locale; import java.util.Optional; import java.util.Set; import java.util.UUID; @@ -24,15 +26,17 @@ import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.WebApplicationException; +import javax.ws.rs.container.ContainerRequestContext; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Request; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Hex; import org.apache.commons.lang3.StringUtils; +import org.glassfish.jersey.message.internal.AcceptableLanguageTag; +import org.glassfish.jersey.message.internal.InboundMessageContext; import org.signal.zkgroup.InvalidInputException; import org.signal.zkgroup.VerificationFailedException; import org.signal.zkgroup.profiles.ProfileKeyCommitment; @@ -183,14 +187,14 @@ public class ProfileController { public Optional getProfile( @Auth Optional auth, @HeaderParam(OptionalAccess.UNIDENTIFIED) Optional accessKey, - @Context Request request, + @Context ContainerRequestContext containerRequestContext, @PathParam("uuid") UUID uuid, @PathParam("version") String version) throws RateLimitExceededException { if (!isZkEnabled) { throw new WebApplicationException(Response.Status.NOT_FOUND); } - return getVersionedProfile(auth.map(AuthenticatedAccount::getAccount), accessKey, request, uuid, version, Optional.empty()); + return getVersionedProfile(auth.map(AuthenticatedAccount::getAccount), accessKey, containerRequestContext.getAcceptableLanguages(), uuid, version, Optional.empty()); } @Timed @@ -200,7 +204,7 @@ public class ProfileController { public Optional getProfile( @Auth Optional auth, @HeaderParam(OptionalAccess.UNIDENTIFIED) Optional accessKey, - @Context Request request, + @Context ContainerRequestContext containerRequestContext, @PathParam("uuid") UUID uuid, @PathParam("version") String version, @PathParam("credentialRequest") String credentialRequest) @@ -208,13 +212,13 @@ public class ProfileController { if (!isZkEnabled) { throw new WebApplicationException(Response.Status.NOT_FOUND); } - return getVersionedProfile(auth.map(AuthenticatedAccount::getAccount), accessKey, request, uuid, version, Optional.of(credentialRequest)); + return getVersionedProfile(auth.map(AuthenticatedAccount::getAccount), accessKey, containerRequestContext.getAcceptableLanguages(), uuid, version, Optional.of(credentialRequest)); } private Optional getVersionedProfile( Optional requestAccount, Optional accessKey, - Request request, + List acceptableLanguages, UUID uuid, String version, Optional credentialRequest) @@ -265,7 +269,7 @@ public class ProfileController { UserCapabilities.createForAccount(accountProfile.get()), username.orElse(null), null, - profileBadgeConverter.convert(request, accountProfile.get().getBadges()), + profileBadgeConverter.convert(acceptableLanguages, accountProfile.get().getBadges()), credential.orElse(null))); } catch (InvalidInputException e) { logger.info("Bad profile request", e); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java index cbcb4720f..02d13200a 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/tests/controllers/ProfileControllerTest.java @@ -96,7 +96,7 @@ class ProfileControllerTest { profilesManager, usernamesManager, dynamicConfigurationManager, - (request, accountBadges) -> Set.of(), // TODO: Test with some badges. + (acceptableLanguages, accountBadges) -> Set.of(), // TODO: Test with some badges. s3client, postPolicyGenerator, policySigner,