1111import lombok .Getter ;
1212import okhttp3 .Request ;
1313import okhttp3 .RequestBody ;
14+ import org .junit .platform .commons .logging .Logger ;
15+ import org .junit .platform .commons .logging .LoggerFactory ;
1416
1517import javax .crypto .*;
1618import javax .crypto .spec .GCMParameterSpec ;
@@ -68,6 +70,7 @@ private record V2Envelope(String envelope, byte[] nonce) {
6870 // When running via IntelliJ, environment variables are defined in the uid2-dev-workspace repo under .idea/runConfigurations.
6971 // Test data is defined in the uid2-admin repo.
7072
73+ private static final Logger LOGGER = LoggerFactory .getLogger (Operator .class );
7174 private static final ObjectMapper OBJECT_MAPPER = Mapper .getInstance ();
7275 private static final SecureRandom SECURE_RANDOM = new SecureRandom ();
7376 private static final int TIMESTAMP_LENGTH = 8 ;
@@ -78,6 +81,27 @@ private record V2Envelope(String envelope, byte[] nonce) {
7881
7982 public static final String CLIENT_API_KEY = EnvUtil .getEnv (Const .Config .Operator .CLIENT_API_KEY );
8083 public static final String CLIENT_API_SECRET = EnvUtil .getEnv (Const .Config .Operator .CLIENT_API_SECRET );
84+
85+ static {
86+ // Log operator configuration at class initialization
87+ String maskedKey = CLIENT_API_KEY != null && CLIENT_API_KEY .length () > 20
88+ ? CLIENT_API_KEY .substring (0 , 10 ) + "..." + CLIENT_API_KEY .substring (CLIENT_API_KEY .length () - 10 )
89+ : "[null or too short]" ;
90+ String maskedSecret = CLIENT_API_SECRET != null && CLIENT_API_SECRET .length () > 20
91+ ? CLIENT_API_SECRET .substring (0 , 10 ) + "..." + CLIENT_API_SECRET .substring (CLIENT_API_SECRET .length () - 10 )
92+ : "[null or too short]" ;
93+ LOGGER .info (() -> String .format (
94+ "[OPERATOR CONFIG] Initialized with:%n" +
95+ " CLIENT_API_KEY: %s (length: %d)%n" +
96+ " CLIENT_API_SECRET: %s (length: %d)%n" +
97+ " E2E_ENV: %s%n" +
98+ " IDENTITY_SCOPE: %s" ,
99+ maskedKey , CLIENT_API_KEY != null ? CLIENT_API_KEY .length () : 0 ,
100+ maskedSecret , CLIENT_API_SECRET != null ? CLIENT_API_SECRET .length () : 0 ,
101+ EnvUtil .getEnv (Const .Config .ENV , false ),
102+ EnvUtil .getEnv (Const .Config .IDENTITY_SCOPE , false )
103+ ));
104+ }
81105
82106 // Local only - Sharing
83107 public static final String CLIENT_API_KEY_SHARING_RECIPIENT = EnvUtil .getEnv (Const .Config .Operator .CLIENT_API_KEY_SHARING_RECIPIENT , EnabledCondition .isLocal ());
@@ -274,9 +298,55 @@ public IdentityMapResponse v2IdentityMap(IdentityMapInput input) {
274298
275299 // Need to use the manual mapping for error cases - SDK won't allow creating input with bad emails
276300 public JsonNode v3IdentityMap (String payload ) throws Exception {
301+ String baseUrl = getBaseUrl ();
302+ String endpoint = baseUrl + "/v3/identity/map" ;
303+
304+ LOGGER .info (() -> String .format (
305+ "[v3IdentityMap] Preparing request:%n" +
306+ " Operator Name: %s%n" +
307+ " Operator Type: %s%n" +
308+ " Base URL: %s%n" +
309+ " Full Endpoint: %s%n" +
310+ " CLIENT_API_KEY: %s (length: %d)%n" +
311+ " CLIENT_API_SECRET: %s (length: %d)%n" +
312+ " Payload (raw): %s" ,
313+ getName (), type , baseUrl , endpoint ,
314+ CLIENT_API_KEY != null ? CLIENT_API_KEY .substring (0 , Math .min (20 , CLIENT_API_KEY .length ())) + "..." : "[null]" ,
315+ CLIENT_API_KEY != null ? CLIENT_API_KEY .length () : 0 ,
316+ CLIENT_API_SECRET != null ? CLIENT_API_SECRET .substring (0 , Math .min (20 , CLIENT_API_SECRET .length ())) + "..." : "[null]" ,
317+ CLIENT_API_SECRET != null ? CLIENT_API_SECRET .length () : 0 ,
318+ payload != null && payload .length () > 200 ? payload .substring (0 , 200 ) + "..." : payload
319+ ));
320+
277321 V2Envelope envelope = v2CreateEnvelope (payload , CLIENT_API_SECRET );
278- String encryptedResponse = HttpClient .post (getBaseUrl () + "/v3/identity/map" , envelope .envelope (), CLIENT_API_KEY );
279- return v2DecryptEncryptedResponse (encryptedResponse , envelope .nonce (), CLIENT_API_SECRET );
322+
323+ LOGGER .info (() -> String .format (
324+ "[v3IdentityMap] Created envelope:%n" +
325+ " Envelope length: %d%n" +
326+ " Nonce length: %d" ,
327+ envelope .envelope ().length (),
328+ envelope .nonce ().length
329+ ));
330+
331+ try {
332+ String encryptedResponse = HttpClient .post (endpoint , envelope .envelope (), CLIENT_API_KEY );
333+ LOGGER .info (() -> String .format (
334+ "[v3IdentityMap] Request successful, response length: %d" ,
335+ encryptedResponse != null ? encryptedResponse .length () : 0
336+ ));
337+ return v2DecryptEncryptedResponse (encryptedResponse , envelope .nonce (), CLIENT_API_SECRET );
338+ } catch (Exception e ) {
339+ final String errorMsg = e .getMessage ();
340+ final String errorType = e .getClass ().getName ();
341+ LOGGER .error (() -> String .format (
342+ "[v3IdentityMap] Request failed:%n" +
343+ " Endpoint: %s%n" +
344+ " Error: %s%n" +
345+ " Error Type: %s" ,
346+ endpoint , errorMsg , errorType
347+ ));
348+ throw e ;
349+ }
280350 }
281351
282352 public IdentityMapV3Response v3IdentityMap (IdentityMapV3Input input ) {
0 commit comments