Skip to content

Commit

Permalink
Renamed IdentityRequest/IdentityResponse to TokenGenerateRequest/Resp…
Browse files Browse the repository at this point in the history
…onse
  • Loading branch information
sunnywu committed Dec 9, 2024
1 parent a002ad1 commit ea0b247
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 143 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@

import java.time.Instant;

public final class IdentityRequest {
public final class TokenGenerateRequest {
public final SourcePublisher sourcePublisher;
public final HashedDiiIdentity hashedDiiIdentity;
public final OptoutCheckPolicy optoutCheckPolicy;

public final PrivacyBits privacyBits;
public final Instant establishedAt;

public IdentityRequest(
public TokenGenerateRequest(
SourcePublisher sourcePublisher,
HashedDiiIdentity hashedDiiIdentity,
OptoutCheckPolicy tokenGeneratePolicy,
Expand All @@ -26,7 +26,7 @@ public IdentityRequest(
this.establishedAt = establishedAt;
}

public IdentityRequest(
public TokenGenerateRequest(
SourcePublisher sourcePublisher,
HashedDiiIdentity hashedDiiIdentity,
OptoutCheckPolicy tokenGeneratePolicy) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
// this defines all the fields for the response of the /token/generate and /client/generate endpoints before they are
// jsonified
// todo: can be converted to record later
public class IdentityResponse {
public static final IdentityResponse OptOutResponse = new IdentityResponse("", null, "", Instant.EPOCH, Instant.EPOCH, Instant.EPOCH);
public class TokenGenerateResponse {
public static final TokenGenerateResponse OptOutResponse = new TokenGenerateResponse("", null, "", Instant.EPOCH, Instant.EPOCH, Instant.EPOCH);

//aka UID token
private final String advertisingToken;
Expand All @@ -20,8 +20,8 @@ public class IdentityResponse {
private final Instant refreshExpires;
private final Instant refreshFrom;

public IdentityResponse(String advertisingToken, TokenVersion advertisingTokenVersion, String refreshToken,
Instant identityExpires, Instant refreshExpires, Instant refreshFrom) {
public TokenGenerateResponse(String advertisingToken, TokenVersion advertisingTokenVersion, String refreshToken,
Instant identityExpires, Instant refreshExpires, Instant refreshFrom) {
this.advertisingToken = advertisingToken;
this.advertisingTokenVersion = advertisingTokenVersion;
this.refreshToken = refreshToken;
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/com/uid2/operator/model/TokenRefreshResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,37 @@
public class TokenRefreshResponse {

public static final TokenRefreshResponse Invalid = new TokenRefreshResponse(Status.Invalid,
IdentityResponse.OptOutResponse);
public static final TokenRefreshResponse Optout = new TokenRefreshResponse(Status.Optout, IdentityResponse.OptOutResponse);
public static final TokenRefreshResponse Expired = new TokenRefreshResponse(Status.Expired, IdentityResponse.OptOutResponse);
public static final TokenRefreshResponse Deprecated = new TokenRefreshResponse(Status.Deprecated, IdentityResponse.OptOutResponse);
public static final TokenRefreshResponse NoActiveKey = new TokenRefreshResponse(Status.NoActiveKey, IdentityResponse.OptOutResponse);
TokenGenerateResponse.OptOutResponse);
public static final TokenRefreshResponse Optout = new TokenRefreshResponse(Status.Optout, TokenGenerateResponse.OptOutResponse);
public static final TokenRefreshResponse Expired = new TokenRefreshResponse(Status.Expired, TokenGenerateResponse.OptOutResponse);
public static final TokenRefreshResponse Deprecated = new TokenRefreshResponse(Status.Deprecated, TokenGenerateResponse.OptOutResponse);
public static final TokenRefreshResponse NoActiveKey = new TokenRefreshResponse(Status.NoActiveKey, TokenGenerateResponse.OptOutResponse);
private final Status status;
private final IdentityResponse identityResponse;
private final TokenGenerateResponse tokenGenerateResponse;
private final Duration durationSinceLastRefresh;
private final boolean isCstg;

private TokenRefreshResponse(Status status, IdentityResponse identityResponse, Duration durationSinceLastRefresh, boolean isCstg) {
private TokenRefreshResponse(Status status, TokenGenerateResponse tokenGenerateResponse, Duration durationSinceLastRefresh, boolean isCstg) {
this.status = status;
this.identityResponse = identityResponse;
this.tokenGenerateResponse = tokenGenerateResponse;
this.durationSinceLastRefresh = durationSinceLastRefresh;
this.isCstg = isCstg;
}

private TokenRefreshResponse(Status status, IdentityResponse identityResponse) {
this(status, identityResponse, null, false);
private TokenRefreshResponse(Status status, TokenGenerateResponse tokenGenerateResponse) {
this(status, tokenGenerateResponse, null, false);
}

public static TokenRefreshResponse createRefreshedResponse(IdentityResponse identityResponse, Duration durationSinceLastRefresh, boolean isCstg) {
return new TokenRefreshResponse(Status.Refreshed, identityResponse, durationSinceLastRefresh, isCstg);
public static TokenRefreshResponse createRefreshedResponse(TokenGenerateResponse tokenGenerateResponse, Duration durationSinceLastRefresh, boolean isCstg) {
return new TokenRefreshResponse(Status.Refreshed, tokenGenerateResponse, durationSinceLastRefresh, isCstg);
}

public Status getStatus() {
return status;
}

public IdentityResponse getIdentityResponse() {
return identityResponse;
public TokenGenerateResponse getIdentityResponse() {
return tokenGenerateResponse;
}

public Duration getDurationSinceLastRefresh() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ public static String bytesToBase64Token(byte[] advertisingTokenBytes, TokenVersi
}

@Override
public IdentityResponse encodeIntoIdentityResponse(AdvertisingTokenRequest advertisingTokenRequest, TokenRefreshRequest tokenRefreshRequest, Instant refreshFrom, Instant asOf) {
public TokenGenerateResponse encodeIntoIdentityResponse(AdvertisingTokenRequest advertisingTokenRequest, TokenRefreshRequest tokenRefreshRequest, Instant refreshFrom, Instant asOf) {
final String advertisingToken = generateAdvertisingTokenString(advertisingTokenRequest, asOf);
final String refreshToken = generateRefreshTokenString(tokenRefreshRequest, asOf);
return new IdentityResponse(
return new TokenGenerateResponse(
advertisingToken,
advertisingTokenRequest.version,
refreshToken,
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/uid2/operator/service/ITokenEncoder.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.uid2.operator.service;

import com.uid2.operator.model.AdvertisingTokenRequest;
import com.uid2.operator.model.IdentityResponse;
import com.uid2.operator.model.TokenGenerateResponse;
import com.uid2.operator.model.TokenRefreshRequest;

import java.time.Instant;

public interface ITokenEncoder {
IdentityResponse encodeIntoIdentityResponse(AdvertisingTokenRequest advertisingTokenRequest, TokenRefreshRequest tokenRefreshRequest, Instant refreshFrom, Instant asOf);
TokenGenerateResponse encodeIntoIdentityResponse(AdvertisingTokenRequest advertisingTokenRequest, TokenRefreshRequest tokenRefreshRequest, Instant refreshFrom, Instant asOf);

AdvertisingTokenRequest decodeAdvertisingToken(String base64String);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public interface IUIDOperatorService {

IdentityResponse generateIdentity(IdentityRequest request);
TokenGenerateResponse generateIdentity(TokenGenerateRequest request);

TokenRefreshResponse refreshIdentity(TokenRefreshRequest input);

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/uid2/operator/service/UIDOperatorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ public UIDOperatorService(JsonObject config, IOptOutStore optOutStore, ISaltProv
}

@Override
public IdentityResponse generateIdentity(IdentityRequest request) {
public TokenGenerateResponse generateIdentity(TokenGenerateRequest request) {
final Instant now = EncodingUtils.NowUTCMillis(this.clock);
final byte[] firstLevelHash = getFirstLevelHash(request.hashedDiiIdentity.hashedDii, now);
final FirstLevelHashIdentity firstLevelHashIdentity = new FirstLevelHashIdentity(
request.hashedDiiIdentity.identityScope, request.hashedDiiIdentity.identityType, firstLevelHash,
request.establishedAt);

if (request.shouldCheckOptOut() && getGlobalOptOutResult(firstLevelHashIdentity, false).isOptedOut()) {
return IdentityResponse.OptOutResponse;
return TokenGenerateResponse.OptOutResponse;
} else {
return generateIdentity(request.sourcePublisher, firstLevelHashIdentity, request.privacyBits);
}
Expand Down Expand Up @@ -145,11 +145,11 @@ public TokenRefreshResponse refreshIdentity(TokenRefreshRequest input) {
final Duration durationSinceLastRefresh = Duration.between(input.createdAt, now);

if (!optedOut) {
IdentityResponse identityResponse = this.generateIdentity(input.sourcePublisher,
TokenGenerateResponse tokenGenerateResponse = this.generateIdentity(input.sourcePublisher,
input.firstLevelHashIdentity,
input.privacyBits);

return TokenRefreshResponse.createRefreshedResponse(identityResponse, durationSinceLastRefresh, isCstg);
return TokenRefreshResponse.createRefreshedResponse(tokenGenerateResponse, durationSinceLastRefresh, isCstg);
} else {
return TokenRefreshResponse.Optout;
}
Expand Down Expand Up @@ -250,8 +250,8 @@ private RawUidResponse generateRawUid(FirstLevelHashIdentity firstLevelHashIdent
rotatingSalt.getHashedId());
}

private IdentityResponse generateIdentity(SourcePublisher sourcePublisher,
FirstLevelHashIdentity firstLevelHashIdentity, PrivacyBits privacyBits) {
private TokenGenerateResponse generateIdentity(SourcePublisher sourcePublisher,
FirstLevelHashIdentity firstLevelHashIdentity, PrivacyBits privacyBits) {
final Instant nowUtc = EncodingUtils.NowUTCMillis(this.clock);

final RawUidResponse rawUidResponse = generateRawUid(firstLevelHashIdentity, nowUtc);
Expand Down
30 changes: 15 additions & 15 deletions src/main/java/com/uid2/operator/vertx/UIDOperatorVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.uid2.operator.Const;
import com.uid2.operator.model.*;
import com.uid2.operator.model.IdentityResponse;
import com.uid2.operator.model.TokenGenerateResponse;
import com.uid2.operator.model.IdentityScope;
import com.uid2.operator.model.userIdentity.HashedDiiIdentity;
import com.uid2.operator.monitoring.IStatsCollectorQueue;
Expand Down Expand Up @@ -464,10 +464,10 @@ else if(emailHash != null) {
privacyBits.setLegacyBit();
privacyBits.setClientSideTokenGenerate();

IdentityResponse identityResponse;
TokenGenerateResponse tokenGenerateResponse;
try {
identityResponse = this.idService.generateIdentity(
new IdentityRequest(
tokenGenerateResponse = this.idService.generateIdentity(
new TokenGenerateRequest(
new SourcePublisher(clientSideKeypair.getSiteId()),
input.toHashedDiiIdentity(this.identityScope),
OptoutCheckPolicy.RespectOptOut, privacyBits, Instant.now()));
Expand All @@ -478,20 +478,20 @@ else if(emailHash != null) {
JsonObject response;
TokenResponseStatsCollector.ResponseStatus responseStatus = TokenResponseStatsCollector.ResponseStatus.Success;

if (identityResponse.isOptedOut()) {
if (tokenGenerateResponse.isOptedOut()) {
response = ResponseUtil.SuccessNoBodyV2(ResponseStatus.OptOut);
responseStatus = TokenResponseStatsCollector.ResponseStatus.OptOut;
}
else { //user not opted out and already generated valid identity token
response = ResponseUtil.SuccessV2(identityResponse.toJsonV1());
response = ResponseUtil.SuccessV2(tokenGenerateResponse.toJsonV1());
}
//if returning an optout token or a successful identity token created originally
if (responseStatus == TokenResponseStatsCollector.ResponseStatus.Success) {
V2RequestUtil.handleRefreshTokenInResponseBody(response.getJsonObject("body"), keyManager, this.identityScope);
}
final byte[] encryptedResponse = AesGcm.encrypt(response.toBuffer().getBytes(), sharedSecret);
rc.response().setStatusCode(200).end(Buffer.buffer(Unpooled.wrappedBuffer(Base64.getEncoder().encode(encryptedResponse))));
recordTokenResponseStats(clientSideKeypair.getSiteId(), TokenResponseStatsCollector.Endpoint.ClientSideTokenGenerateV2, responseStatus, siteProvider, identityResponse.getAdvertisingTokenVersion(), platformType);
recordTokenResponseStats(clientSideKeypair.getSiteId(), TokenResponseStatsCollector.Endpoint.ClientSideTokenGenerateV2, responseStatus, siteProvider, tokenGenerateResponse.getAdvertisingTokenVersion(), platformType);
}

private boolean hasValidOriginOrAppName(RoutingContext rc, CstgRequest request, ClientSideKeypair keypair, TokenResponseStatsCollector.PlatformType platformType) {
Expand Down Expand Up @@ -939,8 +939,8 @@ private void handleTokenGenerateV1(RoutingContext rc) {
final InputUtil.InputVal input = this.phoneSupport ? this.getTokenInputV1(rc) : this.getTokenInput(rc);
platformType = getPlatformType(rc);
if (isTokenInputValid(input, rc)) {
final IdentityResponse response = this.idService.generateIdentity(
new IdentityRequest(
final TokenGenerateResponse response = this.idService.generateIdentity(
new TokenGenerateRequest(
new SourcePublisher(siteId),
input.toHashedDiiIdentity(this.identityScope),
OptoutCheckPolicy.defaultPolicy()));
Expand Down Expand Up @@ -991,8 +991,8 @@ private void handleTokenGenerateV2(RoutingContext rc) {
return;
}

final IdentityResponse response = this.idService.generateIdentity(
new IdentityRequest(
final TokenGenerateResponse response = this.idService.generateIdentity(
new TokenGenerateRequest(
new SourcePublisher(siteId),
input.toHashedDiiIdentity(this.identityScope),
OptoutCheckPolicy.respectOptOut()));
Expand All @@ -1007,8 +1007,8 @@ private void handleTokenGenerateV2(RoutingContext rc) {
pb.setLegacyBit();
pb.setClientSideTokenGenerateOptout();

final IdentityResponse optOutTokens = this.idService.generateIdentity(
new IdentityRequest(
final TokenGenerateResponse optOutTokens = this.idService.generateIdentity(
new TokenGenerateRequest(
new SourcePublisher(siteId),
optOutTokenInput.toHashedDiiIdentity(this.identityScope),
OptoutCheckPolicy.DoNotRespect, pb, Instant.now()));
Expand Down Expand Up @@ -1047,8 +1047,8 @@ else if (!input.isValid()) {

try {
siteId = AuthMiddleware.getAuthClient(rc).getSiteId();
final IdentityResponse response = this.idService.generateIdentity(
new IdentityRequest(
final TokenGenerateResponse response = this.idService.generateIdentity(
new TokenGenerateRequest(
new SourcePublisher(siteId),
input.toHashedDiiIdentity(this.identityScope),
OptoutCheckPolicy.defaultPolicy()));
Expand Down
Loading

0 comments on commit ea0b247

Please sign in to comment.