Verify that nobody's addressing API calls by e164 any more.
This commit is contained in:
parent
5400abb065
commit
44838d6238
|
@ -5,13 +5,22 @@
|
|||
|
||||
package org.whispersystems.textsecuregcm.auth;
|
||||
|
||||
import io.micrometer.core.instrument.Metrics;
|
||||
import io.micrometer.core.instrument.Tag;
|
||||
import io.micrometer.core.instrument.Tags;
|
||||
import org.whispersystems.textsecuregcm.metrics.UserAgentTagUtil;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.codahale.metrics.MetricRegistry.name;
|
||||
|
||||
public class AmbiguousIdentifier {
|
||||
|
||||
private final UUID uuid;
|
||||
private final String number;
|
||||
|
||||
private static final String REQUEST_COUNTER_NAME = name(AmbiguousIdentifier.class, "request");
|
||||
|
||||
public AmbiguousIdentifier(String target) {
|
||||
if (target.startsWith("+")) {
|
||||
this.uuid = null;
|
||||
|
@ -42,4 +51,11 @@ public class AmbiguousIdentifier {
|
|||
public String toString() {
|
||||
return hasUuid() ? uuid.toString() : number;
|
||||
}
|
||||
|
||||
public void incrementRequestCounter(final String context, @Nullable final String userAgent) {
|
||||
Metrics.counter(REQUEST_COUNTER_NAME, Tags.of(
|
||||
Tag.of("type", hasUuid() ? "uuid" : "e164"),
|
||||
Tag.of("context", context),
|
||||
UserAgentTagUtil.getPlatformTag(userAgent))).increment();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -128,6 +128,9 @@ public class KeysController {
|
|||
@PathParam("device_id") String deviceId,
|
||||
@HeaderParam("User-Agent") String userAgent)
|
||||
throws RateLimitExceededException, RateLimitChallengeException {
|
||||
|
||||
targetName.incrementRequestCounter("getDeviceKeys", userAgent);
|
||||
|
||||
if (!account.isPresent() && !accessKey.isPresent()) {
|
||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||
}
|
||||
|
|
|
@ -197,6 +197,9 @@ public class MessageController {
|
|||
@PathParam("destination") AmbiguousIdentifier destinationName,
|
||||
@Valid IncomingMessageList messages)
|
||||
throws RateLimitExceededException, RateLimitChallengeException {
|
||||
|
||||
destinationName.incrementRequestCounter("sendMessage", userAgent);
|
||||
|
||||
if (source.isEmpty() && accessKey.isEmpty()) {
|
||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||
}
|
||||
|
|
|
@ -328,10 +328,14 @@ public class ProfileController {
|
|||
@Path("/{identifier}")
|
||||
public Profile getProfile(@Auth Optional<Account> requestAccount,
|
||||
@HeaderParam(OptionalAccess.UNIDENTIFIED) Optional<Anonymous> accessKey,
|
||||
@HeaderParam("User-Agent") String userAgent,
|
||||
@PathParam("identifier") AmbiguousIdentifier identifier,
|
||||
@QueryParam("ca") boolean useCaCertificate)
|
||||
throws RateLimitExceededException
|
||||
{
|
||||
|
||||
identifier.incrementRequestCounter("getProfile", userAgent);
|
||||
|
||||
if (requestAccount.isEmpty() && accessKey.isEmpty()) {
|
||||
throw new WebApplicationException(Response.Status.UNAUTHORIZED);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue