HHH-10349 : PersistenceUtilHelper should call getDeclaredField/Method inside of privileged block
This commit is contained in:
parent
62fd52ad59
commit
986b2b65ad
|
@ -10,6 +10,8 @@ import java.io.Serializable;
|
|||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -342,24 +344,29 @@ public final class PersistenceUtilHelper {
|
|||
return attributeAccess;
|
||||
}
|
||||
|
||||
private AttributeAccess buildAttributeAccess(String attributeName) {
|
||||
for ( Class clazz : classHierarchy ) {
|
||||
try {
|
||||
final Field field = clazz.getDeclaredField( attributeName );
|
||||
if ( field != null ) {
|
||||
return new FieldAttributeAccess( field );
|
||||
private AttributeAccess buildAttributeAccess(final String attributeName) {
|
||||
final PrivilegedAction<AttributeAccess> action = new PrivilegedAction<AttributeAccess>() {
|
||||
@Override
|
||||
public AttributeAccess run() {
|
||||
for ( Class clazz : classHierarchy ) {
|
||||
try {
|
||||
final Field field = clazz.getDeclaredField( attributeName );
|
||||
if ( field != null ) {
|
||||
return new FieldAttributeAccess( field );
|
||||
}
|
||||
}
|
||||
catch ( NoSuchFieldException e ) {
|
||||
final Method method = getMethod( clazz, attributeName );
|
||||
if ( method != null ) {
|
||||
return new MethodAttributeAccess( attributeName, method );
|
||||
}
|
||||
}
|
||||
}
|
||||
//we could not find any match
|
||||
return new NoSuchAttributeAccess( specifiedClass, attributeName );
|
||||
}
|
||||
catch ( NoSuchFieldException e ) {
|
||||
final Method method = getMethod( clazz, attributeName );
|
||||
if ( method != null ) {
|
||||
return new MethodAttributeAccess( attributeName, method );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//we could not find any match
|
||||
return new NoSuchAttributeAccess( specifiedClass, attributeName );
|
||||
};
|
||||
return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue