OPENJPA-369. Committed Albert's changes for the Java 2 Security updates for the Solaris platform.

git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@577029 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Kevin W. Sutter 2007-09-18 19:44:06 +00:00
parent c0cf405648
commit 7524219f6a
7 changed files with 128 additions and 30 deletions

View File

@ -99,10 +99,9 @@ public class DataCacheScheduler
_caches.put(cache, schedule); _caches.put(cache, schedule);
_stop = false; _stop = false;
if (_thread == null) { if (_thread == null) {
_thread = (Thread) AccessController _thread = (Thread) AccessController.doPrivileged(J2DoPrivHelper
.doPrivileged(J2DoPrivHelper.newThreadAction(this, _loc.get( .newDaemonThreadAction(this, _loc.get("scheduler-name")
"scheduler-name").getMessage())); .getMessage()));
_thread.setDaemon(true);
_thread.start(); _thread.start();
if (_log.isTraceEnabled()) if (_log.isTraceEnabled())
_log.trace(_loc.get("scheduler-start", _thread.getName())); _log.trace(_loc.get("scheduler-start", _thread.getName()));

View File

@ -24,6 +24,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.AccessibleObject; import java.lang.reflect.AccessibleObject;
import java.lang.reflect.AnnotatedElement;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.ServerSocket; import java.net.ServerSocket;
@ -48,6 +49,9 @@ import serp.bytecode.Project;
* methods: * methods:
* <ul> * <ul>
* <li>AccessibleObject.setAccessible * <li>AccessibleObject.setAccessible
* <li>AnnotatedElement.getAnnotations
* <li>AnnotatedElement.getDeclaredAnnotations
* <li>AnnotatedElement.isAnnotationPresent
* <li>Class.forName * <li>Class.forName
* <li>Class.getClassLoader * <li>Class.getClassLoader
* <li>Class.getDeclaredField * <li>Class.getDeclaredField
@ -324,6 +328,60 @@ public abstract class J2DoPrivHelper {
}; };
} }
/**
* Return a PrivilegeAction object for AnnotatedElement.getAnnotations().
*
* Requires security policy:
* 'permission java.lang.RuntimePermission "accessDeclaredMembers";'
*
* @return Annotation[]
*/
public static final PrivilegedAction getAnnotationsAction(
final AnnotatedElement element) {
return new PrivilegedAction() {
public Object run() {
return element.getAnnotations();
}
};
}
/**
* Return a PrivilegeAction object for
* AnnotatedElement.getDeclaredAnnotations().
*
* Requires security policy:
* 'permission java.lang.RuntimePermission "accessDeclaredMembers";'
*
* @return Annotation[]
*/
public static final PrivilegedAction getDeclaredAnnotationsAction(
final AnnotatedElement element) {
return new PrivilegedAction() {
public Object run() {
return element.getDeclaredAnnotations();
}
};
}
/**
* Return a PrivilegeAction object for
* AnnotatedElement.isAnnotationPresent().
*
* Requires security policy:
* 'permission java.lang.RuntimePermission "accessDeclaredMembers";'
*
* @return Boolean
*/
public static final PrivilegedAction isAnnotationPresentAction(
final AnnotatedElement element, final Class annotationClazz) {
return new PrivilegedAction() {
public Object run() {
return element.isAnnotationPresent(annotationClazz)
? Boolean.TRUE : Boolean.FALSE;
}
};
}
/** /**
* Return a PrivilegedExceptionAction object for clazz.newInstance(). * Return a PrivilegedExceptionAction object for clazz.newInstance().
* *
@ -794,14 +852,17 @@ public abstract class J2DoPrivHelper {
* *
* Requires security policy: * Requires security policy:
* 'permission java.lang.RuntimePermission "modifyThreadGroup";' * 'permission java.lang.RuntimePermission "modifyThreadGroup";'
* 'permission java.lang.RuntimePermission "modifyThread";'
* *
* @return Thread * @return Thread
*/ */
public static final PrivilegedAction newThreadAction( public static final PrivilegedAction newDaemonThreadAction(
final Runnable target, final String name) { final Runnable target, final String name) {
return new PrivilegedAction() { return new PrivilegedAction() {
public Object run() { public Object run() {
return new Thread(target, name); Thread thread = new Thread(target, name);
thread.setDaemon(true);
return thread;
} }
}; };
} }

