mirror of
https://github.com/hibernate/hibernate-orm
synced 2025-02-18 00:55:16 +00:00
HHH-5289 remove unnecessary security checks in property accessors
This commit is contained in:
parent
945463e3fe
commit
f58968c0a2
@ -69,9 +69,7 @@ public static void validateFactory(Object object) {
|
|||||||
final Class activatorClass = BeanValidationIntegrator.class.getClassLoader().loadClass( ACTIVATOR_CLASS_NAME );
|
final Class activatorClass = BeanValidationIntegrator.class.getClassLoader().loadClass( ACTIVATOR_CLASS_NAME );
|
||||||
try {
|
try {
|
||||||
final Method validateMethod = activatorClass.getMethod( VALIDATE_SUPPLIED_FACTORY_METHOD_NAME, Object.class );
|
final Method validateMethod = activatorClass.getMethod( VALIDATE_SUPPLIED_FACTORY_METHOD_NAME, Object.class );
|
||||||
if ( ! validateMethod.isAccessible() ) {
|
validateMethod.setAccessible( true );
|
||||||
validateMethod.setAccessible( true );
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
validateMethod.invoke( null, object );
|
validateMethod.invoke( null, object );
|
||||||
}
|
}
|
||||||
|
@ -303,9 +303,7 @@ public static <T> Constructor<T> getDefaultConstructor(Class<T> clazz) throws Pr
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Constructor<T> constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE );
|
Constructor<T> constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE );
|
||||||
if ( !isPublic( clazz, constructor ) ) {
|
constructor.setAccessible( true );
|
||||||
constructor.setAccessible( true );
|
|
||||||
}
|
|
||||||
return constructor;
|
return constructor;
|
||||||
}
|
}
|
||||||
catch ( NoSuchMethodException nme ) {
|
catch ( NoSuchMethodException nme ) {
|
||||||
@ -363,9 +361,7 @@ public static Constructor getConstructor(Class clazz, Type[] types) throws Prope
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( found ) {
|
if ( found ) {
|
||||||
if ( !isPublic( clazz, constructor ) ) {
|
constructor.setAccessible( true );
|
||||||
constructor.setAccessible( true );
|
|
||||||
}
|
|
||||||
return constructor;
|
return constructor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -260,7 +260,7 @@ private static BasicSetter getSetterOrNull(Class theClass, String propertyName)
|
|||||||
Method method = setterMethod(theClass, propertyName);
|
Method method = setterMethod(theClass, propertyName);
|
||||||
|
|
||||||
if (method!=null) {
|
if (method!=null) {
|
||||||
if ( !ReflectHelper.isPublic(theClass, method) ) method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
return new BasicSetter(theClass, method, propertyName);
|
return new BasicSetter(theClass, method, propertyName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -325,9 +325,7 @@ private static BasicGetter getGetterOrNull(Class theClass, String propertyName)
|
|||||||
Method method = getterMethod(theClass, propertyName);
|
Method method = getterMethod(theClass, propertyName);
|
||||||
|
|
||||||
if (method!=null) {
|
if (method!=null) {
|
||||||
if ( !ReflectHelper.isPublic( theClass, method ) ) {
|
method.setAccessible(true);
|
||||||
method.setAccessible(true);
|
|
||||||
}
|
|
||||||
return new BasicGetter(theClass, method, propertyName);
|
return new BasicGetter(theClass, method, propertyName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -157,7 +157,7 @@ private static Field getField(Class clazz, String name) throws PropertyNotFoundE
|
|||||||
catch (NoSuchFieldException nsfe) {
|
catch (NoSuchFieldException nsfe) {
|
||||||
field = getField( clazz, clazz.getSuperclass(), name );
|
field = getField( clazz, clazz.getSuperclass(), name );
|
||||||
}
|
}
|
||||||
if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,7 +172,7 @@ private static Field getField(Class root, Class clazz, String name) throws Prope
|
|||||||
catch (NoSuchFieldException nsfe) {
|
catch (NoSuchFieldException nsfe) {
|
||||||
field = getField( root, clazz.getSuperclass(), name );
|
field = getField( root, clazz.getSuperclass(), name );
|
||||||
}
|
}
|
||||||
if ( !ReflectHelper.isPublic(clazz, field) ) field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
return field;
|
return field;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,9 +192,7 @@ public Object invoke(
|
|||||||
returnValue = thisMethod.invoke( target, args );
|
returnValue = thisMethod.invoke( target, args );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if ( !thisMethod.isAccessible() ) {
|
thisMethod.setAccessible( true );
|
||||||
thisMethod.setAccessible( true );
|
|
||||||
}
|
|
||||||
returnValue = thisMethod.invoke( target, args );
|
returnValue = thisMethod.invoke( target, args );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,14 +135,11 @@ private Constructor<? extends ComponentTuplizer> getProperConstructor(Class<? ex
|
|||||||
Constructor<? extends ComponentTuplizer> constructor = null;
|
Constructor<? extends ComponentTuplizer> constructor = null;
|
||||||
try {
|
try {
|
||||||
constructor = clazz.getDeclaredConstructor( COMPONENT_TUP_CTOR_SIG );
|
constructor = clazz.getDeclaredConstructor( COMPONENT_TUP_CTOR_SIG );
|
||||||
if ( ! ReflectHelper.isPublic( constructor ) ) {
|
try {
|
||||||
try {
|
constructor.setAccessible( true );
|
||||||
// found a constructor, but it was not publicly accessible so try to request accessibility
|
}
|
||||||
constructor.setAccessible( true );
|
catch ( SecurityException e ) {
|
||||||
}
|
constructor = null;
|
||||||
catch ( SecurityException e ) {
|
|
||||||
constructor = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( NoSuchMethodException ignore ) {
|
catch ( NoSuchMethodException ignore ) {
|
||||||
|
@ -227,14 +227,11 @@ private Constructor<? extends EntityTuplizer> getProperConstructor(
|
|||||||
Constructor<? extends EntityTuplizer> constructor = null;
|
Constructor<? extends EntityTuplizer> constructor = null;
|
||||||
try {
|
try {
|
||||||
constructor = clazz.getDeclaredConstructor( constructorArgs );
|
constructor = clazz.getDeclaredConstructor( constructorArgs );
|
||||||
if ( ! ReflectHelper.isPublic( constructor ) ) {
|
try {
|
||||||
try {
|
constructor.setAccessible( true );
|
||||||
// found a constructor, but it was not publicly accessible so try to request accessibility
|
}
|
||||||
constructor.setAccessible( true );
|
catch ( SecurityException e ) {
|
||||||
}
|
constructor = null;
|
||||||
catch ( SecurityException e ) {
|
|
||||||
constructor = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( NoSuchMethodException ignore ) {
|
catch ( NoSuchMethodException ignore ) {
|
||||||
|
@ -132,9 +132,7 @@ private Callback createListenerCallback(
|
|||||||
if (argType != Object.class && argType != entityClass) {
|
if (argType != Object.class && argType != entityClass) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (!method.isAccessible()) {
|
method.setAccessible( true );
|
||||||
method.setAccessible( true );
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ListenerCallback( listenerInstance, method );
|
return new ListenerCallback( listenerInstance, method );
|
||||||
}
|
}
|
||||||
@ -151,7 +149,7 @@ private Callback createBeanCallback( Class<?> callbackClass,
|
|||||||
for (Method method : callbackClass.getDeclaredMethods()) {
|
for (Method method : callbackClass.getDeclaredMethods()) {
|
||||||
if (!method.getName().equals(methodName)) continue;
|
if (!method.getName().equals(methodName)) continue;
|
||||||
if (method.getParameterTypes().length != 0) continue;
|
if (method.getParameterTypes().length != 0) continue;
|
||||||
if (!method.isAccessible()) method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
return new EntityCallback(method);
|
return new EntityCallback(method);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
@ -104,7 +104,7 @@ public Callback[] resolveCallbacks(XClass beanClass, Class annotation, Reflectio
|
|||||||
.getName() + " - " + xMethod
|
.getName() + " - " + xMethod
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (!method.isAccessible()) method.setAccessible(true);
|
method.setAccessible(true);
|
||||||
log.debugf("Adding %s as %s callback for entity %s",
|
log.debugf("Adding %s as %s callback for entity %s",
|
||||||
methodName,
|
methodName,
|
||||||
annotation.getSimpleName(),
|
annotation.getSimpleName(),
|
||||||
|
@ -428,10 +428,8 @@ private <X> void registerAttribute(Class metamodelClass, Attribute<X, ?> attribu
|
|||||||
? metamodelClass.getField( name )
|
? metamodelClass.getField( name )
|
||||||
: metamodelClass.getDeclaredField( name );
|
: metamodelClass.getDeclaredField( name );
|
||||||
try {
|
try {
|
||||||
if ( ! field.isAccessible() ) {
|
// should be public anyway, but to be sure...
|
||||||
// should be public anyway, but to be sure...
|
field.setAccessible( true );
|
||||||
field.setAccessible( true );
|
|
||||||
}
|
|
||||||
field.set( null, attribute );
|
field.set( null, attribute );
|
||||||
}
|
}
|
||||||
catch ( IllegalAccessException e ) {
|
catch ( IllegalAccessException e ) {
|
||||||
|
@ -83,13 +83,11 @@ private void addBeforeClassOnceCallback(Method method) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void ensureAccessibility(Method method) {
|
private void ensureAccessibility(Method method) {
|
||||||
if ( !method.isAccessible() ) {
|
try {
|
||||||
try {
|
method.setAccessible( true );
|
||||||
method.setAccessible( true );
|
}
|
||||||
}
|
catch (Exception ignored) {
|
||||||
catch (Exception ignored) {
|
// ignore for now
|
||||||
// ignore for now
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,17 +139,15 @@ private void validateCallbackMethod(Method method, CallbackType type, List<Throw
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if ( !method.isAccessible() ) {
|
try {
|
||||||
try {
|
method.setAccessible( true );
|
||||||
method.setAccessible( true );
|
}
|
||||||
}
|
catch (Exception e) {
|
||||||
catch (Exception e) {
|
errors.add(
|
||||||
errors.add(
|
new InvalidMethodForAnnotationException(
|
||||||
new InvalidMethodForAnnotationException(
|
type.buildTypeMarker() + " attached to inaccessible method and unable to make accessible"
|
||||||
type.buildTypeMarker() + " attached to inaccessible method and unable to make accessible"
|
)
|
||||||
)
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user