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,35 +118,47 @@ 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;
|
||||
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 );
|
||||
}
|
||||
else {
|
||||
// set the component
|
||||
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() ) {
|
||||
if ( data.get(
|
||||
property.getKey()
|
||||
.getName()
|
||||
) != null || !( property.getValue() instanceof SinglePropertyMapper ) ) {
|
||||
allNullAndSingle = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( allNullAndSingle ) {
|
||||
// single property, but default value need not be null, so we'll set it to null anyway
|
||||
setter.set( obj, null, null );
|
||||
}
|
||||
else {
|
||||
// set the component
|
||||
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 );
|
||||
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,71 +97,104 @@ public class MultiPropertyMapper implements ExtendedPropertyMapper {
|
|||
|
||||
@Override
|
||||
public boolean mapToMapFromEntity(
|
||||
SessionImplementor session,
|
||||
Map<String, Object> data,
|
||||
Object newObj,
|
||||
Object oldObj) {
|
||||
boolean ret = false;
|
||||
for ( Map.Entry<PropertyData, PropertyMapper> entry : properties.entrySet() ) {
|
||||
final PropertyData propertyData = entry.getKey();
|
||||
final PropertyMapper propertyMapper = entry.getValue();
|
||||
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();
|
||||
final PropertyMapper propertyMapper = entry.getValue();
|
||||
|
||||
// synthetic properties are not part of the entity model; therefore they should be ignored.
|
||||
if ( propertyData.isSynthetic() ) {
|
||||
continue;
|
||||
}
|
||||
// synthetic properties are not part of the entity model; therefore they should be ignored.
|
||||
if ( propertyData.isSynthetic() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Getter getter;
|
||||
if ( newObj != null ) {
|
||||
getter = ReflectionTools.getGetter( newObj.getClass(), propertyData, session.getFactory().getServiceRegistry() );
|
||||
}
|
||||
else if ( oldObj != null ) {
|
||||
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 )
|
||||
);
|
||||
}
|
||||
Getter getter;
|
||||
if ( newObj != null ) {
|
||||
getter = ReflectionTools.getGetter(
|
||||
newObj.getClass(),
|
||||
propertyData,
|
||||
session.getFactory().getServiceRegistry()
|
||||
);
|
||||
}
|
||||
else if ( oldObj != null ) {
|
||||
getter = ReflectionTools.getGetter(
|
||||
oldObj.getClass(),
|
||||
propertyData,
|
||||
session.getFactory().getServiceRegistry()
|
||||
);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ret;
|
||||
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) {
|
||||
for ( Map.Entry<PropertyData, PropertyMapper> entry : properties.entrySet() ) {
|
||||
final PropertyData propertyData = entry.getKey();
|
||||
final PropertyMapper propertyMapper = entry.getValue();
|
||||
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();
|
||||
|
||||
// synthetic properties are not part of the entity model; therefore they should be ignored.
|
||||
if ( propertyData.isSynthetic() ) {
|
||||
continue;
|
||||
}
|
||||
// synthetic properties are not part of the entity model; therefore they should be ignored.
|
||||
if ( propertyData.isSynthetic() ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Getter getter;
|
||||
if ( newObj != null ) {
|
||||
getter = ReflectionTools.getGetter( newObj.getClass(), propertyData, session.getFactory().getServiceRegistry() );
|
||||
}
|
||||
else if ( oldObj != null ) {
|
||||
getter = ReflectionTools.getGetter( oldObj.getClass(), propertyData, session.getFactory().getServiceRegistry() );
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
propertyMapper.mapModifiedFlagsToMapFromEntity(
|
||||
session, data,
|
||||
newObj == null ? null : getter.get( newObj ),
|
||||
oldObj == null ? null : getter.get( oldObj )
|
||||
);
|
||||
}
|
||||
Getter getter;
|
||||
if ( newObj != null ) {
|
||||
getter = ReflectionTools.getGetter(
|
||||
newObj.getClass(),
|
||||
propertyData,
|
||||
session.getFactory().getServiceRegistry()
|
||||
);
|
||||
}
|
||||
else if ( oldObj != null ) {
|
||||
getter = ReflectionTools.getGetter(
|
||||
oldObj.getClass(),
|
||||
propertyData,
|
||||
session.getFactory().getServiceRegistry()
|
||||
);
|
||||
}
|
||||
else {
|
||||
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() );
|
||||
final Object value = data.get( propertyData.getName() );
|
||||
// We only set a null value if the field is not primite. Otherwise, we leave it intact.
|
||||
if ( value != null || !isPrimitive( setter, propertyData, obj.getClass() ) ) {
|
||||
setter.set( obj, value, null );
|
||||
}
|
||||
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 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,41 +41,61 @@ 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;
|
||||
}
|
||||
|
||||
final Getter getter = ReflectionTools.getGetter( obj.getClass(), idPropertyData, getServiceRegistry() );
|
||||
final Setter setter = ReflectionTools.getSetter( obj.getClass(), idPropertyData, getServiceRegistry() );
|
||||
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() );
|
||||
|
||||
try {
|
||||
final Object subObj = ReflectHelper.getDefaultConstructor( getter.getReturnType() ).newInstance();
|
||||
try {
|
||||
final Object subObj = ReflectHelper.getDefaultConstructor( getter.getReturnType() ).newInstance();
|
||||
|
||||
boolean ret = true;
|
||||
for ( IdMapper idMapper : ids.values() ) {
|
||||
ret &= idMapper.mapToEntityFromMap( subObj, data );
|
||||
}
|
||||
boolean ret = true;
|
||||
for ( IdMapper idMapper : ids.values() ) {
|
||||
ret &= idMapper.mapToEntityFromMap( subObj, data );
|
||||
}
|
||||
|
||||
if ( ret ) {
|
||||
setter.set( obj, subObj, null );
|
||||
}
|
||||
if ( ret ) {
|
||||
setter.set( obj, subObj, null );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -89,13 +111,24 @@ 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 getter.get( data );
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Getter getter = ReflectionTools.getGetter(
|
||||
data.getClass(),
|
||||
idPropertyData,
|
||||
getServiceRegistry()
|
||||
);
|
||||
return getter.get( data );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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,10 +55,20 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
|||
return false;
|
||||
}
|
||||
|
||||
final Setter setter = ReflectionTools.getSetter( obj.getClass(), propertyData, getServiceRegistry() );
|
||||
setter.set( obj, value, null );
|
||||
|
||||
return true;
|
||||
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
|
||||
|
@ -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,8 +91,19 @@ public class SingleIdMapper extends AbstractIdMapper implements SimpleIdMapperBu
|
|||
return hibernateProxy.getHibernateLazyInitializer().getIdentifier();
|
||||
}
|
||||
else {
|
||||
final Getter getter = ReflectionTools.getGetter( data.getClass(), propertyData, getServiceRegistry() );
|
||||
return getter.get( data );
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<Object>() {
|
||||
@Override
|
||||
public Object run() {
|
||||
final Getter getter = ReflectionTools.getGetter(
|
||||
data.getClass(),
|
||||
propertyData,
|
||||
getServiceRegistry()
|
||||
);
|
||||
return getter.get( data );
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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() );
|
||||
setter.set( objTo, getter.get( objFrom ), null );
|
||||
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,45 +249,52 @@ public abstract class AbstractCollectionMapper<T> implements PropertyMapper {
|
|||
|
||||
@Override
|
||||
public void mapToEntityFromMap(
|
||||
EnversService enversService,
|
||||
Object obj,
|
||||
Map data,
|
||||
Object primaryKey,
|
||||
AuditReaderImplementor versionsReader,
|
||||
Number revision) {
|
||||
final Setter setter = ReflectionTools.getSetter(
|
||||
obj.getClass(),
|
||||
commonCollectionMapperData.getCollectionReferencingPropertyData(),
|
||||
enversService.getServiceRegistry()
|
||||
);
|
||||
try {
|
||||
setter.set(
|
||||
obj,
|
||||
proxyConstructor.newInstance(
|
||||
getInitializor(
|
||||
enversService,
|
||||
versionsReader,
|
||||
primaryKey,
|
||||
revision,
|
||||
RevisionType.DEL.equals(
|
||||
data.get(
|
||||
enversService.getAuditEntitiesConfiguration().getRevisionTypePropName()
|
||||
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,
|
||||
proxyConstructor.newInstance(
|
||||
getInitializor(
|
||||
enversService,
|
||||
versionsReader,
|
||||
primaryKey,
|
||||
revision,
|
||||
RevisionType.DEL.equals( data.get( revisionTypePropertyName ) )
|
||||
)
|
||||
)
|
||||
)
|
||||
),
|
||||
null
|
||||
);
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
),
|
||||
null
|
||||
);
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
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 );
|
||||
setter.set( targetObject, value, null );
|
||||
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,18 +45,25 @@ public class BasicCollectionInitializor<T extends Collection> extends AbstractCo
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T initializeCollection(int size) {
|
||||
try {
|
||||
return (T) ReflectHelper.getDefaultConstructor( collectionClass ).newInstance();
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<T>() {
|
||||
@Override
|
||||
public T run() {
|
||||
try {
|
||||
return (T) ReflectHelper.getDefaultConstructor( collectionClass ).newInstance();
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@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.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
@ -45,18 +47,25 @@ public class MapCollectionInitializor<T extends Map> extends AbstractCollectionI
|
|||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
protected T initializeCollection(int size) {
|
||||
try {
|
||||
return (T) ReflectHelper.getDefaultConstructor( collectionClass ).newInstance();
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
return AccessController.doPrivileged(
|
||||
new PrivilegedAction<T>() {
|
||||
@Override
|
||||
public T run() {
|
||||
try {
|
||||
return (T) ReflectHelper.getDefaultConstructor( collectionClass ).newInstance();
|
||||
}
|
||||
catch (InstantiationException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (IllegalAccessException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
throw new AuditException( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -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