yadavay-amzn commented on code in PR #57140: URL: https://github.com/apache/spark/pull/57140#discussion_r3549443869
########## 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"); + this.issuedAt = issuedAt; + this.expiresAt = expiresAt; + } + + /** Returns the {@code sub} claim (principal identifier). */ + public String getPrincipal() { + return principal; + } + + /** Returns the {@code iss} claim (token issuer). */ + public String getIssuer() { + return issuer; + } + + /** Returns the raw OIDC JWT. This value must never be logged or transmitted to executors. */ + @JsonIgnore Review Comment: You're right, there's no reachable JSON path, so this is just being defensive against a path that doesn't exist. Removed both annotations. -- 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]
