Skip to content

Commit 07766a2

Browse files
Added operator environment in remote config and removed from UserIdentity
1 parent 758ddf2 commit 07766a2

19 files changed

Lines changed: 268 additions & 163 deletions

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,7 @@ public class Config extends com.uid2.shared.Const.Config {
3636
public static final String DisableOptoutTokenProp = "disable_optout_token";
3737
public static final String EnableRemoteConfigProp = "enable_remote_config";
3838
public static final String RuntimeConfigMetadataPathProp = "runtime_config_metadata_path";
39+
40+
public static final String IdentityEnvironmentProp = "identity_environment";
3941
}
4042
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@ public final class IdentityRequest {
44
public final PublisherIdentity publisherIdentity;
55
public final UserIdentity userIdentity;
66
public final OptoutCheckPolicy optoutCheckPolicy;
7+
public final IdentityEnvironment identityEnvironment;
78

89
public IdentityRequest(
910
PublisherIdentity publisherIdentity,
1011
UserIdentity userIdentity,
11-
OptoutCheckPolicy tokenGeneratePolicy)
12+
OptoutCheckPolicy tokenGeneratePolicy,
13+
IdentityEnvironment identityEnvironment)
1214
{
1315
this.publisherIdentity = publisherIdentity;
1416
this.userIdentity = userIdentity;
1517
this.optoutCheckPolicy = tokenGeneratePolicy;
18+
this.identityEnvironment = identityEnvironment;
1619
}
1720

