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

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

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


##########
hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/security/authentication/util/SubjectUtil.java:
##########
@@ -335,9 +397,31 @@ public static <T> T doAs(
   /**
    * Maps to Subject.current() if available, otherwise maps to 
Subject.getSubject().
    *
+   * <p>On JDK 22+ also consults the Hadoop-managed
+   * {@link #CURRENT_SUBJECT_TL InheritableThreadLocal} so that platform 
Threads which
+   * inherited a Subject from a parent's {@link #callAs} scope continue to 
observe it.
+   * The JDK API {@code Subject.current()} (backed by {@code ScopedValue}) is 
consulted
+   * first, so any future virtual-thread / {@code StructuredTaskScope} usage 
that propagates
+   * the {@code ScopedValue} keeps working without falling back to the TLS 
layer.
+   *
    * @return the current subject
    */
   public static Subject current() {
+    if (!THREAD_INHERITS_SUBJECT) {
+      // Prefer the JDK ScopedValue source of truth (forward-compatible with 
virtual threads
+      // forked through StructuredTaskScope, which DO propagate ScopedValue).
+      Subject fromJdk = invokeJdkCurrent();
+      if (fromJdk != null) {
+        return fromJdk;
+      }
+      // Fallback: the Hadoop InheritableThreadLocal cascade for platform 
Threads that inherited
+      // a Subject at construction time but are no longer inside any callAs 
scope themselves.
+      return CURRENT_SUBJECT_TL.get();

Review Comment:
   @K0K0V0K thank you for comments, I added two line logs in this method, how 
about now?
   





> 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