HHH-12614 Respect the protection domain when proxying classes
This commit is contained in:
parent
20bdd991c5
commit
c9f5bc920a
|
@ -37,6 +37,8 @@ public class BasicProxyFactoryImpl implements BasicProxyFactory {
|
|||
throw new AssertionFailure( "attempting to build proxy without any superclass or interfaces" );
|
||||
}
|
||||
|
||||
Class<?> superClassOrMainInterface = superClass != null ? superClass : interfaces[0];
|
||||
|
||||
Set<Class> key = new HashSet<Class>();
|
||||
if ( superClass != null ) {
|
||||
key.add( superClass );
|
||||
|
@ -55,7 +57,7 @@ public class BasicProxyFactoryImpl implements BasicProxyFactory {
|
|||
.implement( ProxyConfiguration.class )
|
||||
.intercept( FieldAccessor.ofField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME ).withAssigner( Assigner.DEFAULT, Assigner.Typing.DYNAMIC ) )
|
||||
.make()
|
||||
.load( BasicProxyFactory.class.getClassLoader(), ByteBuddyState.getLoadingStrategy() )
|
||||
.load( superClassOrMainInterface.getClassLoader(), ByteBuddyState.resolveClassLoadingStrategy( superClassOrMainInterface ) )
|
||||
.getLoaded();
|
||||
}
|
||||
|
||||
|
|
|
@ -24,11 +24,6 @@ public final class ByteBuddyState {
|
|||
*/
|
||||
private static final ByteBuddy buddy = new ByteBuddy().with( TypeValidation.DISABLED );
|
||||
|
||||
/**
|
||||
* This will need to change depending on the runtime JDK.
|
||||
*/
|
||||
private static final ClassLoadingStrategy loadingStrategy = new ClassLoadingStrategy.ForUnsafeInjection();
|
||||
|
||||
/**
|
||||
* This currently needs to be static: the BytecodeProvider is a static field of Environment and
|
||||
* is being accessed from static methods.
|
||||
|
@ -81,8 +76,8 @@ public final class ByteBuddyState {
|
|||
return buddy;
|
||||
}
|
||||
|
||||
public static ClassLoadingStrategy getLoadingStrategy() {
|
||||
return loadingStrategy;
|
||||
public static ClassLoadingStrategy<?> resolveClassLoadingStrategy(Class<?> originalClass) {
|
||||
return new ClassLoadingStrategy.ForUnsafeInjection( originalClass.getProtectionDomain() );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@ public class BytecodeProviderImpl implements BytecodeProvider {
|
|||
.method( newInstanceMethodName )
|
||||
.intercept( MethodCall.construct( constructor ) )
|
||||
.make()
|
||||
.load( clazz.getClassLoader(), ByteBuddyState.getLoadingStrategy() )
|
||||
.load( clazz.getClassLoader(), ByteBuddyState.resolveClassLoadingStrategy( clazz ) )
|
||||
.getLoaded();
|
||||
|
||||
final Class bulkAccessor = bytebuddy.getCurrentyByteBuddy()
|
||||
|
@ -80,7 +80,7 @@ public class BytecodeProviderImpl implements BytecodeProvider {
|
|||
.method( getPropertyNamesMethodName )
|
||||
.intercept( MethodCall.call( new CloningPropertyCall( getterNames ) ) )
|
||||
.make()
|
||||
.load( clazz.getClassLoader(), ByteBuddyState.getLoadingStrategy() )
|
||||
.load( clazz.getClassLoader(), ByteBuddyState.resolveClassLoadingStrategy( clazz ) )
|
||||
.getLoaded();
|
||||
|
||||
try {
|
||||
|
|
|
@ -113,7 +113,7 @@ public class ByteBuddyProxyFactory implements ProxyFactory, Serializable {
|
|||
.implement( ProxyConfiguration.class )
|
||||
.intercept( FieldAccessor.ofField( ProxyConfiguration.INTERCEPTOR_FIELD_NAME ).withAssigner( Assigner.DEFAULT, Assigner.Typing.DYNAMIC ) )
|
||||
.make()
|
||||
.load( persistentClass.getClassLoader(), ByteBuddyState.getLoadingStrategy() )
|
||||
.load( persistentClass.getClassLoader(), ByteBuddyState.resolveClassLoadingStrategy( persistentClass ) )
|
||||
.getLoaded(), cacheForProxies );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue