mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 14:18:04 +01:00
minor username api refinements
This commit is contained in:
committed by
GitHub
parent
67343f6bdc
commit
0188d314ce
@@ -354,11 +354,11 @@ public class AccountController {
|
||||
final Account account = accounts.confirmReservedUsernameHash(
|
||||
auth.getAccount(),
|
||||
confirmRequest.usernameHash(),
|
||||
Optional.ofNullable(confirmRequest.encryptedUsername()).map(EncryptedUsername::usernameLinkEncryptedValue).orElse(null));
|
||||
confirmRequest.encryptedUsername());
|
||||
final UUID linkHandle = account.getUsernameLinkHandle();
|
||||
return new UsernameHashResponse(
|
||||
account.getUsernameHash().orElseThrow(() -> new IllegalStateException("Could not get username after setting")),
|
||||
linkHandle == null ? null : new UsernameLinkHandle(linkHandle));
|
||||
linkHandle);
|
||||
} catch (final UsernameReservationNotFoundException e) {
|
||||
throw new WebApplicationException(Status.CONFLICT);
|
||||
} catch (final UsernameHashNotAvailableException e) {
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.entities;
|
||||
|
||||
import javax.validation.Valid;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.Size;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
@@ -27,8 +27,10 @@ public record ConfirmUsernameHashRequest(
|
||||
@JsonDeserialize(using = ByteArrayBase64UrlAdapter.Deserializing.class)
|
||||
byte[] zkProof,
|
||||
|
||||
@Schema(description = "The encrypted username to be stored for username links")
|
||||
@Schema(type = "string", description = "The url-safe base64-encoded encrypted username to be stored for username links")
|
||||
@Nullable
|
||||
@Valid
|
||||
EncryptedUsername encryptedUsername
|
||||
@JsonSerialize(using = ByteArrayBase64UrlAdapter.Serializing.class)
|
||||
@JsonDeserialize(using = ByteArrayBase64UrlAdapter.Deserializing.class)
|
||||
@Size(min = 1, max = 128)
|
||||
byte[] encryptedUsername
|
||||
) {}
|
||||
|
||||
@@ -5,8 +5,18 @@
|
||||
|
||||
package org.whispersystems.textsecuregcm.entities;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import org.whispersystems.textsecuregcm.util.ByteArrayBase64UrlAdapter;
|
||||
|
||||
public record EncryptedUsername(@NotNull @Size(min = 1, max = 128) byte[] usernameLinkEncryptedValue) {
|
||||
public record EncryptedUsername(
|
||||
@JsonSerialize(using = ByteArrayBase64UrlAdapter.Serializing.class)
|
||||
@JsonDeserialize(using = ByteArrayBase64UrlAdapter.Deserializing.class)
|
||||
@NotNull
|
||||
@Size(min = 1, max = 128)
|
||||
@Schema(type = "string", description = "the URL-safe base64 encoding of the encrypted username")
|
||||
byte[] usernameLinkEncryptedValue) {
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import org.whispersystems.textsecuregcm.controllers.AccountController;
|
||||
import org.whispersystems.textsecuregcm.util.ByteArrayBase64UrlAdapter;
|
||||
import org.whispersystems.textsecuregcm.util.ExactlySize;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.validation.Valid;
|
||||
|
||||
@@ -20,11 +20,11 @@ public record UsernameHashResponse(
|
||||
@JsonSerialize(using = ByteArrayBase64UrlAdapter.Serializing.class)
|
||||
@JsonDeserialize(using = ByteArrayBase64UrlAdapter.Deserializing.class)
|
||||
@ExactlySize(AccountController.USERNAME_HASH_LENGTH)
|
||||
@Schema(description = "The hash of the confirmed username, as supplied in the request")
|
||||
@Schema(type = "string", description = "The hash of the confirmed username, as supplied in the request")
|
||||
byte[] usernameHash,
|
||||
|
||||
@Nullable
|
||||
@Valid
|
||||
@Schema(description = "A handle that can be included in username links to retrieve the stored encrypted username")
|
||||
UsernameLinkHandle usernameLinkHandle
|
||||
@Schema(type = "string", description = "A handle that can be included in username links to retrieve the stored encrypted username")
|
||||
UUID usernameLinkHandle
|
||||
) {}
|
||||
|
||||
@@ -7,6 +7,11 @@ package org.whispersystems.textsecuregcm.entities;
|
||||
|
||||
import java.util.UUID;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Size;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
public record UsernameLinkHandle(@NotNull UUID usernameLinkHandle) {
|
||||
public record UsernameLinkHandle(
|
||||
@Schema(description = "A handle that can be included in username links to retrieve the stored encrypted username")
|
||||
@NotNull
|
||||
UUID usernameLinkHandle) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user