[ 
https://issues.apache.org/jira/browse/HADOOP-19906?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18091372#comment-18091372
 ] 

ASF GitHub Bot commented on HADOOP-19906:
-----------------------------------------

pan3793 commented on code in PR #8522:
URL: https://github.com/apache/hadoop/pull/8522#discussion_r3471553724


##########
hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/util/TestSubjectPropagation.java:
##########
@@ -0,0 +1,179 @@
+/**
+ * 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.hadoop.security.authentication.util;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+
+import org.junit.jupiter.api.Test;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicReference;
+import javax.security.auth.Subject;
+
+/**
+ * Verifies the JDK22+ Subject-propagation cascade restored by the
+ * {@link InheritableThreadLocal}-based mechanism in
+ * {@link SubjectUtil#callAs(Subject, java.util.concurrent.Callable)}.
+ *
+ * <p>The mechanism relies solely on Hadoop's own InheritableThreadLocal layer 
and
+ * the JVM's standard {@code Thread.<init>}-time {@code 
InheritableThreadLocal} copy.
+ * No special {@code Thread} subclass is required: any platform thread ({@link 
Thread},
+ * {@link java.util.concurrent.ForkJoinWorkerThread}, Netty's
+ * {@code FastThreadLocalThread}, …) constructed inside a {@code 
SubjectUtil.callAs}
+ * scope inherits the active Subject and observes it via {@link 
SubjectUtil#current()}.
+ */
+public class TestSubjectPropagation {
+
+  /** Plain Thread inside callAs sees parent's Subject via 
SubjectUtil.current(). */
+  @Test
+  public void testPlainThreadInheritsSubjectViaSubjectUtilCallAs() {
+    Subject parent = new Subject();
+    AtomicReference<Subject> seen = new AtomicReference<>();
+    SubjectUtil.callAs(parent, () -> {
+      Thread t = new Thread(() -> seen.set(SubjectUtil.current()), 
"plain-child");
+      t.start();
+      t.join(50000);
+      return null;
+    });
+    assertEquals(parent, seen.get(),

Review Comment:
   updated





> Alternative to SubjectInheritingThread to restore Subject propagation
> ---------------------------------------------------------------------
>
>                 Key: HADOOP-19906
>                 URL: https://issues.apache.org/jira/browse/HADOOP-19906
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: security
>    Affects Versions: 3.5.0, 3.4.3
>            Reporter: Cheng Pan
>            Priority: Major
>              Labels: pull-request-available
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to