Skip to content

Commit a002ad1

Browse files
committed
Code review feedback,
Mainly renaming RefreshTokenRequest/RefreshResponse to TokenRefreshRequest/TokenRefreshResponse
1 parent 23a6f50 commit a002ad1

18 files changed

+178
-175
lines changed

src/main/java/com/uid2/operator/IdentityConst.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class IdentityConst {
1313
public static final byte[] ValidateIdentityForEmailHash = EncodingUtils.getSha256Bytes(IdentityConst.ValidateIdentityForEmail);
1414
public static final byte[] ValidateIdentityForPhoneHash = EncodingUtils.getSha256Bytes(IdentityConst.ValidateIdentityForPhone);
1515

16-
// DIIs to use when you want to generate a optout response in token generation or identity map
16+
// DIIs to use when you want to generate an optout response in token generation or identity map
1717
public static final String OptOutIdentityForEmail = "[email protected]";
1818
public static final String OptOutIdentityForPhone = "+00000000000";
1919

src/main/java/com/uid2/operator/model/AdvertisingTokenRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import com.uid2.operator.util.PrivacyBits;
77
import com.uid2.shared.model.TokenVersion;
88

9-
// class containing enough data to create a new uid or advertising token
10-
public class AdvertisingTokenRequest extends VersionedToken {
9+
// class containing enough information to create a new uid token (aka advertising token)
10+
public class AdvertisingTokenRequest extends VersionedTokenRequest {
1111
public final OperatorIdentity operatorIdentity;
1212
public final SourcePublisher sourcePublisher;
1313
public final RawUidIdentity rawUidIdentity;

src/main/java/com/uid2/operator/model/IdentityResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// jsonified
1010
// todo: can be converted to record later
1111
public class IdentityResponse {
12-
public static IdentityResponse OptOutIdentityResponse = new IdentityResponse("", null, "", Instant.EPOCH, Instant.EPOCH, Instant.EPOCH);
12+
public static final IdentityResponse OptOutResponse = new IdentityResponse("", null, "", Instant.EPOCH, Instant.EPOCH, Instant.EPOCH);
1313

1414
//aka UID token
1515
private final String advertisingToken;

src/main/java/com/uid2/operator/model/SourcePublisher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
// The original publisher that requests to generate a UID token
44
public class SourcePublisher {
55
public final int siteId;
6+
7+
// these 2 values are added into adverting/UID token and refresh token payload but
8+
// are not really used for any real purposes currently so sometimes are set to 0
9+
// see the constructor below
610
public final int clientKeyId;
711
public final long publisherId;
812

src/main/java/com/uid2/operator/model/RefreshTokenRequest.java renamed to src/main/java/com/uid2/operator/model/TokenRefreshRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
import com.uid2.shared.model.TokenVersion;
88

99
// class containing enough data to create a new refresh token
10-
public class RefreshTokenRequest extends VersionedToken {
10+
public class TokenRefreshRequest extends VersionedTokenRequest {
1111
public final OperatorIdentity operatorIdentity;
1212
public final SourcePublisher sourcePublisher;
1313
public final FirstLevelHashIdentity firstLevelHashIdentity;
1414
// by default, inherited from the previous refresh token's privacy bits
1515
public final PrivacyBits privacyBits;
1616

1717

18-
public RefreshTokenRequest(TokenVersion version, Instant createdAt, Instant expiresAt, OperatorIdentity operatorIdentity,
18+
public TokenRefreshRequest(TokenVersion version, Instant createdAt, Instant expiresAt, OperatorIdentity operatorIdentity,
1919
SourcePublisher sourcePublisher, FirstLevelHashIdentity firstLevelHashIdentity, PrivacyBits privacyBits) {
2020
super(version, createdAt, expiresAt);
2121
this.operatorIdentity = operatorIdentity;

src/main/java/com/uid2/operator/model/RefreshResponse.java renamed to src/main/java/com/uid2/operator/model/TokenRefreshResponse.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,32 @@
22

33
import java.time.Duration;
44

5-
public class RefreshResponse {
6-
7-
public static final RefreshResponse Invalid = new RefreshResponse(Status.Invalid,
8-
IdentityResponse.OptOutIdentityResponse);
9-
public static final RefreshResponse Optout = new RefreshResponse(Status.Optout, IdentityResponse.OptOutIdentityResponse);
10-
public static final RefreshResponse Expired = new RefreshResponse(Status.Expired, IdentityResponse.OptOutIdentityResponse);
11-
public static final RefreshResponse Deprecated = new RefreshResponse(Status.Deprecated, IdentityResponse.OptOutIdentityResponse);
12-
public static final RefreshResponse NoActiveKey = new RefreshResponse(Status.NoActiveKey, IdentityResponse.OptOutIdentityResponse);
5+
public class TokenRefreshResponse {
6+
7+
public static final TokenRefreshResponse Invalid = new TokenRefreshResponse(Status.Invalid,
8+
IdentityResponse.OptOutResponse);
9+
public static final TokenRefreshResponse Optout = new TokenRefreshResponse(Status.Optout, IdentityResponse.OptOutResponse);
10+
public static final TokenRefreshResponse Expired = new TokenRefreshResponse(Status.Expired, IdentityResponse.OptOutResponse);
11+
public static final TokenRefreshResponse Deprecated = new TokenRefreshResponse(Status.Deprecated, IdentityResponse.OptOutResponse);
12+
public static final TokenRefreshResponse NoActiveKey = new TokenRefreshResponse(Status.NoActiveKey, IdentityResponse.OptOutResponse);
1313
private final Status status;
1414
private final IdentityResponse identityResponse;
1515
private final Duration durationSinceLastRefresh;
1616
private final boolean isCstg;
1717

18-
private RefreshResponse(Status status, IdentityResponse identityResponse, Duration durationSinceLastRefresh, boolean isCstg) {
18+
private TokenRefreshResponse(Status status, IdentityResponse identityResponse, Duration durationSinceLastRefresh, boolean isCstg) {
1919
this.status = status;
2020
this.identityResponse = identityResponse;
2121
this.durationSinceLastRefresh = durationSinceLastRefresh;
2222
this.isCstg = isCstg;
2323
}
2424

25-
private RefreshResponse(Status status, IdentityResponse identityResponse) {
25+
private TokenRefreshResponse(Status status, IdentityResponse identityResponse) {
2626
this(status, identityResponse, null, false);
2727
}
2828

29-
public static RefreshResponse createRefreshedResponse(IdentityResponse identityResponse, Duration durationSinceLastRefresh, boolean isCstg) {
30-
return new RefreshResponse(Status.Refreshed, identityResponse, durationSinceLastRefresh, isCstg);
29+
public static TokenRefreshResponse createRefreshedResponse(IdentityResponse identityResponse, Duration durationSinceLastRefresh, boolean isCstg) {
30+
return new TokenRefreshResponse(Status.Refreshed, identityResponse, durationSinceLastRefresh, isCstg);
3131
}
3232

3333
public Status getStatus() {

src/main/java/com/uid2/operator/model/VersionedToken.java renamed to src/main/java/com/uid2/operator/model/VersionedTokenRequest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
package com.uid2.operator.model;
22

33
import java.time.Instant;
4-
import java.util.Objects;
4+
55
import com.uid2.shared.model.TokenVersion;
66

77

8-
public abstract class VersionedToken {
8+
public abstract class VersionedTokenRequest {
99
public final TokenVersion version;
1010
public final Instant createdAt;
1111
public final Instant expiresAt;
1212

13-
public VersionedToken(TokenVersion version, Instant createdAt, Instant expiresAt) {
13+
public VersionedTokenRequest(TokenVersion version, Instant createdAt, Instant expiresAt) {
1414
this.version = version;
1515
this.createdAt = createdAt;
1616
this.expiresAt = expiresAt;

src/main/java/com/uid2/operator/monitoring/TokenResponseStatsCollector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.uid2.operator.monitoring;
22

3-
import com.uid2.operator.model.RefreshResponse;
3+
import com.uid2.operator.model.TokenRefreshResponse;
44
import com.uid2.operator.vertx.UIDOperatorVerticle;
55
import com.uid2.shared.model.TokenVersion;
66
import com.uid2.shared.store.ISiteStore;
@@ -69,7 +69,7 @@ private static void recordInternal(ISiteStore siteStore, Integer siteId, Endpoin
6969
builder.register(Metrics.globalRegistry).increment();
7070
}
7171

72-
public static void recordRefresh(ISiteStore siteStore, Integer siteId, Endpoint endpoint, RefreshResponse refreshResponse, PlatformType platformType) {
72+
public static void recordRefresh(ISiteStore siteStore, Integer siteId, Endpoint endpoint, TokenRefreshResponse refreshResponse, PlatformType platformType) {
7373
if (!refreshResponse.isRefreshed()) {
7474
if (refreshResponse.isOptOut() || refreshResponse.isDeprecated()) {
7575
recordInternal(siteStore, siteId, endpoint, ResponseStatus.OptOut, refreshResponse.getIdentityResponse().getAdvertisingTokenVersion(), refreshResponse.isCstg(), platformType);

src/main/java/com/uid2/operator/service/EncryptedTokenEncoder.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private byte[] encodeIntoAdvertisingTokenV3(AdvertisingTokenRequest t, KeysetKey
7878
}
7979

8080
@Override
81-
public RefreshTokenRequest decodeRefreshToken(String s) {
81+
public TokenRefreshRequest decodeRefreshToken(String s) {
8282
if (s != null && !s.isEmpty()) {
8383
final byte[] bytes;
8484
try {
@@ -97,7 +97,7 @@ public RefreshTokenRequest decodeRefreshToken(String s) {
9797
throw new ClientInputValidationException("Invalid refresh token version");
9898
}
9999

100-
private RefreshTokenRequest decodeRefreshTokenV2(Buffer b) {
100+
private TokenRefreshRequest decodeRefreshTokenV2(Buffer b) {
101101
final Instant createdAt = Instant.ofEpochMilli(b.getLong(1));
102102
//final Instant expiresAt = Instant.ofEpochMilli(b.getLong(9));
103103
final Instant validTill = Instant.ofEpochMilli(b.getLong(17));
@@ -125,7 +125,7 @@ private RefreshTokenRequest decodeRefreshTokenV2(Buffer b) {
125125
final PrivacyBits privacyBits = PrivacyBits.fromInt(b2.getInt(8 + length));
126126
final long establishedMillis = b2.getLong(8 + length + 4);
127127

128-
return new RefreshTokenRequest(
128+
return new TokenRefreshRequest(
129129
TokenVersion.V2, createdAt, validTill,
130130
new OperatorIdentity(0, OperatorType.Service, 0, 0),
131131
new SourcePublisher(siteId),
@@ -134,7 +134,7 @@ private RefreshTokenRequest decodeRefreshTokenV2(Buffer b) {
134134
privacyBits);
135135
}
136136

137-
private RefreshTokenRequest decodeRefreshTokenV3(Buffer b, byte[] bytes) {
137+
private TokenRefreshRequest decodeRefreshTokenV3(Buffer b, byte[] bytes) {
138138
final int keyId = b.getInt(2);
139139
final KeysetKey key = this.keyManager.getKey(keyId);
140140

@@ -162,7 +162,7 @@ private RefreshTokenRequest decodeRefreshTokenV3(Buffer b, byte[] bytes) {
162162
throw new ClientInputValidationException("Failed to decode refreshTokenV3: Identity type mismatch");
163163
}
164164

165-
return new RefreshTokenRequest(
165+
return new TokenRefreshRequest(
166166
TokenVersion.V3, createdAt, expiresAt, operatorIdentity, sourcePublisher,
167167
new FirstLevelHashIdentity(identityScope, identityType, firstLevelHash, establishedAt),
168168
privacyBits);
@@ -289,7 +289,7 @@ private void recordRefreshTokenVersionCount(String siteId, TokenVersion tokenVer
289289
.register(Metrics.globalRegistry).increment();
290290
}
291291

292-
public byte[] encodeIntoRefreshToken(RefreshTokenRequest t, Instant asOf) {
292+
public byte[] encodeIntoRefreshToken(TokenRefreshRequest t, Instant asOf) {
293293
final KeysetKey serviceKey = this.keyManager.getRefreshKey(asOf);
294294

295295
switch (t.version) {
@@ -304,7 +304,7 @@ public byte[] encodeIntoRefreshToken(RefreshTokenRequest t, Instant asOf) {
304304
}
305305
}
306306

307-
public byte[] encodeIntoRefreshTokenV2(RefreshTokenRequest t, KeysetKey serviceKey) {
307+
public byte[] encodeIntoRefreshTokenV2(TokenRefreshRequest t, KeysetKey serviceKey) {
308308
final Buffer b = Buffer.buffer();
309309
b.appendByte((byte) t.version.rawVersion);
310310
b.appendLong(t.createdAt.toEpochMilli());
@@ -318,7 +318,7 @@ public byte[] encodeIntoRefreshTokenV2(RefreshTokenRequest t, KeysetKey serviceK
318318
return b.getBytes();
319319
}
320320

321-
public byte[] encodeIntoRefreshTokenV3(RefreshTokenRequest t, KeysetKey serviceKey) {
321+
public byte[] encodeIntoRefreshTokenV3(TokenRefreshRequest t, KeysetKey serviceKey) {
322322
final Buffer refreshPayload = Buffer.buffer(90);
323323
refreshPayload.appendLong(t.expiresAt.toEpochMilli());
324324
refreshPayload.appendLong(t.createdAt.toEpochMilli());
@@ -351,21 +351,21 @@ public static String bytesToBase64Token(byte[] advertisingTokenBytes, TokenVersi
351351
}
352352

353353
@Override
354-
public IdentityResponse encodeIntoIdentityResponse(AdvertisingTokenRequest advertisingTokenRequest, RefreshTokenRequest refreshTokenRequest, Instant refreshFrom, Instant asOf) {
354+
public IdentityResponse encodeIntoIdentityResponse(AdvertisingTokenRequest advertisingTokenRequest, TokenRefreshRequest tokenRefreshRequest, Instant refreshFrom, Instant asOf) {
355355
final String advertisingToken = generateAdvertisingTokenString(advertisingTokenRequest, asOf);
356-
final String refreshToken = generateRefreshTokenString(refreshTokenRequest, asOf);
356+
final String refreshToken = generateRefreshTokenString(tokenRefreshRequest, asOf);
357357
return new IdentityResponse(
358358
advertisingToken,
359359
advertisingTokenRequest.version,
360360
refreshToken,
361361
advertisingTokenRequest.expiresAt,
362-
refreshTokenRequest.expiresAt,
362+
tokenRefreshRequest.expiresAt,
363363
refreshFrom
364364
);
365365
}
366366

367-
private String generateRefreshTokenString(RefreshTokenRequest refreshTokenRequest, Instant asOf) {
368-
return EncodingUtils.toBase64String(encodeIntoRefreshToken(refreshTokenRequest, asOf));
367+
private String generateRefreshTokenString(TokenRefreshRequest tokenRefreshRequest, Instant asOf) {
368+
return EncodingUtils.toBase64String(encodeIntoRefreshToken(tokenRefreshRequest, asOf));
369369
}
370370

371371
private String generateAdvertisingTokenString(AdvertisingTokenRequest advertisingTokenRequest, Instant asOf) {

src/main/java/com/uid2/operator/service/ITokenEncoder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import com.uid2.operator.model.AdvertisingTokenRequest;
44
import com.uid2.operator.model.IdentityResponse;
5-
import com.uid2.operator.model.RefreshTokenRequest;
5+
import com.uid2.operator.model.TokenRefreshRequest;
66

77
import java.time.Instant;
88

99
public interface ITokenEncoder {
10-
IdentityResponse encodeIntoIdentityResponse(AdvertisingTokenRequest advertisingTokenRequest, RefreshTokenRequest refreshTokenRequest, Instant refreshFrom, Instant asOf);
10+
IdentityResponse encodeIntoIdentityResponse(AdvertisingTokenRequest advertisingTokenRequest, TokenRefreshRequest tokenRefreshRequest, Instant refreshFrom, Instant asOf);
1111

1212
AdvertisingTokenRequest decodeAdvertisingToken(String base64String);
1313

14-
RefreshTokenRequest decodeRefreshToken(String base64String);
14+
TokenRefreshRequest decodeRefreshToken(String base64String);
1515
}

0 commit comments

Comments
 (0)