![JAR search and dependency download from the Maven repository](/logo.png)
org.apache.hadoop.security.AsSubjectInvoker Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hadoop-apache2 Show documentation
Show all versions of hadoop-apache2 Show documentation
Shaded version of Apache Hadoop 2.x for Presto
The newest version!
package org.apache.hadoop.security;
import com.facebook.presto.hadoop.$internal.com.facebook.presto.hadoop.$internal.com.facebook.presto.hadoop.$internal.org.apache.avro.reflect.Nullable;
import javax.security.auth.Subject;
import java.security.PrivilegedActionException;
import java.util.ArrayDeque;
import java.util.Deque;
class AsSubjectInvoker
{
private static ThreadLocal> SUBJECT_STACKS = new ThreadLocal>()
{
@Override
protected Deque initialValue()
{
return new ArrayDeque<>();
}
};
@Nullable
public static Subject getCurrentUser()
{
return subjectStack().peek();
}
private static Deque subjectStack()
{
return SUBJECT_STACKS.get();
}
public static T doAs(Subject subject, SubjectPrivilegedAction action)
{
subjectStack().push(subject);
try {
return action.run();
}
finally {
subjectStack().pop();
}
}
public static T doAs(Subject subject, SubjectPrivilegedExceptionAction action)
throws PrivilegedActionException
{
subjectStack().push(subject);
try {
return action.run();
}
catch (PrivilegedActionException e) {
throw e;
}
catch (Exception e) {
throw new PrivilegedActionException(e);
}
finally {
subjectStack().pop();
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy