-
Notifications
You must be signed in to change notification settings - Fork 9.2k
HADOOP-19212 [JDK23] org.apache.hadoop.security.UserGroupInformation … #7434
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
stoty
wants to merge
40
commits into
apache:trunk
Choose a base branch
from
stoty:HADOOP-19212
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,095
−1,160
Draft
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
0234e09
HADOOP-19212 [JDK23] org.apache.hadoop.security.UserGroupInformation …
stoty 4c4bfd6
attempt to fix the Subject propagation nonsense
stoty 92abd64
WIP
stoty 587416e
WIP
stoty 0348287
WIP
stoty 3ed90be
WIP
stoty b2bf827
hack in jabx-impl test dependency
stoty 97c4fde
disable javascript tests
stoty a9c9d70
WIP
stoty 75c2a99
WIP
stoty d8fbc24
still trying to fix inifite recuresion...
stoty ab081a7
revert stuff
stoty 0286a13
wip
stoty bf08fba
wip
stoty db5698c
hpopefully fix rest of subject propagation
stoty 94ff809
fix some missing propagations
stoty 2ba07fc
before reverting most test HadoopThread changes
stoty 8cb3c29
replace most wrap calls with HadoopThread, revert Hadoopthread/wrap u…
stoty e2b5eb6
more HadoopThread
stoty 9fadd0c
moar
stoty 77aaccc
fix
stoty 43791a8
fix jaxb-impl version
stoty 2e277ec
test fixes
stoty 42000c7
fixes
stoty 7663820
fix
stoty 3cea9ec
fix
stoty 4ef0952
fix
stoty f08dbfa
fixes
stoty 42c3fb4
revert log config changes causing Shell test failures
stoty 7ae09ce
partially fix TestPipeApplication
stoty 786b5d6
add missing ASL headers
stoty 1b514f8
handle ip address toString changes in line with existing tests.
stoty 6d73768
revert extra logging in TestMiniMRWithDFSWithDistinctUsers.java
stoty 203a0d0
revert some anonymous classes to lambdas
stoty e2fb719
more HadoopThread changes
stoty be3877f
add -Dsurefire.failIfNoSpecifiedTests=false in hadoop.sh
stoty 3e1436f
add another missing -Dsurefire.failIfNoSpecifiedTests=false
stoty 260373f
fix super().run() calls on HadoopThread sub-subclasses
stoty c6557be
HADOOP-19528. Update Surefire plugin to 3.5.3
stoty 4791067
Add Javadoc links to deprecated methods in UGI and SecurityUtil
stoty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
250 changes: 250 additions & 0 deletions
250
hadoop-common-project/hadoop-auth/src/main/java/org/apache/hadoop/util/SubjectUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,250 @@ | ||
| /** | ||
| * 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.util; | ||
|
|
||
| import java.lang.invoke.MethodHandle; | ||
| import java.lang.invoke.MethodHandles; | ||
| import java.lang.invoke.MethodType; | ||
| import java.lang.reflect.UndeclaredThrowableException; | ||
| import java.security.PrivilegedAction; | ||
| import java.security.PrivilegedActionException; | ||
| import java.security.PrivilegedExceptionAction; | ||
| import java.util.concurrent.Callable; | ||
| import java.util.concurrent.CompletionException; | ||
|
|
||
| import javax.security.auth.Subject; | ||
|
|
||
| import org.apache.hadoop.classification.InterfaceAudience; | ||
|
|
||
| @InterfaceAudience.Private() | ||
| public class SubjectUtil { | ||
| private static final MethodHandle CALL_AS = lookupCallAs(); | ||
| private static final MethodHandle CURRENT = lookupCurrent(); | ||
| private static boolean HAS_CALL_AS = true; | ||
|
|
||
| private SubjectUtil() { | ||
| } | ||
|
|
||
| private static MethodHandle lookupCallAs() { | ||
| MethodHandles.Lookup lookup = MethodHandles.lookup(); | ||
| try { | ||
| try { | ||
| // Subject.doAs() is deprecated for removal and replaced by Subject.callAs(). | ||
| // Lookup first the new API, since for Java versions where both exist, the | ||
| // new API delegates to the old API (for example Java 18, 19 and 20). | ||
| // Otherwise (Java 17), lookup the old API. | ||
| return lookup.findStatic(Subject.class, "callAs", | ||
| MethodType.methodType(Object.class, Subject.class, Callable.class)); | ||
| } catch (NoSuchMethodException x) { | ||
| HAS_CALL_AS = false; | ||
| try { | ||
| // Lookup the old API. | ||
| MethodType oldSignature = MethodType.methodType(Object.class, Subject.class, | ||
| PrivilegedExceptionAction.class); | ||
| MethodHandle doAs = lookup.findStatic(Subject.class, "doAs", oldSignature); | ||
| // Convert the Callable used in the new API to the PrivilegedAction used in the | ||
| // old | ||
| // API. | ||
| MethodType convertSignature = MethodType.methodType(PrivilegedExceptionAction.class, | ||
| Callable.class); | ||
| MethodHandle converter = lookup.findStatic(SubjectUtil.class, "callableToPrivilegedExceptionAction", | ||
| convertSignature); | ||
| return MethodHandles.filterArguments(doAs, 1, converter); | ||
| } catch (NoSuchMethodException e) { | ||
| throw new AssertionError(e); | ||
| } | ||
| } | ||
| } catch (IllegalAccessException e) { | ||
| throw new AssertionError(e); | ||
| } | ||
| } | ||
|
|
||
| private static MethodHandle lookupCurrent() { | ||
| MethodHandles.Lookup lookup = MethodHandles.lookup(); | ||
| try { | ||
| // Subject.getSubject(AccessControlContext) is deprecated for removal and | ||
| // replaced by | ||
| // Subject.current(). | ||
| // Lookup first the new API, since for Java versions where both exists, the | ||
| // new API delegates to the old API (for example Java 18, 19 and 20). | ||
| // Otherwise (Java 17), lookup the old API. | ||
| return lookup.findStatic(Subject.class, "current", MethodType.methodType(Subject.class)); | ||
| } catch (NoSuchMethodException e) { | ||
| MethodHandle getContext = lookupGetContext(); | ||
| MethodHandle getSubject = lookupGetSubject(); | ||
| return MethodHandles.filterReturnValue(getContext, getSubject); | ||
| } catch (IllegalAccessException e) { | ||
| throw new AssertionError(e); | ||
| } | ||
| } | ||
|
|
||
| private static MethodHandle lookupGetSubject() { | ||
| MethodHandles.Lookup lookup = MethodHandles.lookup(); | ||
| try { | ||
| Class<?> contextklass = ClassLoader.getSystemClassLoader().loadClass("java.security.AccessControlContext"); | ||
| return lookup.findStatic(Subject.class, "getSubject", MethodType.methodType(Subject.class, contextklass)); | ||
| } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) { | ||
| throw new AssertionError(e); | ||
| } | ||
| } | ||
|
|
||
| private static MethodHandle lookupGetContext() { | ||
| try { | ||
| // Use reflection to work with Java versions that have and don't have | ||
| // AccessController. | ||
| Class<?> controllerKlass = ClassLoader.getSystemClassLoader().loadClass("java.security.AccessController"); | ||
| Class<?> contextklass = ClassLoader.getSystemClassLoader().loadClass("java.security.AccessControlContext"); | ||
|
|
||
| MethodHandles.Lookup lookup = MethodHandles.lookup(); | ||
| return lookup.findStatic(controllerKlass, "getContext", MethodType.methodType(contextklass)); | ||
| } catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException e) { | ||
| throw new AssertionError(e); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Maps to Subject.callAs() if available, otherwise maps to Subject.doAs(). | ||
| * It also wraps the Callable so that the Subject is propagated to the new thread | ||
| * in all Java versions. | ||
| * | ||
| * @param subject the subject this action runs as | ||
| * @param action the action to run | ||
| * @return the result of the action | ||
| * @param <T> the type of the result | ||
| * @throws CompletionException | ||
| */ | ||
| public static <T> T callAs(Subject subject, Callable<T> action) throws CompletionException { | ||
| try { | ||
| return (T) CALL_AS.invoke(subject, action); | ||
| } catch (PrivilegedActionException e) { | ||
| throw new CompletionException(e.getCause()); | ||
| } catch (Throwable t) { | ||
| throw sneakyThrow(t); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Maps action to a Callable, and delegates to callAs(). On older JVMs, the | ||
| * action may be double wrapped (into Callable, and then back into | ||
| * PrivilegedAction). | ||
| * | ||
| * @param subject the subject this action runs as | ||
| * @param action action the action to run | ||
| * @return the result of the action | ||
| */ | ||
| public static <T> T doAs(Subject subject, PrivilegedAction<T> action) { | ||
| return callAs(subject, privilegedActionToCallable(action)); | ||
| } | ||
|
|
||
| /** | ||
| * Maps action to a Callable, and delegates to callAs(). On older JVMs, the | ||
| * action may be double wrapped (into Callable, and then back into | ||
| * PrivilegedAction). | ||
| * | ||
| * @param subject the subject this action runs as | ||
| * @param action action the action to run | ||
| * @return the result of the action | ||
| */ | ||
| public static <T> T doAs(Subject subject, PrivilegedExceptionAction<T> action) throws PrivilegedActionException { | ||
| try { | ||
| return callAs(subject, privilegedExceptionActionToCallable(action)); | ||
| } catch (CompletionException ce) { | ||
| try { | ||
| Exception cause = (Exception) (ce.getCause()); | ||
| throw new PrivilegedActionException(cause); | ||
| } catch (ClassCastException castException) { | ||
| // This should never happen, as PrivilegedExceptionAction should not wrap | ||
| // non-checked exceptions | ||
| throw new PrivilegedActionException(new UndeclaredThrowableException(ce.getCause())); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Maps to Subject.currect() is available, otherwise maps to | ||
| * Subject.getSubject() | ||
| * | ||
| * @return the current subject | ||
| */ | ||
| public static Subject current() { | ||
| try { | ||
| return (Subject) CURRENT.invoke(); | ||
| } catch (Throwable t) { | ||
| throw sneakyThrow(t); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Wraps Runnable in callAs() to preserve pre-JEP486 behaviour | ||
| * | ||
| * Note that this snapshots the subject at the time wrap() is called. | ||
| * If the subject is changed between calling this and starting the thread, | ||
| * that is going to be ignored. | ||
| * | ||
| * @param r Runnable | ||
| * @return r wrapped in callAs() | ||
| */ | ||
| public static Runnable wrap(Runnable r) { | ||
| if (!HAS_CALL_AS) { | ||
| return r; | ||
| } | ||
| Subject s = current(); | ||
| return () -> callAs(s, () -> { | ||
| r.run(); | ||
| return null; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Wraps Callable in callAs() to preserve pre-JEP486 behaviour | ||
| * | ||
| * Note that this snapshots the subject at the time wrap() is called. | ||
| * If the subject is changed between calling this and starting the thread, | ||
| * that is going to be ignored. | ||
| * | ||
| * @param <T> the return type of the Callable | ||
| * @param c Callable | ||
| * @return c wrapped in callAs() | ||
| */ | ||
| public static <T> Callable<T> wrap(Callable<T> c) { | ||
| if (!HAS_CALL_AS) { | ||
| return c; | ||
| } | ||
| Subject s = current(); | ||
| return () -> callAs(s, () -> c.call()); | ||
| } | ||
|
|
||
| @SuppressWarnings("unused") | ||
| private static <T> PrivilegedExceptionAction<T> callableToPrivilegedExceptionAction(Callable<T> callable) { | ||
| return callable::call; | ||
| } | ||
|
|
||
| private static <T> Callable<T> privilegedExceptionActionToCallable(PrivilegedExceptionAction<T> action) { | ||
| return action::run; | ||
| } | ||
|
|
||
| private static <T> Callable<T> privilegedActionToCallable(PrivilegedAction<T> action) { | ||
| return action::run; | ||
| } | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| private static <E extends Throwable> RuntimeException sneakyThrow(Throwable e) throws E { | ||
| throw (E) e; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my alternate compatibility shim, @steveloughran ( based on Avatica's which is based on Jetty's)