View File

@ -21,6 +21,7 @@ package org.apache.openjpa.persistence.jdbc;
import java.lang.annotation.Annotation; import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement; import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Modifier; import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.sql.Types; import java.sql.Types;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -74,6 +75,7 @@ import org.apache.openjpa.jdbc.schema.Column;
import org.apache.openjpa.jdbc.schema.Unique; import org.apache.openjpa.jdbc.schema.Unique;
import org.apache.openjpa.jdbc.sql.DBDictionary; import org.apache.openjpa.jdbc.sql.DBDictionary;
import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.meta.ClassMetaData; import org.apache.openjpa.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData; import org.apache.openjpa.meta.FieldMetaData;
@ -1058,7 +1060,9 @@ public class AnnotationPersistenceMappingParser
if (xmlTypeClass != null if (xmlTypeClass != null
&& StringUtils.isEmpty(pcols[i].columnDefinition()) && StringUtils.isEmpty(pcols[i].columnDefinition())
&& fm.getDeclaredType().isAnnotationPresent(xmlTypeClass)) { && ((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(fm.getDeclaredType(),
xmlTypeClass))).booleanValue()) {
DBDictionary dict = ((MappingRepository) getRepository()) DBDictionary dict = ((MappingRepository) getRepository())
.getDBDictionary(); .getDBDictionary();
if (dict.supportsXMLColumn) if (dict.supportsXMLColumn)

View File

@ -465,9 +465,14 @@ public class AnnotationPersistenceMetaDataParser
// check immediately whether the user is using any annotations, // check immediately whether the user is using any annotations,
// regardless of mode. this prevents adding non-entity classes to // regardless of mode. this prevents adding non-entity classes to
// repository if we're ignoring these annotations in mapping mode // repository if we're ignoring these annotations in mapping mode
if (!_cls.isAnnotationPresent(Entity.class) if (!((Boolean) AccessController.doPrivileged(J2DoPrivHelper
&& !_cls.isAnnotationPresent(Embeddable.class) .isAnnotationPresentAction(_cls, Entity.class))).booleanValue()
&& !_cls.isAnnotationPresent(MappedSuperclass.class)) && !((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(_cls, Embeddable.class)))
.booleanValue()
&& !((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(_cls, MappedSuperclass.class)))
.booleanValue())
return null; return null;
// find / create metadata // find / create metadata
@ -762,7 +767,9 @@ public class AnnotationPersistenceMetaDataParser
J2DoPrivHelper.getDeclaredFieldsAction( J2DoPrivHelper.getDeclaredFieldsAction(
meta.getDescribedType())); meta.getDescribedType()));
for (int i = 0; i < fields.length; i++) for (int i = 0; i < fields.length; i++)
if (fields[i].isAnnotationPresent(DetachedState.class)) if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(fields[i], DetachedState.class)))
.booleanValue())
meta.setDetachedState(fields[i].getName()); meta.setDetachedState(fields[i].getName());
} }
} }
@ -818,7 +825,8 @@ public class AnnotationPersistenceMetaDataParser
MetaDataDefaults def = repos.getMetaDataFactory().getDefaults(); MetaDataDefaults def = repos.getMetaDataFactory().getDefaults();
for (Method m : methods) { for (Method m : methods) {
for (Annotation anno : m.getDeclaredAnnotations()) { for (Annotation anno : (Annotation[]) AccessController
.doPrivileged(J2DoPrivHelper.getDeclaredAnnotationsAction(m))) {
MetaDataTag tag = _tags.get(anno.annotationType()); MetaDataTag tag = _tags.get(anno.annotationType());
if (tag == null) if (tag == null)
continue; continue;
@ -956,7 +964,8 @@ public class AnnotationPersistenceMetaDataParser
fmd.setExplicit(true); fmd.setExplicit(true);
AnnotatedElement el = (AnnotatedElement) member; AnnotatedElement el = (AnnotatedElement) member;
boolean lob = el.isAnnotationPresent(Lob.class); boolean lob = ((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(el, Lob.class))).booleanValue();
if (isMetaDataMode()) { if (isMetaDataMode()) {
switch (pstrat) { switch (pstrat) {
case BASIC: case BASIC:

View File

@ -22,10 +22,12 @@ import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Member; import java.lang.reflect.Member;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.security.AccessController;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.conf.OpenJPAConfiguration; import org.apache.openjpa.conf.OpenJPAConfiguration;
import org.apache.openjpa.lib.log.Log; import org.apache.openjpa.lib.log.Log;
import org.apache.openjpa.lib.util.J2DoPrivHelper;
import org.apache.openjpa.lib.util.Localizer; import org.apache.openjpa.lib.util.Localizer;
import org.apache.openjpa.meta.DelegatingMetaDataFactory; import org.apache.openjpa.meta.DelegatingMetaDataFactory;
import org.apache.openjpa.meta.FieldMetaData; import org.apache.openjpa.meta.FieldMetaData;
@ -171,8 +173,11 @@ public class AnnotationPersistenceXMLMetaDataParser {
private XMLMetaData parseXMLClassAnnotations() { private XMLMetaData parseXMLClassAnnotations() {
// check immediately whether the class has JAXB XML annotations // check immediately whether the class has JAXB XML annotations
if (_cls == null || xmlTypeClass == null if (_cls == null || xmlTypeClass == null
|| !(_cls.isAnnotationPresent(xmlTypeClass) || !(((Boolean) AccessController.doPrivileged(J2DoPrivHelper
&& _cls.isAnnotationPresent(xmlRootElementClass))) .isAnnotationPresentAction(_cls, xmlTypeClass))).booleanValue()
&& ((Boolean) AccessController
.doPrivileged(J2DoPrivHelper.isAnnotationPresentAction(_cls,
xmlRootElementClass))).booleanValue()))
return null; return null;
// find / create metadata // find / create metadata
@ -220,7 +225,9 @@ public class AnnotationPersistenceXMLMetaDataParser {
Class superclass = cls.getSuperclass(); Class superclass = cls.getSuperclass();
// handle inheritance at sub-element level // handle inheritance at sub-element level
if (superclass.isAnnotationPresent(xmlTypeClass)) if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(superclass, xmlTypeClass)))
.booleanValue())
populateFromReflection(superclass, meta); populateFromReflection(superclass, meta);
try { try {
@ -240,8 +247,9 @@ public class AnnotationPersistenceXMLMetaDataParser {
// avoid JAXB XML bind default name // avoid JAXB XML bind default name
if (StringUtils.equals(XMLMetaData.defaultName, xmlname)) if (StringUtils.equals(XMLMetaData.defaultName, xmlname))
xmlname = member.getName(); xmlname = member.getName();
if (((Field) member).getType() if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresent(xmlTypeClass)) { .isAnnotationPresentAction(((Field) member).getType(),
xmlTypeClass))).booleanValue()) {
field = _repos.addXMLMetaData(((Field) member).getType() field = _repos.addXMLMetaData(((Field) member).getType()
, member.getName()); , member.getName());
parseXmlRootElement(((Field) member).getType(), field); parseXmlRootElement(((Field) member).getType(), field);

View File

@ -116,7 +116,8 @@ public class PersistenceMetaDataDefaults
if (member == null) if (member == null)
return null; return null;
AnnotatedElement el = (AnnotatedElement) member; AnnotatedElement el = (AnnotatedElement) member;
if (el.isAnnotationPresent(Transient.class)) if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(el, Transient.class))).booleanValue())
return TRANSIENT; return TRANSIENT;
if (fmd != null if (fmd != null
&& fmd.getManagement() != FieldMetaData.MANAGE_PERSISTENT) && fmd.getManagement() != FieldMetaData.MANAGE_PERSISTENT)
@ -182,7 +183,8 @@ public class PersistenceMetaDataDefaults
} }
//### EJB3: what if defined in XML? //### EJB3: what if defined in XML?
if (type.isAnnotationPresent(Embeddable.class)) if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(type, Embeddable.class))).booleanValue())
return EMBEDDED; return EMBEDDED;
if (Serializable.class.isAssignableFrom(type)) if (Serializable.class.isAssignableFrom(type))
return BASIC; return BASIC;
@ -271,7 +273,8 @@ public class PersistenceMetaDataDefaults
Annotation[] annos; Annotation[] annos;
String name; String name;
for (int i = 0; i < members.length; i++) { for (int i = 0; i < members.length; i++) {
annos = members[i].getAnnotations(); annos = (Annotation[]) AccessController.doPrivileged(J2DoPrivHelper
.getAnnotationsAction(members[i]));
for (int j = 0; j < annos.length; j++) { for (int j = 0; j < annos.length; j++) {
name = annos[j].annotationType().getName(); name = annos[j].annotationType().getName();
if ((name.startsWith("javax.persistence.") if ((name.startsWith("javax.persistence.")
@ -317,7 +320,9 @@ public class PersistenceMetaDataDefaults
private boolean isAnnotatedTransient(Member member) { private boolean isAnnotatedTransient(Member member) {
return member instanceof AnnotatedElement return member instanceof AnnotatedElement
&& ((AnnotatedElement) member).isAnnotationPresent(Transient.class); && ((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(((AnnotatedElement) member),
Transient.class))).booleanValue();
} }
private void logNoSetter(ClassMetaData meta, String name, Exception e) { private void logNoSetter(ClassMetaData meta, String name, Exception e) {

View File

@ -293,18 +293,26 @@ public class PersistenceMetaDataFactory
return null; return null;
Collection classes = repos.loadPersistentTypes(false, loader); Collection classes = repos.loadPersistentTypes(false, loader);
for (Class cls : (Collection<Class>) classes) { for (Class cls : (Collection<Class>) classes) {
if (cls.isAnnotationPresent(NamedQuery.class) && hasNamedQuery if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(cls, NamedQuery.class)))
.booleanValue() && hasNamedQuery
(queryName, (NamedQuery) cls.getAnnotation(NamedQuery.class))) (queryName, (NamedQuery) cls.getAnnotation(NamedQuery.class)))
return cls; return cls;
if (cls.isAnnotationPresent(NamedQueries.class) && if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(cls, NamedQueries.class)))
.booleanValue() &&
hasNamedQuery(queryName, ((NamedQueries) cls. hasNamedQuery(queryName, ((NamedQueries) cls.
getAnnotation(NamedQueries.class)).value())) getAnnotation(NamedQueries.class)).value()))
return cls; return cls;
if (cls.isAnnotationPresent(NamedNativeQuery.class) && if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(cls, NamedNativeQuery.class)))
.booleanValue() &&
hasNamedNativeQuery(queryName, (NamedNativeQuery) cls. hasNamedNativeQuery(queryName, (NamedNativeQuery) cls.
getAnnotation(NamedNativeQuery.class))) getAnnotation(NamedNativeQuery.class)))
return cls; return cls;
if (cls.isAnnotationPresent(NamedNativeQueries.class) && if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(cls, NamedNativeQueries.class)))
.booleanValue() &&
hasNamedNativeQuery(queryName, ((NamedNativeQueries) cls. hasNamedNativeQuery(queryName, ((NamedNativeQueries) cls.
getAnnotation(NamedNativeQueries.class)).value())) getAnnotation(NamedNativeQueries.class)).value()))
return cls; return cls;
@ -320,13 +328,17 @@ public class PersistenceMetaDataFactory
Collection classes = repos.loadPersistentTypes(false, loader); Collection classes = repos.loadPersistentTypes(false, loader);
for (Class cls : (Collection<Class>) classes) { for (Class cls : (Collection<Class>) classes) {
if (cls.isAnnotationPresent(SqlResultSetMapping.class) && if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(cls, SqlResultSetMapping.class)))
.booleanValue() &&
hasRSMapping(rsMappingName, (SqlResultSetMapping) cls. hasRSMapping(rsMappingName, (SqlResultSetMapping) cls.
getAnnotation(SqlResultSetMapping.class))) getAnnotation(SqlResultSetMapping.class)))
return cls; return cls;
if (cls.isAnnotationPresent(SqlResultSetMappings.class) && if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
.isAnnotationPresentAction(cls, SqlResultSetMappings.class)))
.booleanValue() &&
hasRSMapping(rsMappingName, ((SqlResultSetMappings) cls. hasRSMapping(rsMappingName, ((SqlResultSetMappings) cls.
getAnnotation(SqlResultSetMappings.class)).value())) getAnnotation(SqlResultSetMappings.class)).value()))
return cls; return cls;