From 56a29af496dcdc6bd31ac3c6c2ce2286565ffcc9 Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Mon, 27 Aug 2018 17:22:15 +0200 Subject: [PATCH] HHH-12931 Revert "HHH-12542 - Add necessary privileged action blocks for SecurityManager used on WildFly." This reverts commit d24685de6776d5df9eb7cdb08bbb96c1ca40c60c. --- .../boot/cfgxml/internal/ConfigLoader.java | 47 +++---- .../boot/jaxb/internal/AbstractBinder.java | 14 +- .../internal/ClassLoaderServiceImpl.java | 130 +++++++----------- .../hibernate/internal/util/ConfigHelper.java | 45 +++--- .../internal/util/ReflectHelper.java | 128 +++++------------ .../internal/CallbackBuilderLegacyImpl.java | 17 +-- .../metamodel/internal/MetadataContext.java | 27 +--- .../tuple/entity/PojoEntityTuplizer.java | 45 +++--- .../reader/AuditedPropertiesReader.java | 30 +--- 9 files changed, 153 insertions(+), 330 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/ConfigLoader.java b/hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/ConfigLoader.java index 1485347c9f..ab094f769b 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/ConfigLoader.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/cfgxml/internal/ConfigLoader.java @@ -12,8 +12,6 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Properties; import org.hibernate.boot.cfgxml.spi.LoadedConfig; @@ -50,34 +48,27 @@ public class ConfigLoader { } public LoadedConfig loadConfigXmlResource(String cfgXmlResourceName) { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public JaxbCfgHibernateConfiguration run() { - final InputStream stream = bootstrapServiceRegistry.getService( ClassLoaderService.class ).locateResourceStream( cfgXmlResourceName ); - if ( stream == null ) { - throw new ConfigurationException( "Could not locate cfg.xml resource [" + cfgXmlResourceName + "]" ); - } + final InputStream stream = bootstrapServiceRegistry.getService( ClassLoaderService.class ).locateResourceStream( cfgXmlResourceName ); + if ( stream == null ) { + throw new ConfigurationException( "Could not locate cfg.xml resource [" + cfgXmlResourceName + "]" ); + } - try { - return jaxbProcessorHolder.getValue().unmarshal( - stream, - new Origin( SourceType.RESOURCE, cfgXmlResourceName ) - ); - } - finally { - try { - stream.close(); - } - catch ( IOException e ) { - log.debug( "Unable to close cfg.xml resource stream", e ); - } - } + try { + final JaxbCfgHibernateConfiguration jaxbCfg = jaxbProcessorHolder.getValue().unmarshal( + stream, + new Origin( SourceType.RESOURCE, cfgXmlResourceName ) + ); + + return LoadedConfig.consume( jaxbCfg ); + } + finally { + try { + stream.close(); } - }; - - return LoadedConfig.consume( - System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run() - ); + catch (IOException e) { + log.debug( "Unable to close cfg.xml resource stream", e ); + } + } } public LoadedConfig loadConfigXmlFile(File cfgXmlFile) { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/AbstractBinder.java b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/AbstractBinder.java index 8f5ffd919d..79ef80e060 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/AbstractBinder.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/jaxb/internal/AbstractBinder.java @@ -7,9 +7,6 @@ package org.hibernate.boot.jaxb.internal; import java.io.InputStream; -import java.security.AccessController; -import java.security.PrivilegedAction; - import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; @@ -101,15 +98,8 @@ public abstract class AbstractBinder implements Binder { private Binding doBind(XMLEventReader eventReader, Origin origin) { try { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public Binding run() { - final StartElement rootElementStartEvent = seekRootElementStartEvent( eventReader, origin ); - return doBind( eventReader, rootElementStartEvent, origin ); - } - }; - - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + final StartElement rootElementStartEvent = seekRootElementStartEvent( eventReader, origin ); + return doBind( eventReader, rootElementStartEvent, origin ); } finally { try { diff --git a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java index c1f7fa3df1..fd4deff3f3 100644 --- a/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/boot/registry/classloading/internal/ClassLoaderServiceImpl.java @@ -83,16 +83,11 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { orderedClassLoaderSet.add( ClassLoaderServiceImpl.class.getClassLoader() ); // now build the aggregated class loader... - final PrivilegedAction action = new PrivilegedAction() { - @Override + this.aggregatedClassLoader = AccessController.doPrivileged( new PrivilegedAction() { public AggregatedClassLoader run() { return new AggregatedClassLoader( orderedClassLoaderSet, lookupPrecedence ); } - }; - - this.aggregatedClassLoader = System.getSecurityManager() != null - ? AccessController.doPrivileged( action ) - : action.run(); + } ); } /** @@ -352,62 +347,49 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { @Override @SuppressWarnings({"unchecked"}) public Class classForName(String className) { - final PrivilegedAction> action = new PrivilegedAction>() { - @Override - public Class run() { - try { - return (Class) Class.forName( className, true, getAggregatedClassLoader() ); - } - catch (Exception e) { - throw new ClassLoadingException( "Unable to load class [" + className + "]", e ); - } - catch (LinkageError e) { - throw new ClassLoadingException( "Unable to load class [" + className + "]", e ); - } - } - }; - - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + try { + return (Class) Class.forName( className, true, getAggregatedClassLoader() ); + } + catch (Exception e) { + throw new ClassLoadingException( "Unable to load class [" + className + "]", e ); + } + catch (LinkageError e) { + throw new ClassLoadingException( "Unable to load class [" + className + "]", e ); + } } @Override - public URL locateResource(final String name) { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public URL run() { - try { - return new URL( name ); - } - catch (Exception ignore) { - } + public URL locateResource(String name) { + // first we try name as a URL + try { + return new URL( name ); + } + catch (Exception ignore) { + } - try { - final URL url = getAggregatedClassLoader().getResource( name ); - if ( url != null ) { - return url; - } - } - catch (Exception ignore) { - } - - if ( name.startsWith( "/" ) ) { - final String resourceName = name.substring( 1 ); - - try { - final URL url = getAggregatedClassLoader().getResource( resourceName ); - if ( url != null ) { - return url; - } - } - catch (Exception ignore) { - } - } - - return null; + try { + final URL url = getAggregatedClassLoader().getResource( name ); + if ( url != null ) { + return url; } - }; + } + catch (Exception ignore) { + } - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + if ( name.startsWith( "/" ) ) { + name = name.substring( 1 ); + + try { + final URL url = getAggregatedClassLoader().getResource( name ); + if ( url != null ) { + return url; + } + } + catch (Exception ignore) { + } + } + + return null; } @Override @@ -474,22 +456,16 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { @Override @SuppressWarnings("unchecked") public Collection loadJavaServices(Class serviceContract) { - final PrivilegedAction> action = new PrivilegedAction>() { - @Override - public Collection run() { - ServiceLoader serviceLoader = serviceLoaders.get( serviceContract ); - if ( serviceLoader == null ) { - serviceLoader = ServiceLoader.load( serviceContract, getAggregatedClassLoader() ); - serviceLoaders.put( serviceContract, serviceLoader ); - } - final LinkedHashSet services = new LinkedHashSet(); - for ( S service : serviceLoader ) { - services.add( service ); - } - return services; - } - }; - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + ServiceLoader serviceLoader = serviceLoaders.get( serviceContract ); + if ( serviceLoader == null ) { + serviceLoader = ServiceLoader.load( serviceContract, getAggregatedClassLoader() ); + serviceLoaders.put( serviceContract, serviceLoader ); + } + final LinkedHashSet services = new LinkedHashSet(); + for ( S service : serviceLoader ) { + services.add( service ); + } + return services; } @Override @@ -504,13 +480,7 @@ public class ClassLoaderServiceImpl implements ClassLoaderService { @Override public T workWithClassLoader(Work work) { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public T run() { - return work.doWork( getAggregatedClassLoader() ); - } - }; - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + return work.doWork( getAggregatedClassLoader() ); } private ClassLoader getAggregatedClassLoader() { diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/ConfigHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/ConfigHelper.java index a3383bde86..f87581521c 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/ConfigHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/ConfigHelper.java @@ -10,8 +10,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedAction; import org.hibernate.HibernateException; import org.hibernate.cfg.Environment; @@ -115,33 +113,28 @@ public final class ConfigHelper { } public static InputStream getResourceAsStream(String resource) { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public InputStream run() { - String stripped = resource.startsWith( "/" ) - ? resource.substring( 1 ) - : resource; + String stripped = resource.startsWith( "/" ) + ? resource.substring( 1 ) + : resource; - InputStream stream = null; - ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - if ( classLoader != null ) { - stream = classLoader.getResourceAsStream( stripped ); - } - if ( stream == null ) { - stream = Environment.class.getResourceAsStream( resource ); - } - if ( stream == null ) { - stream = Environment.class.getClassLoader().getResourceAsStream( stripped ); - } - if ( stream == null ) { - throw new HibernateException( resource + " not found" ); - } - return stream; - } - }; - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + InputStream stream = null; + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + if ( classLoader != null ) { + stream = classLoader.getResourceAsStream( stripped ); + } + if ( stream == null ) { + stream = Environment.class.getResourceAsStream( resource ); + } + if ( stream == null ) { + stream = Environment.class.getClassLoader().getResourceAsStream( stripped ); + } + if ( stream == null ) { + throw new HibernateException( resource + " not found" ); + } + return stream; } + public static InputStream getUserResourceAsStream(String resource) { boolean hasLeadingSlash = resource.startsWith( "/" ); String stripped = hasLeadingSlash ? resource.substring( 1 ) : resource; diff --git a/hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java b/hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java index b192252ad5..4fbff725c4 100644 --- a/hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/internal/util/ReflectHelper.java @@ -13,8 +13,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Member; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Locale; import java.util.regex.Pattern; import javax.persistence.Transient; @@ -237,14 +235,7 @@ public final class ReflectHelper { } private static Getter getter(Class clazz, String name) throws MappingException { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public Getter run() { - return PropertyAccessStrategyMixedImpl.INSTANCE.buildPropertyAccess( clazz, name ).getGetter(); - } - }; - - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + return PropertyAccessStrategyMixedImpl.INSTANCE.buildPropertyAccess( clazz, name ).getGetter(); } public static Object getConstantValue(String name, SessionFactoryImplementor factory) { @@ -281,23 +272,16 @@ public final class ReflectHelper { return null; } - final PrivilegedAction action = new PrivilegedAction() { - @Override - public Constructor run() { - try { - Constructor constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE ); - ensureAccessibility( constructor ); - return constructor; - } - catch (NoSuchMethodException e) { - throw new PropertyNotFoundException( - "Object class [" + clazz.getName() + "] must declare a default (no-argument) constructor" - ); - } - } - }; - - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + try { + Constructor constructor = clazz.getDeclaredConstructor( NO_PARAM_SIGNATURE ); + ensureAccessibility( constructor ); + return constructor; + } + catch ( NoSuchMethodException nme ) { + throw new PropertyNotFoundException( + "Object class [" + clazz.getName() + "] must declare a default (no-argument) constructor" + ); + } } /** @@ -364,19 +348,12 @@ public final class ReflectHelper { } public static Method getMethod(Class clazz, Method method) { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public Method run() { - try { - return clazz.getMethod( method.getName(), method.getParameterTypes() ); - } - catch (Exception e){ - return null; - } - } - }; - - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + try { + return clazz.getMethod( method.getName(), method.getParameterTypes() ); + } + catch (Exception e) { + return null; + } } public static Field findField(Class containerClass, String propertyName) { @@ -387,14 +364,8 @@ public final class ReflectHelper { throw new IllegalArgumentException( "Illegal attempt to locate field [" + propertyName + "] on Object.class" ); } - final PrivilegedAction action = new PrivilegedAction() { - @Override - public Field run() { - return locateField( containerClass, propertyName ); - } - }; + Field field = locateField( containerClass, propertyName ); - final Field field = System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); if ( field == null ) { throw new PropertyNotFoundException( String.format( @@ -412,22 +383,11 @@ public final class ReflectHelper { } public static void ensureAccessibility(AccessibleObject accessibleObject) { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public Object run() { - if ( !accessibleObject.isAccessible() ) { - accessibleObject.setAccessible( true ); - } - return null; - } - }; + if ( accessibleObject.isAccessible() ) { + return; + } - if ( System.getSecurityManager() != null ) { - AccessController.doPrivileged( action ); - } - else { - action.run(); - } + accessibleObject.setAccessible( true ); } private static Field locateField(Class clazz, String propertyName) { @@ -502,7 +462,7 @@ public final class ReflectHelper { } private static Method getGetterOrNull(Class containerClass, String propertyName) { - for ( Method method : getDeclaredMethods( containerClass ) ) { + for ( Method method : containerClass.getDeclaredMethods() ) { // if the method has parameters, skip it if ( method.getParameterCount() != 0 ) { continue; @@ -553,39 +513,17 @@ public final class ReflectHelper { String propertyName, Method getMethod, String stemName) { - final Method isMethod = getDeclaredMethod( containerClass, "is" + stemName ); - if ( isMethod != null ) { + // verify that the Class does not also define a method with the same stem name with 'is' + try { + final Method isMethod = containerClass.getDeclaredMethod( "is" + stemName ); if ( !Modifier.isStatic( isMethod.getModifiers() ) && isMethod.getAnnotation( Transient.class ) == null ) { // No such method should throw the caught exception. So if we get here, there was // such a method. checkGetAndIsVariants( containerClass, propertyName, getMethod, isMethod ); } } - } - - private static Method getDeclaredMethod(Class containerClass, String methodName) { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public Method run() { - try { - return containerClass.getDeclaredMethod( methodName ); - } - catch (NoSuchMethodException ignore) { - return null; - } - } - }; - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); - } - - private static Method[] getDeclaredMethods(Class containerClass) { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public Method[] run() { - return containerClass.getDeclaredMethods(); - } - }; - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + catch (NoSuchMethodException ignore) { + } } private static void checkGetAndIsVariants( @@ -616,14 +554,16 @@ public final class ReflectHelper { Method isMethod, String stemName) { // verify that the Class does not also define a method with the same stem name with 'is' - final Method getMethod = getDeclaredMethod( containerClass, "get" + stemName ); - if ( getMethod != null ) { + try { + final Method getMethod = containerClass.getDeclaredMethod( "get" + stemName ); // No such method should throw the caught exception. So if we get here, there was // such a method. if ( !Modifier.isStatic( getMethod.getModifiers() ) && getMethod.getAnnotation( Transient.class ) == null ) { checkGetAndIsVariants( containerClass, propertyName, getMethod, isMethod ); } } + catch (NoSuchMethodException ignore) { + } } public static Method getterMethodOrNull(Class containerJavaType, String propertyName) { @@ -691,7 +631,7 @@ public final class ReflectHelper { private static Method setterOrNull(Class theClass, String propertyName, Class propertyType) { Method potentialSetter = null; - for ( Method method : getDeclaredMethods( theClass ) ) { + for ( Method method : theClass.getDeclaredMethods() ) { final String methodName = method.getName(); if ( method.getParameterCount() == 1 && methodName.startsWith( "set" ) ) { final String testOldMethod = methodName.substring( 3 ); @@ -716,7 +656,7 @@ public final class ReflectHelper { * as an abstract - but again, that is such an edge case... */ public static Method findGetterMethodForFieldAccess(Field field, String propertyName) { - for ( Method method : getDeclaredMethods( field.getDeclaringClass() ) ) { + for ( Method method : field.getDeclaringClass().getDeclaredMethods() ) { // if the method has parameters, skip it if ( method.getParameterCount() != 0 ) { continue; diff --git a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackBuilderLegacyImpl.java b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackBuilderLegacyImpl.java index 42da63f82d..1a6851ba3c 100644 --- a/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackBuilderLegacyImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/jpa/event/internal/CallbackBuilderLegacyImpl.java @@ -10,8 +10,6 @@ import java.lang.annotation.Annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Target; import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.List; import javax.persistence.Entity; @@ -74,7 +72,6 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder { } continue; } - final Callback[] callbacks = resolveEntityCallbacks( entityXClass, callbackType, reflectionManager ); callbackRegistrar.registerCallbacks( entityClass, callbacks ); } @@ -122,7 +119,7 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder { final boolean debugEnabled = log.isDebugEnabled(); do { Callback callback = null; - List methods = getDeclaredMethods( currentClazz ); + List methods = currentClazz.getDeclaredMethods(); for ( final XMethod xMethod : methods ) { if ( xMethod.isAnnotationPresent( callbackType.getCallbackAnnotation() ) ) { Method method = reflectionManager.toMethod( xMethod ); @@ -193,7 +190,7 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder { if ( listener != null ) { XClass xListener = reflectionManager.toXClass( listener ); callbacksMethodNames = new ArrayList<>(); - List methods = getDeclaredMethods( xListener ); + List methods = xListener.getDeclaredMethods(); for ( final XMethod xMethod : methods ) { if ( xMethod.isAnnotationPresent( callbackType.getCallbackAnnotation() ) ) { final Method method = reflectionManager.toMethod( xMethod ); @@ -341,14 +338,4 @@ public class CallbackBuilderLegacyImpl implements CallbackBuilder { } } } - - private static List getDeclaredMethods(XClass clazz) { - final PrivilegedAction> action = new PrivilegedAction>() { - @Override - public List run() { - return clazz.getDeclaredMethods(); - } - }; - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); - } } diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java index 1012c391c1..e97fdad691 100755 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/internal/MetadataContext.java @@ -7,8 +7,6 @@ package org.hibernate.metamodel.internal; import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -378,26 +376,13 @@ class MetadataContext { return; } final String metamodelClassName = managedTypeClass.getName() + '_'; - - final PrivilegedAction action = new PrivilegedAction() { - @Override - public Object run() { - try { - final Class metamodelClass = Class.forName( metamodelClassName, true, managedTypeClass.getClassLoader() ); - // we found the class; so populate it... - registerAttributes( metamodelClass, managedType ); - } - catch (ClassNotFoundException ignore) { - // nothing to do... - } - return null; - } - }; - if ( System.getSecurityManager() != null ) { - AccessController.doPrivileged( action ); + try { + final Class metamodelClass = Class.forName( metamodelClassName, true, managedTypeClass.getClassLoader() ); + // we found the class; so populate it... + registerAttributes( metamodelClass, managedType ); } - else { - action.run(); + catch (ClassNotFoundException ignore) { + // nothing to do... } // todo : this does not account for @MappeSuperclass, mainly because this is not being tracked in our diff --git a/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java b/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java index 6efd27b543..f186e8a384 100644 --- a/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java +++ b/hibernate-core/src/main/java/org/hibernate/tuple/entity/PojoEntityTuplizer.java @@ -8,8 +8,6 @@ package org.hibernate.tuple.entity; import java.lang.reflect.Method; import java.lang.reflect.Modifier; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Iterator; import java.util.Map; import java.util.Set; @@ -159,31 +157,24 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer { null : ReflectHelper.getMethod( proxyInterface, idSetterMethod ); - final PrivilegedAction action = new PrivilegedAction() { - @Override - public ProxyFactory run() { - ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter ); - try { - pf.postInstantiate( - getEntityName(), - mappedClass, - proxyInterfaces, - proxyGetIdentifierMethod, - proxySetIdentifierMethod, - persistentClass.hasEmbeddedIdentifier() ? - (CompositeType) persistentClass.getIdentifier().getType() : - null - ); - } - catch (HibernateException he) { - LOG.unableToCreateProxyFactory( getEntityName(), he ); - pf = null; - } - return pf; - } - }; - - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); + ProxyFactory pf = buildProxyFactoryInternal( persistentClass, idGetter, idSetter ); + try { + pf.postInstantiate( + getEntityName(), + mappedClass, + proxyInterfaces, + proxyGetIdentifierMethod, + proxySetIdentifierMethod, + persistentClass.hasEmbeddedIdentifier() ? + (CompositeType) persistentClass.getIdentifier().getType() : + null + ); + } + catch (HibernateException he) { + LOG.unableToCreateProxyFactory( getEntityName(), he ); + pf = null; + } + return pf; } protected ProxyFactory buildProxyFactoryInternal( diff --git a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java index a1d2859215..3ddffe0a46 100644 --- a/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java +++ b/hibernate-envers/src/main/java/org/hibernate/envers/configuration/internal/metadata/reader/AuditedPropertiesReader.java @@ -7,8 +7,6 @@ package org.hibernate.envers.configuration.internal.metadata.reader; import java.lang.annotation.Annotation; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; @@ -49,7 +47,6 @@ import org.hibernate.loader.PropertyPath; import org.hibernate.mapping.Component; import org.hibernate.mapping.Property; import org.hibernate.mapping.Value; - import org.jboss.logging.Logger; import static org.hibernate.envers.internal.tools.Tools.newHashMap; @@ -357,47 +354,26 @@ public class AuditedPropertiesReader { //look in the class addFromProperties( - getPropertiesFromClassByType( clazz, AccessType.FIELD ), + clazz.getDeclaredProperties( "field" ), it -> "field", fieldAccessedPersistentProperties, allClassAudited ); - addFromProperties( - getPropertiesFromClassByType( clazz, AccessType.PROPERTY ), + clazz.getDeclaredProperties( "property" ), propertyAccessedPersistentProperties::get, propertyAccessedPersistentProperties.keySet(), allClassAudited ); if ( allClassAudited != null || !auditedPropertiesHolder.isEmpty() ) { - final PrivilegedAction action = new PrivilegedAction() { - @Override - public XClass run() { - return clazz.getSuperclass(); - } - }; - - final XClass superclazz = System.getSecurityManager() != null - ? AccessController.doPrivileged( action ) - : action.run(); - + final XClass superclazz = clazz.getSuperclass(); if ( !clazz.isInterface() && !"java.lang.Object".equals( superclazz.getName() ) ) { addPropertiesFromClass( superclazz ); } } } - private Iterable getPropertiesFromClassByType(XClass clazz, AccessType accessType) { - final PrivilegedAction> action = new PrivilegedAction>() { - @Override - public Iterable run() { - return clazz.getDeclaredProperties( accessType.getType() ); - } - }; - return System.getSecurityManager() != null ? AccessController.doPrivileged( action ) : action.run(); - } - private void addFromProperties( Iterable properties, Function accessTypeProvider,