HHH-15655 use privileged operation when defining classes

Signed-off-by: Scott Marlow <smarlow@redhat.com>
This commit is contained in:
Scott Marlow 2022-10-31 15:30:59 -04:00 committed by Christian Beikov
parent 11b968a2ee
commit 8f2325ed4a
1 changed files with 18 additions and 4 deletions

View File

@ -192,10 +192,24 @@ public final class ByteBuddyState {
return cache.findOrInsert(
referenceClass.getClassLoader(),
cacheKey,
() -> make( makeProxyFunction.apply( byteBuddy ) )
.load( referenceClass.getClassLoader(), resolveClassLoadingStrategy( referenceClass ) )
.getLoaded(),
cache );
() -> {
PrivilegedAction<Class<?>> delegateToPrivilegedAction = new PrivilegedAction<Class<?>>() {
@Override
public Class<?> run() {
return make( makeProxyFunction.apply( byteBuddy ) )
.load(
referenceClass.getClassLoader(),
resolveClassLoadingStrategy( referenceClass )
)
.getLoaded();
}
};
return SystemSecurityManager.isSecurityManagerEnabled() ? AccessController.doPrivileged(
delegateToPrivilegedAction ) :
delegateToPrivilegedAction.run();
},
cache
);
}
public Unloaded<?> make(Function<ByteBuddy, DynamicType.Builder<?>> makeProxyFunction) {