yadavay-amzn commented on code in PR #57140:
URL: https://github.com/apache/spark/pull/57140#discussion_r3549504315


##########
core/src/main/java/org/apache/spark/security/UserContext.java:
##########
@@ -0,0 +1,139 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.spark.security;
+
+import java.time.Instant;
+import java.util.Objects;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
+import org.apache.spark.annotation.DeveloperApi;
+
+/**
+ * :: DeveloperApi ::
+ * Represents the authenticated user's identity context on the driver side.
+ * <p>
+ * This class holds the OIDC token information used to derive short-lived
+ * {@link ServiceCredential} instances via credential providers. It is 
intentionally
+ * <b>not</b> {@link java.io.Serializable} and must never be transmitted to 
executors.
+ * The {@code rawToken} field is always redacted in {@link #toString()} and 
excluded from
+ * Jackson serialization.
+ *
+ * @since 4.3.0
+ */
+@DeveloperApi
+public final class UserContext {
+
+  private final String principal;
+  private final String issuer;
+  @JsonIgnore
+  private final String rawToken;
+  private final Instant issuedAt;
+  private final Instant expiresAt;
+
+  /**
+   * Constructs a new {@code UserContext}.
+   *
+   * @param principal the {@code sub} claim from the JWT (must not be null)
+   * @param issuer the {@code iss} claim from the JWT (must not be null)
+   * @param rawToken the raw OIDC JWT string (must not be null)
+   * @param issuedAt token issue time (may be null)
+   * @param expiresAt token expiry time (may be null)
+   */
+  public UserContext(
+      String principal,
+      String issuer,
+      String rawToken,
+      Instant issuedAt,
+      Instant expiresAt) {
+    this.principal = Objects.requireNonNull(principal, "principal must not be 
null");
+    this.issuer = Objects.requireNonNull(issuer, "issuer must not be null");
+    this.rawToken = Objects.requireNonNull(rawToken, "rawToken must not be 
null");

Review Comment:
   Makes sense - I was considering to remove it while implementing as well. 
   
   Excluded `rawToken` from both `equals()` and `hashCode()`. The identity 
fields (principal, issuer) plus the validity window now define equality. 
   I also updated the test to assert two contexts differing only by rawToken 
compare equal. 
   Happy to add `isIdenticalToken(...)` later if an exact-token comparison is 
ever needed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to