HHH-15371 ByteBuddyProxyFactory call to proxyClass.getConstructor().newInstance() when used with Java Security Manager should run in a privileged action
Signed-off-by: Scott Marlow <smarlow@redhat.com>
This commit is contained in:
parent
fbd7fe000e
commit
deb2c52ab4
|
@ -8,6 +8,8 @@ package org.hibernate.proxy.pojo.bytebuddy;
|
|||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
@ -85,11 +87,24 @@ public class ByteBuddyProxyFactory implements ProxyFactory, Serializable {
|
|||
overridesEquals
|
||||
);
|
||||
|
||||
try {
|
||||
final HibernateProxy proxy = (HibernateProxy) proxyClass.getConstructor().newInstance();
|
||||
|
||||
final HibernateProxy proxy = getHibernateProxy();
|
||||
( (ProxyConfiguration) proxy ).$$_hibernate_set_interceptor( interceptor );
|
||||
|
||||
return proxy;
|
||||
|
||||
}
|
||||
|
||||
private HibernateProxy getHibernateProxy()
|
||||
throws HibernateException {
|
||||
|
||||
final PrivilegedAction<HibernateProxy> action = new PrivilegedAction<HibernateProxy>() {
|
||||
|
||||
@Override
|
||||
public HibernateProxy run() {
|
||||
|
||||
try {
|
||||
return (HibernateProxy) proxyClass.getConstructor().newInstance();
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
String logMessage = LOG.bytecodeEnhancementFailedBecauseOfDefaultConstructor( entityName );
|
||||
|
@ -101,5 +116,10 @@ public class ByteBuddyProxyFactory implements ProxyFactory, Serializable {
|
|||
LOG.error( logMessage, t );
|
||||
throw new HibernateException( logMessage, t );
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue