HHH-11615 - Fix Envers to run under WildFly's SecurityManager.
This commit is contained in:
parent
dd2bf67ac9
commit
ed69c7c5b6
|
@ -13,12 +13,10 @@ import java.util.Map;
|
|||
|
||||
import org.hibernate.envers.RevisionType;
|
||||
import org.hibernate.envers.boot.internal.EnversService;
|
||||
import org.hibernate.envers.exception.AuditException;
|
||||
import org.hibernate.envers.internal.entities.mapper.id.IdMapper;
|
||||
import org.hibernate.envers.internal.entities.mapper.relation.lazy.ToOneDelegateSessionImplementor;
|
||||
import org.hibernate.envers.internal.reader.AuditReaderImplementor;
|
||||
import org.hibernate.envers.internal.tools.ReflectionTools;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.proxy.HibernateProxy;
|
||||
import org.hibernate.proxy.LazyInitializer;
|
||||
|
||||
|
@ -78,20 +76,11 @@ public class EntityInstantiator {
|
|||
}
|
||||
|
||||
// If it is not in the cache, creating a new entity instance
|
||||
Object ret;
|
||||
try {
|
||||
EntityConfiguration entCfg = enversService.getEntitiesConfigurations().get( entityName );
|
||||
if ( entCfg == null ) {
|
||||
// a relation marked as RelationTargetAuditMode.NOT_AUDITED
|
||||
entCfg = enversService.getEntitiesConfigurations().getNotVersionEntityConfiguration( entityName );
|
||||
}
|
||||
|
||||
final Class<?> cls = ReflectionTools.loadClass( entCfg.getEntityClassName(), enversService.getClassLoaderService() );
|
||||
ret = ReflectHelper.getDefaultConstructor( cls ).newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
Object ret = versionsReader.getSessionImplementor()
|
||||
.getFactory()
|
||||
.getEntityPersister( entityName )
|
||||
.getEntityTuplizer()
|
||||
.instantiate();
|
||||
|
||||
// Putting the newly created entity instance into the first level cache, in case a one-to-one bidirectional
|
||||
// relation is present (which is eagerly loaded).
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
package org.hibernate.envers.internal.entities.mapper;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -99,12 +101,12 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB
|
|||
|
||||
@Override
|
||||
public void mapToEntityFromMap(
|
||||
EnversService enversService,
|
||||
Object obj,
|
||||
Map data,
|
||||
Object primaryKey,
|
||||
AuditReaderImplementor versionsReader,
|
||||
Number revision) {
|
||||
final EnversService enversService,
|
||||
final Object obj,
|
||||
final Map data,
|
||||
final Object primaryKey,
|
||||
final AuditReaderImplementor versionsReader,
|
||||
final Number revision) {
|
||||
if ( data == null || obj == null ) {
|
||||
return;
|
||||
}
|
||||
|
@ -116,21 +118,17 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB
|
|||
return;
|
||||
}
|
||||
|
||||
final Setter setter = ReflectionTools.getSetter( obj.getClass(), propertyData, enversService.getServiceRegistry() );
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Setter setter = ReflectionTools.getSetter(
|
||||
obj.getClass(),
|
||||
propertyData,
|
||||
enversService.getServiceRegistry()
|
||||
);
|
||||
|
||||
// If all properties are null and single, then the component has to be null also.
|
||||
boolean allNullAndSingle = true;
|
||||
for ( Map.Entry<PropertyData, PropertyMapper> property : delegate.getProperties().entrySet() ) {
|
||||
if ( data.get(
|
||||
property.getKey()
|
||||
.getName()
|
||||
) != null || !( property.getValue() instanceof SinglePropertyMapper ) ) {
|
||||
allNullAndSingle = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( allNullAndSingle ) {
|
||||
if ( isAllPropertiesNull( data ) ) {
|
||||
// single property, but default value need not be null, so we'll set it to null anyway
|
||||
setter.set( obj, null, null );
|
||||
}
|
||||
|
@ -139,12 +137,28 @@ public class ComponentPropertyMapper implements PropertyMapper, CompositeMapperB
|
|||
try {
|
||||
final Object subObj = ReflectHelper.getDefaultConstructor( componentClass ).newInstance();
|
||||
setter.set( obj, subObj, null );
|
||||
|
||||
delegate.mapToEntityFromMap( enversService, subObj, data, primaryKey, versionsReader, revision );
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private boolean isAllPropertiesNull(Map data) {
|
||||
for ( Map.Entry<PropertyData, PropertyMapper> property : delegate.getProperties().entrySet() ) {
|
||||
final Object value = data.get( property.getKey().getName() );
|
||||
if ( value != null || !( property.getValue() instanceof SinglePropertyMapper ) ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
package org.hibernate.envers.internal.entities.mapper;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -95,10 +97,14 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper {
|
|||
|
||||
@Override
|
||||
public boolean mapToMapFromEntity(
|
||||
SessionImplementor session,
|
||||
Map<String, Object> data,
|
||||
Object newObj,
|
||||
Object oldObj) {
|
||||
final SessionImplementor session,
|
||||
final Map<String, Object> data,
|
||||
final Object newObj,
|
||||
final Object oldObj) {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
boolean ret = false;
|
||||
for ( Map.Entry<PropertyData, PropertyMapper> entry : properties.entrySet() ) {
|
||||
final PropertyData propertyData = entry.getKey();
|
||||
|
@ -111,30 +117,45 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper {
|
|||
|
||||
Getter getter;
|
||||
if ( newObj != null ) {
|
||||
getter = ReflectionTools.getGetter( newObj.getClass(), propertyData, session.getFactory().getServiceRegistry() );
|
||||
getter = ReflectionTools.getGetter(
|
||||
newObj.getClass(),
|
||||
propertyData,
|
||||
session.getFactory().getServiceRegistry()
|
||||
);
|
||||
}
|
||||
else if ( oldObj != null ) {
|
||||
getter = ReflectionTools.getGetter( oldObj.getClass(), propertyData, session.getFactory().getServiceRegistry() );
|
||||
getter = ReflectionTools.getGetter(
|
||||
oldObj.getClass(),
|
||||
propertyData,
|
||||
session.getFactory().getServiceRegistry()
|
||||
);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
ret |= propertyMapper.mapToMapFromEntity(
|
||||
session, data,
|
||||
newObj == null ? null : getter.get( newObj ),
|
||||
oldObj == null ? null : getter.get( oldObj )
|
||||
);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mapModifiedFlagsToMapFromEntity(
|
||||
SessionImplementor session,
|
||||
Map<String, Object> data,
|
||||
Object newObj,
|
||||
Object oldObj) {
|
||||
final SessionImplementor session,
|
||||
final Map<String, Object> data,
|
||||
final Object newObj,
|
||||
final Object oldObj) {
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
for ( Map.Entry<PropertyData, PropertyMapper> entry : properties.entrySet() ) {
|
||||
final PropertyData propertyData = entry.getKey();
|
||||
final PropertyMapper propertyMapper = entry.getValue();
|
||||
|
@ -146,20 +167,34 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper {
|
|||
|
||||
Getter getter;
|
||||
if ( newObj != null ) {
|
||||
getter = ReflectionTools.getGetter( newObj.getClass(), propertyData, session.getFactory().getServiceRegistry() );
|
||||
getter = ReflectionTools.getGetter(
|
||||
newObj.getClass(),
|
||||
propertyData,
|
||||
session.getFactory().getServiceRegistry()
|
||||
);
|
||||
}
|
||||
else if ( oldObj != null ) {
|
||||
getter = ReflectionTools.getGetter( oldObj.getClass(), propertyData, session.getFactory().getServiceRegistry() );
|
||||
getter = ReflectionTools.getGetter(
|
||||
oldObj.getClass(),
|
||||
propertyData,
|
||||
session.getFactory().getServiceRegistry()
|
||||
);
|
||||
}
|
||||
else {
|
||||
return;
|
||||
break;
|
||||
}
|
||||
|
||||
propertyMapper.mapModifiedFlagsToMapFromEntity(
|
||||
session, data,
|
||||
newObj == null ? null : getter.get( newObj ),
|
||||
oldObj == null ? null : getter.get( oldObj )
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
package org.hibernate.envers.internal.entities.mapper;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -84,9 +86,9 @@ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder
|
|||
|
||||
@Override
|
||||
public void mapToEntityFromMap(
|
||||
EnversService enversService,
|
||||
Object obj,
|
||||
Map data,
|
||||
final EnversService enversService,
|
||||
final Object obj,
|
||||
final Map data,
|
||||
Object primaryKey,
|
||||
AuditReaderImplementor versionsReader,
|
||||
Number revision) {
|
||||
|
@ -95,12 +97,27 @@ public class SinglePropertyMapper implements PropertyMapper, SimpleMapperBuilder
|
|||
return;
|
||||
}
|
||||
|
||||
final Setter setter = ReflectionTools.getSetter( obj.getClass(), propertyData, enversService.getServiceRegistry() );
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Setter setter = ReflectionTools.getSetter(
|
||||
obj.getClass(),
|
||||
propertyData,
|
||||
enversService.getServiceRegistry()
|
||||
);
|
||||
|
||||
final Object value = data.get( propertyData.getName() );
|
||||
// We only set a null value if the field is not primite. Otherwise, we leave it intact.
|
||||
|
||||
// We only set a null value if the field is not primitive. Otherwise, we leave it intact.
|
||||
if ( value != null || !isPrimitive( setter, propertyData, obj.getClass() ) ) {
|
||||
setter.set( obj, value, null );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private boolean isPrimitive(Setter setter, PropertyData propertyData, Class<?> cls) {
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.envers.internal.entities.mapper.id;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.envers.exception.AuditException;
|
||||
|
@ -40,20 +42,29 @@ public abstract class AbstractCompositeIdMapper extends AbstractIdMapper impleme
|
|||
return null;
|
||||
}
|
||||
|
||||
final Object ret;
|
||||
try {
|
||||
ret = ReflectHelper.getDefaultConstructor( compositeIdClass ).newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
|
||||
final Object compositeId = instantiateCompositeId();
|
||||
for ( SingleIdMapper mapper : ids.values() ) {
|
||||
if ( !mapper.mapToEntityFromMap( ret, data ) ) {
|
||||
if ( !mapper.mapToEntityFromMap( compositeId, data ) ) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
return compositeId;
|
||||
}
|
||||
|
||||
protected Object instantiateCompositeId() {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
try {
|
||||
return ReflectHelper.getDefaultConstructor( compositeIdClass ).newInstance();
|
||||
}
|
||||
catch ( Exception e ) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.envers.internal.entities.mapper.id;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
@ -39,21 +41,38 @@ public class EmbeddedIdMapper extends AbstractCompositeIdMapper implements Simpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public void mapToMapFromEntity(Map<String, Object> data, Object obj) {
|
||||
public void mapToMapFromEntity(Map<String, Object> data, final Object obj) {
|
||||
if ( obj == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Getter getter = ReflectionTools.getGetter( obj.getClass(), idPropertyData, getServiceRegistry() );
|
||||
mapToMapFromId( data, getter.get( obj ) );
|
||||
final Object value = AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Getter getter = ReflectionTools.getGetter(
|
||||
obj.getClass(),
|
||||
idPropertyData,
|
||||
getServiceRegistry()
|
||||
);
|
||||
return getter.get( obj );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
mapToMapFromId( data, value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean mapToEntityFromMap(Object obj, Map data) {
|
||||
public boolean mapToEntityFromMap(final Object obj, final Map data) {
|
||||
if ( data == null || obj == null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
final Getter getter = ReflectionTools.getGetter( obj.getClass(), idPropertyData, getServiceRegistry() );
|
||||
final Setter setter = ReflectionTools.getSetter( obj.getClass(), idPropertyData, getServiceRegistry() );
|
||||
|
||||
|
@ -75,6 +94,9 @@ public class EmbeddedIdMapper extends AbstractCompositeIdMapper implements Simpl
|
|||
throw new AuditException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdMapper prefixMappedProperties(String prefix) {
|
||||
|
@ -89,14 +111,25 @@ public class EmbeddedIdMapper extends AbstractCompositeIdMapper implements Simpl
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object mapToIdFromEntity(Object data) {
|
||||
public Object mapToIdFromEntity(final Object data) {
|
||||
if ( data == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Getter getter = ReflectionTools.getGetter( data.getClass(), idPropertyData, getServiceRegistry() );
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Getter getter = ReflectionTools.getGetter(
|
||||
data.getClass(),
|
||||
idPropertyData,
|
||||
getServiceRegistry()
|
||||
);
|
||||
return getter.get( data );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<QueryParameterData> mapToQueryParametersFromId(Object obj) {
|
||||
|
|
|
@ -11,9 +11,7 @@ import java.util.LinkedHashMap;
|
|||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.envers.exception.AuditException;
|
||||
import org.hibernate.envers.internal.entities.PropertyData;
|
||||
import org.hibernate.internal.util.ReflectHelper;
|
||||
import org.hibernate.service.ServiceRegistry;
|
||||
|
||||
/**
|
||||
|
@ -64,19 +62,12 @@ public class MultipleIdMapper extends AbstractCompositeIdMapper implements Simpl
|
|||
return null;
|
||||
}
|
||||
|
||||
final Object ret;
|
||||
try {
|
||||
ret = ReflectHelper.getDefaultConstructor( compositeIdClass ).newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
|
||||
final Object compositeId = instantiateCompositeId();
|
||||
for ( SingleIdMapper mapper : ids.values() ) {
|
||||
mapper.mapToEntityFromEntity( ret, data );
|
||||
mapper.mapToEntityFromEntity( compositeId, data );
|
||||
}
|
||||
|
||||
return ret;
|
||||
return compositeId;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
*/
|
||||
package org.hibernate.envers.internal.entities.mapper.id;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -43,7 +45,7 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean mapToEntityFromMap(Object obj, Map data) {
|
||||
public boolean mapToEntityFromMap(final Object obj, Map data) {
|
||||
if ( data == null || obj == null ) {
|
||||
return false;
|
||||
}
|
||||
|
@ -53,11 +55,21 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
|||
return false;
|
||||
}
|
||||
|
||||
final Setter setter = ReflectionTools.getSetter( obj.getClass(), propertyData, getServiceRegistry() );
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<Boolean>() {
|
||||
@Override
|
||||
public Boolean run() {
|
||||
final Setter setter = ReflectionTools.getSetter(
|
||||
obj.getClass(),
|
||||
propertyData,
|
||||
getServiceRegistry()
|
||||
);
|
||||
setter.set( obj, value, null );
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object mapToIdFromMap(Map data) {
|
||||
|
@ -69,7 +81,7 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
|||
}
|
||||
|
||||
@Override
|
||||
public Object mapToIdFromEntity(Object data) {
|
||||
public Object mapToIdFromEntity(final Object data) {
|
||||
if ( data == null ) {
|
||||
return null;
|
||||
}
|
||||
|
@ -79,10 +91,21 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
|||
return hibernateProxy.getHibernateLazyInitializer().getIdentifier();
|
||||
}
|
||||
else {
|
||||
final Getter getter = ReflectionTools.getGetter( data.getClass(), propertyData, getServiceRegistry() );
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Getter getter = ReflectionTools.getGetter(
|
||||
data.getClass(),
|
||||
propertyData,
|
||||
getServiceRegistry()
|
||||
);
|
||||
return getter.get( data );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mapToMapFromId(Map<String, Object> data, Object obj) {
|
||||
|
@ -92,7 +115,7 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
|||
}
|
||||
|
||||
@Override
|
||||
public void mapToMapFromEntity(Map<String, Object> data, Object obj) {
|
||||
public void mapToMapFromEntity(Map<String, Object> data, final Object obj) {
|
||||
if ( obj == null ) {
|
||||
data.put( propertyData.getName(), null );
|
||||
}
|
||||
|
@ -102,20 +125,50 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
|||
data.put( propertyData.getName(), hibernateProxy.getHibernateLazyInitializer().getIdentifier() );
|
||||
}
|
||||
else {
|
||||
final Getter getter = ReflectionTools.getGetter( obj.getClass(), propertyData, getServiceRegistry() );
|
||||
data.put( propertyData.getName(), getter.get( obj ) );
|
||||
final Object value = AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Getter getter = ReflectionTools.getGetter(
|
||||
obj.getClass(),
|
||||
propertyData,
|
||||
getServiceRegistry()
|
||||
);
|
||||
return getter.get( obj );
|
||||
}
|
||||
}
|
||||
);
|
||||
data.put( propertyData.getName(), value );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void mapToEntityFromEntity(Object objTo, Object objFrom) {
|
||||
public void mapToEntityFromEntity(final Object objTo, final Object objFrom) {
|
||||
if ( objTo == null || objFrom == null ) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Getter getter = ReflectionTools.getGetter( objFrom.getClass(), propertyData, getServiceRegistry() );
|
||||
final Setter setter = ReflectionTools.getSetter( objTo.getClass(), propertyData, getServiceRegistry() );
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Getter getter = ReflectionTools.getGetter(
|
||||
objFrom.getClass(),
|
||||
propertyData,
|
||||
getServiceRegistry()
|
||||
);
|
||||
|
||||
final Setter setter = ReflectionTools.getSetter(
|
||||
objTo.getClass(),
|
||||
propertyData,
|
||||
getServiceRegistry()
|
||||
);
|
||||
|
||||
setter.set( objTo, getter.get( objFrom ), null );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -9,6 +9,8 @@ package org.hibernate.envers.internal.entities.mapper.relation;
|
|||
import java.io.Serializable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
@ -247,17 +249,23 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
|
|||
|
||||
@Override
|
||||
public void mapToEntityFromMap(
|
||||
EnversService enversService,
|
||||
Object obj,
|
||||
Map data,
|
||||
Object primaryKey,
|
||||
AuditReaderImplementor versionsReader,
|
||||
Number revision) {
|
||||
final EnversService enversService,
|
||||
final Object obj,
|
||||
final Map data,
|
||||
final Object primaryKey,
|
||||
final AuditReaderImplementor versionsReader,
|
||||
final Number revision) {
|
||||
final String revisionTypePropertyName = enversService.getAuditEntitiesConfiguration().getRevisionTypePropName();
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Setter setter = ReflectionTools.getSetter(
|
||||
obj.getClass(),
|
||||
commonCollectionMapperData.getCollectionReferencingPropertyData(),
|
||||
enversService.getServiceRegistry()
|
||||
);
|
||||
|
||||
try {
|
||||
setter.set(
|
||||
obj,
|
||||
|
@ -267,11 +275,7 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
|
|||
versionsReader,
|
||||
primaryKey,
|
||||
revision,
|
||||
RevisionType.DEL.equals(
|
||||
data.get(
|
||||
enversService.getAuditEntitiesConfiguration().getRevisionTypePropName()
|
||||
)
|
||||
)
|
||||
RevisionType.DEL.equals( data.get( revisionTypePropertyName ) )
|
||||
)
|
||||
),
|
||||
null
|
||||
|
@ -286,6 +290,11 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
|
|||
catch (InvocationTargetException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
package org.hibernate.envers.internal.entities.mapper.relation;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -88,8 +90,21 @@ public abstract class AbstractToOneMapper implements PropertyMapper {
|
|||
}
|
||||
|
||||
protected void setPropertyValue(Object targetObject, Object value) {
|
||||
final Setter setter = ReflectionTools.getSetter( targetObject.getClass(), propertyData, serviceRegistry );
|
||||
AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Setter setter = ReflectionTools.getSetter(
|
||||
targetObject.getClass(),
|
||||
propertyData,
|
||||
serviceRegistry
|
||||
);
|
||||
setter.set( targetObject, value, null );
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,6 +6,9 @@
|
|||
*/
|
||||
package org.hibernate.envers.internal.entities.mapper.relation.component;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
|
@ -38,9 +41,7 @@ public class MiddleEmbeddableComponentMapper implements MiddleComponentMapper, C
|
|||
Object dataObject,
|
||||
Number revision) {
|
||||
try {
|
||||
final Object componentInstance = dataObject != null
|
||||
? dataObject
|
||||
: ReflectHelper.getDefaultConstructor( componentClass ).newInstance();
|
||||
final Object componentInstance = getComponentInstance( dataObject );
|
||||
delegate.mapToEntityFromMap(
|
||||
entityInstantiator.getEnversService(),
|
||||
componentInstance,
|
||||
|
@ -56,6 +57,32 @@ public class MiddleEmbeddableComponentMapper implements MiddleComponentMapper, C
|
|||
}
|
||||
}
|
||||
|
||||
private Object getComponentInstance(Object dataObject) {
|
||||
if ( dataObject != null ) {
|
||||
return dataObject;
|
||||
}
|
||||
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
try {
|
||||
return ReflectHelper.getDefaultConstructor( componentClass ).newInstance();
|
||||
}
|
||||
catch ( InstantiationException e ) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch ( IllegalAccessException e ) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch ( InvocationTargetException e ) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mapToMapFromObject(
|
||||
SessionImplementor session,
|
||||
|
|
|
@ -6,12 +6,15 @@
|
|||
*/
|
||||
package org.hibernate.envers.internal.entities.mapper.relation.component;
|
||||
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Map;
|
||||
|
||||
import org.hibernate.engine.spi.SessionImplementor;
|
||||
import org.hibernate.envers.internal.entities.EntityInstantiator;
|
||||
import org.hibernate.envers.internal.tools.ReflectionTools;
|
||||
import org.hibernate.envers.internal.tools.query.Parameters;
|
||||
import org.hibernate.property.access.spi.Getter;
|
||||
|
||||
/**
|
||||
* A component mapper for the @MapKey mapping with the name parameter specified: the value of the map's key
|
||||
|
@ -31,10 +34,25 @@ public class MiddleMapKeyPropertyComponentMapper implements MiddleComponentMappe
|
|||
|
||||
@Override
|
||||
public Object mapToObjectFromFullMap(
|
||||
EntityInstantiator entityInstantiator, Map<String, Object> data,
|
||||
Object dataObject, Number revision) {
|
||||
final EntityInstantiator entityInstantiator,
|
||||
final Map<String, Object> data,
|
||||
final Object dataObject,
|
||||
Number revision) {
|
||||
// dataObject is not null, as this mapper can only be used in an index.
|
||||
return ReflectionTools.getGetter( dataObject.getClass(), propertyName, accessType, entityInstantiator.getEnversService().getServiceRegistry() ).get( dataObject );
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Getter getter = ReflectionTools.getGetter(
|
||||
dataObject.getClass(),
|
||||
propertyName,
|
||||
accessType,
|
||||
entityInstantiator.getEnversService().getServiceRegistry()
|
||||
);
|
||||
return getter.get( dataObject );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
package org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -43,6 +45,10 @@ public class BasicCollectionInitializor<T extends Collection> extends AbstractCo
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T initializeCollection(int size) {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<T>() {
|
||||
@Override
|
||||
public T run() {
|
||||
try {
|
||||
return (T) ReflectHelper.getDefaultConstructor( collectionClass ).newInstance();
|
||||
}
|
||||
|
@ -56,6 +62,9 @@ public class BasicCollectionInitializor<T extends Collection> extends AbstractCo
|
|||
throw new AuditException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
|
|
|
@ -7,6 +7,8 @@
|
|||
package org.hibernate.envers.internal.entities.mapper.relation.lazy.initializor;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -45,6 +47,10 @@ public class MapCollectionInitializor<T extends Map> extends AbstractCollectionI
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T initializeCollection(int size) {
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<T>() {
|
||||
@Override
|
||||
public T run() {
|
||||
try {
|
||||
return (T) ReflectHelper.getDefaultConstructor( collectionClass ).newInstance();
|
||||
}
|
||||
|
@ -58,6 +64,9 @@ public class MapCollectionInitializor<T extends Map> extends AbstractCollectionI
|
|||
throw new AuditException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings({"unchecked"})
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
package org.hibernate.envers.internal.revisioninfo;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.Date;
|
||||
|
||||
|
@ -31,7 +32,7 @@ public class DefaultRevisionInfoGenerator implements RevisionInfoGenerator {
|
|||
private final RevisionListener listener;
|
||||
private final Setter revisionTimestampSetter;
|
||||
private final boolean timestampAsDate;
|
||||
private final Class<?> revisionInfoClass;
|
||||
private final Constructor<?> revisionInfoClassConstructor;
|
||||
private final SessionCacheCleaner sessionCacheCleaner;
|
||||
|
||||
public DefaultRevisionInfoGenerator(
|
||||
|
@ -42,9 +43,9 @@ public class DefaultRevisionInfoGenerator implements RevisionInfoGenerator {
|
|||
boolean timestampAsDate,
|
||||
ServiceRegistry serviceRegistry) {
|
||||
this.revisionInfoEntityName = revisionInfoEntityName;
|
||||
this.revisionInfoClass = revisionInfoClass;
|
||||
this.timestampAsDate = timestampAsDate;
|
||||
|
||||
revisionInfoClassConstructor = ReflectHelper.getDefaultConstructor( revisionInfoClass );
|
||||
revisionTimestampSetter = ReflectionTools.getSetter( revisionInfoClass, revisionInfoTimestampData, serviceRegistry );
|
||||
|
||||
if ( !listenerClass.equals( RevisionListener.class ) ) {
|
||||
|
@ -80,7 +81,7 @@ public class DefaultRevisionInfoGenerator implements RevisionInfoGenerator {
|
|||
public Object generate() {
|
||||
Object revisionInfo;
|
||||
try {
|
||||
revisionInfo = ReflectHelper.getDefaultConstructor( revisionInfoClass ).newInstance();
|
||||
revisionInfo = revisionInfoClassConstructor.newInstance();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException( e );
|
||||
|
|
Loading…
Reference in New Issue