1821
public boolean shouldCheckOptOut() {

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44

55
public final class MapRequest {
66
public final UserIdentity userIdentity;
7+
public final IdentityEnvironment identityEnvironment;
78
public final OptoutCheckPolicy optoutCheckPolicy;
89
public final Instant asOf;
910

1011
public MapRequest(
1112
UserIdentity userIdentity,
13+
IdentityEnvironment identityEnvironment,
1214
OptoutCheckPolicy optoutCheckPolicy,
1315
Instant asOf)
1416
{
1517
this.userIdentity = userIdentity;
18+
this.identityEnvironment = identityEnvironment;
1619
this.optoutCheckPolicy = optoutCheckPolicy;
1720
this.asOf = asOf;
1821
}

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@
66
public class UserIdentity {
77
public final IdentityScope identityScope;
88
public final IdentityType identityType;
9-
public final IdentityEnvironment identityEnvironment;
109
public final byte[] id;
1110
public final int privacyBits;
1211
public final Instant establishedAt;
1312
public final Instant refreshedAt;
1413

15-
public UserIdentity(IdentityScope identityScope, IdentityType identityType, IdentityEnvironment identityEnvironment,
14+
public UserIdentity(IdentityScope identityScope, IdentityType identityType,
1615
byte[] id, int privacyBits,
1716
Instant establishedAt, Instant refreshedAt) {
1817
this.identityScope = identityScope;
1918
this.identityType = identityType;
20-
this.identityEnvironment = identityEnvironment;
2119
this.id = id;
2220
this.privacyBits = privacyBits;
2321
this.establishedAt = establishedAt;
@@ -27,7 +25,6 @@ public UserIdentity(IdentityScope identityScope, IdentityType identityType, Iden
2725
public boolean matches(UserIdentity that) {
2826
return this.identityScope.equals(that.identityScope) &&
2927
this.identityType.equals(that.identityType) &&
30-
this.identityEnvironment.equals(that.identityEnvironment) &&
3128
Arrays.equals(this.id, that.id);
3229
}
3330
}

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
public class EncryptedTokenEncoder implements ITokenEncoder {
1919
private final KeyManager keyManager;
20-
private final IdentityEnvironment identityEnvironment;
21-
22-
public EncryptedTokenEncoder(KeyManager keyManager, IdentityEnvironment identityEnvironment) {
20+
public EncryptedTokenEncoder(KeyManager keyManager) {
2321
this.keyManager = keyManager;
24-
this.identityEnvironment = identityEnvironment;
2522
}
2623

2724
public byte[] encode(AdvertisingToken t, Instant asOf) {
@@ -126,7 +123,7 @@ private RefreshToken decodeRefreshTokenV2(Buffer b) {
126123
TokenVersion.V2, createdAt, validTill,
127124
new OperatorIdentity(0, OperatorType.Service, 0, 0),
128125
new PublisherIdentity(siteId, 0, 0),
129-
new UserIdentity(IdentityScope.UID2, IdentityType.Email, this.identityEnvironment, identity, privacyBits, Instant.ofEpochMilli(establishedMillis), null));
126+
new UserIdentity(IdentityScope.UID2, IdentityType.Email, identity, privacyBits, Instant.ofEpochMilli(establishedMillis), null));
130127
}
131128

132129
private RefreshToken decodeRefreshTokenV3(Buffer b, byte[] bytes) {
@@ -148,6 +145,7 @@ private RefreshToken decodeRefreshTokenV3(Buffer b, byte[] bytes) {
148145
final Instant establishedAt = Instant.ofEpochMilli(b2.getLong(49));
149146
final IdentityScope identityScope = decodeIdentityScopeV3(b2.getByte(57));
150147
final IdentityType identityType = decodeIdentityTypeV3(b2.getByte(57));
148+
151149
final byte[] id = b2.getBytes(58, 90);
152150

153151
if (identityScope != decodeIdentityScopeV3(b.getByte(0))) {
@@ -159,7 +157,7 @@ private RefreshToken decodeRefreshTokenV3(Buffer b, byte[] bytes) {
159157

160158
return new RefreshToken(
161159
TokenVersion.V3, createdAt, expiresAt, operatorIdentity, publisherIdentity,
162-
new UserIdentity(identityScope, identityType, this.identityEnvironment, id, privacyBits, establishedAt, null));
160+
new UserIdentity(identityScope, identityType, id, privacyBits, establishedAt, null));
163161
}
164162

165163
@Override
@@ -227,7 +225,7 @@ public AdvertisingToken decodeAdvertisingTokenV2(Buffer b) {
227225
Instant.ofEpochMilli(expiresMillis),
228226
new OperatorIdentity(0, OperatorType.Service, 0, masterKeyId),
229227
new PublisherIdentity(siteId, siteKeyId, 0),
230-
new UserIdentity(IdentityScope.UID2, IdentityType.Email, this.identityEnvironment, advertisingId, privacyBits, Instant.ofEpochMilli(establishedMillis), null)
228+
new UserIdentity(IdentityScope.UID2, IdentityType.Email, advertisingId, privacyBits, Instant.ofEpochMilli(establishedMillis), null)
231229
);
232230

233231
} catch (Exception e) {
@@ -265,7 +263,7 @@ public AdvertisingToken decodeAdvertisingTokenV3orV4(Buffer b, byte[] bytes, Tok
265263

266264
return new AdvertisingToken(
267265
tokenVersion, createdAt, expiresAt, operatorIdentity, publisherIdentity,
268-
new UserIdentity(identityScope, identityType, this.identityEnvironment, id, privacyBits, establishedAt, refreshedAt)
266+
new UserIdentity(identityScope, identityType, id, privacyBits, establishedAt, refreshedAt)
269267
);
270268
}
271269

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@
1212
public interface IUIDOperatorService {
1313
IdentityTokens generateIdentity(IdentityRequest request, Duration refreshIdentityAfter, Duration refreshExpiresAfter, Duration identityExpiresAfter);
1414

15-
RefreshResponse refreshIdentity(RefreshToken token, Duration refreshIdentityAfter, Duration refreshExpiresAfter, Duration identityExpiresAfter);
15+
RefreshResponse refreshIdentity(RefreshToken token, Duration refreshIdentityAfter, Duration refreshExpiresAfter, Duration identityExpiresAfter, IdentityEnvironment identityEnvironment);
1616

1717
MappedIdentity mapIdentity(MapRequest request);
1818

1919
@Deprecated
20-
MappedIdentity map(UserIdentity userIdentity, Instant asOf);
20+
MappedIdentity map(UserIdentity userIdentity, Instant asOf, IdentityEnvironment identityEnvironment);
2121

2222
List<SaltEntry> getModifiedBuckets(Instant sinceTimestamp);
2323

24-
void invalidateTokensAsync(UserIdentity userIdentity, Instant asOf, String uidTraceId, Handler<AsyncResult<Instant>> handler);
24+
void invalidateTokensAsync(UserIdentity userIdentity, Instant asOf, String uidTraceId, IdentityEnvironment identityEnvironment, Handler<AsyncResult<Instant>> handler);
2525

26-
boolean advertisingTokenMatches(String advertisingToken, UserIdentity userIdentity, Instant asOf);
26+
boolean advertisingTokenMatches(String advertisingToken, UserIdentity userIdentity, Instant asOf, IdentityEnvironment identityEnvironment);
2727
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,11 +264,10 @@ public boolean isValid() {
264264
return valid;
265265
}
266266

267-
public UserIdentity toUserIdentity(IdentityScope identityScope, IdentityEnvironment identityEnvironment, int privacyBits, Instant establishedAt) {
267+
public UserIdentity toUserIdentity(IdentityScope identityScope, int privacyBits, Instant establishedAt) {
268268
return new UserIdentity(
269269
identityScope,
270270
this.identityType,
271-
identityEnvironment,
272271
getIdentityInput(),
273272
privacyBits,
274273
establishedAt,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public static byte encodeIdentityType(IdentityType identityType) {
6969
return (byte) (identityType.value << 2);
7070
}
7171

72-
public static byte encodeIdentityVersion(IdentityVersion identityVersion) { return (byte) (identityVersion.value << 6); }
72+
public static byte encodeIdentityVersion(IdentityVersion identityVersion) { return (byte) (identityVersion.value << 5); }
7373

74-
public static byte encodeIdentityEnvironment(IdentityEnvironment identityEnvironment) { return (byte) (identityEnvironment.value); }
74+
public static byte encodeIdentityEnvironment(IdentityEnvironment identityEnvironment) { return (byte) (identityEnvironment.value << 6); }
7575
}

0 commit comments

Comments
 (0)