diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java
index 316c085f4..38b194aba 100644
--- a/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java
+++ b/openjpa-kernel/src/main/java/org/apache/openjpa/datacache/DataCacheScheduler.java
@@ -99,10 +99,9 @@ public class DataCacheScheduler
_caches.put(cache, schedule);
_stop = false;
if (_thread == null) {
- _thread = (Thread) AccessController
- .doPrivileged(J2DoPrivHelper.newThreadAction(this, _loc.get(
- "scheduler-name").getMessage()));
- _thread.setDaemon(true);
+ _thread = (Thread) AccessController.doPrivileged(J2DoPrivHelper
+ .newDaemonThreadAction(this, _loc.get("scheduler-name")
+ .getMessage()));
_thread.start();
if (_log.isTraceEnabled())
_log.trace(_loc.get("scheduler-start", _thread.getName()));
diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
index f3269e11c..391178578 100644
--- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
+++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/util/J2DoPrivHelper.java
@@ -24,6 +24,7 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.lang.reflect.AccessibleObject;
+import java.lang.reflect.AnnotatedElement;
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.ServerSocket;
@@ -48,6 +49,9 @@ import serp.bytecode.Project;
* methods:
*
* - AccessibleObject.setAccessible
+ *
- AnnotatedElement.getAnnotations
+ *
- AnnotatedElement.getDeclaredAnnotations
+ *
- AnnotatedElement.isAnnotationPresent
*
- Class.forName
*
- Class.getClassLoader
*
- 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().
*
@@ -794,14 +852,17 @@ public abstract class J2DoPrivHelper {
*
* Requires security policy:
* 'permission java.lang.RuntimePermission "modifyThreadGroup";'
+ * 'permission java.lang.RuntimePermission "modifyThread";'
*
* @return Thread
*/
- public static final PrivilegedAction newThreadAction(
+ public static final PrivilegedAction newDaemonThreadAction(
final Runnable target, final String name) {
return new PrivilegedAction() {
public Object run() {
- return new Thread(target, name);
+ Thread thread = new Thread(target, name);
+ thread.setDaemon(true);
+ return thread;
}
};
}
diff --git a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
index 8c29b2c21..747c9fdb3 100644
--- a/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
+++ b/openjpa-persistence-jdbc/src/main/java/org/apache/openjpa/persistence/jdbc/AnnotationPersistenceMappingParser.java
@@ -21,6 +21,7 @@ package org.apache.openjpa.persistence.jdbc;
import java.lang.annotation.Annotation;
import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Modifier;
+import java.security.AccessController;
import java.sql.Types;
import java.util.ArrayList;
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.sql.DBDictionary;
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.meta.ClassMetaData;
import org.apache.openjpa.meta.FieldMetaData;
@@ -1058,7 +1060,9 @@ public class AnnotationPersistenceMappingParser
if (xmlTypeClass != null
&& StringUtils.isEmpty(pcols[i].columnDefinition())
- && fm.getDeclaredType().isAnnotationPresent(xmlTypeClass)) {
+ && ((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(fm.getDeclaredType(),
+ xmlTypeClass))).booleanValue()) {
DBDictionary dict = ((MappingRepository) getRepository())
.getDBDictionary();
if (dict.supportsXMLColumn)
diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
index e4e8b9bbe..60834deea 100644
--- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
+++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceMetaDataParser.java
@@ -465,9 +465,14 @@ public class AnnotationPersistenceMetaDataParser
// check immediately whether the user is using any annotations,
// regardless of mode. this prevents adding non-entity classes to
// repository if we're ignoring these annotations in mapping mode
- if (!_cls.isAnnotationPresent(Entity.class)
- && !_cls.isAnnotationPresent(Embeddable.class)
- && !_cls.isAnnotationPresent(MappedSuperclass.class))
+ if (!((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(_cls, Entity.class))).booleanValue()
+ && !((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(_cls, Embeddable.class)))
+ .booleanValue()
+ && !((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(_cls, MappedSuperclass.class)))
+ .booleanValue())
return null;
// find / create metadata
@@ -762,7 +767,9 @@ public class AnnotationPersistenceMetaDataParser
J2DoPrivHelper.getDeclaredFieldsAction(
meta.getDescribedType()));
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());
}
}
@@ -818,7 +825,8 @@ public class AnnotationPersistenceMetaDataParser
MetaDataDefaults def = repos.getMetaDataFactory().getDefaults();
for (Method m : methods) {
- for (Annotation anno : m.getDeclaredAnnotations()) {
+ for (Annotation anno : (Annotation[]) AccessController
+ .doPrivileged(J2DoPrivHelper.getDeclaredAnnotationsAction(m))) {
MetaDataTag tag = _tags.get(anno.annotationType());
if (tag == null)
continue;
@@ -956,7 +964,8 @@ public class AnnotationPersistenceMetaDataParser
fmd.setExplicit(true);
AnnotatedElement el = (AnnotatedElement) member;
- boolean lob = el.isAnnotationPresent(Lob.class);
+ boolean lob = ((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(el, Lob.class))).booleanValue();
if (isMetaDataMode()) {
switch (pstrat) {
case BASIC:
diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
index 9ec4cf29e..845bcc05b 100644
--- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
+++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/AnnotationPersistenceXMLMetaDataParser.java
@@ -22,10 +22,12 @@ import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
+import java.security.AccessController;
import org.apache.commons.lang.StringUtils;
import org.apache.openjpa.conf.OpenJPAConfiguration;
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.meta.DelegatingMetaDataFactory;
import org.apache.openjpa.meta.FieldMetaData;
@@ -171,8 +173,11 @@ public class AnnotationPersistenceXMLMetaDataParser {
private XMLMetaData parseXMLClassAnnotations() {
// check immediately whether the class has JAXB XML annotations
if (_cls == null || xmlTypeClass == null
- || !(_cls.isAnnotationPresent(xmlTypeClass)
- && _cls.isAnnotationPresent(xmlRootElementClass)))
+ || !(((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(_cls, xmlTypeClass))).booleanValue()
+ && ((Boolean) AccessController
+ .doPrivileged(J2DoPrivHelper.isAnnotationPresentAction(_cls,
+ xmlRootElementClass))).booleanValue()))
return null;
// find / create metadata
@@ -220,7 +225,9 @@ public class AnnotationPersistenceXMLMetaDataParser {
Class superclass = cls.getSuperclass();
// handle inheritance at sub-element level
- if (superclass.isAnnotationPresent(xmlTypeClass))
+ if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(superclass, xmlTypeClass)))
+ .booleanValue())
populateFromReflection(superclass, meta);
try {
@@ -240,8 +247,9 @@ public class AnnotationPersistenceXMLMetaDataParser {
// avoid JAXB XML bind default name
if (StringUtils.equals(XMLMetaData.defaultName, xmlname))
xmlname = member.getName();
- if (((Field) member).getType()
- .isAnnotationPresent(xmlTypeClass)) {
+ if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(((Field) member).getType(),
+ xmlTypeClass))).booleanValue()) {
field = _repos.addXMLMetaData(((Field) member).getType()
, member.getName());
parseXmlRootElement(((Field) member).getType(), field);
diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
index 052ba83b6..cba14fbfc 100644
--- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
+++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataDefaults.java
@@ -116,7 +116,8 @@ public class PersistenceMetaDataDefaults
if (member == null)
return null;
AnnotatedElement el = (AnnotatedElement) member;
- if (el.isAnnotationPresent(Transient.class))
+ if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(el, Transient.class))).booleanValue())
return TRANSIENT;
if (fmd != null
&& fmd.getManagement() != FieldMetaData.MANAGE_PERSISTENT)
@@ -182,7 +183,8 @@ public class PersistenceMetaDataDefaults
}
//### EJB3: what if defined in XML?
- if (type.isAnnotationPresent(Embeddable.class))
+ if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(type, Embeddable.class))).booleanValue())
return EMBEDDED;
if (Serializable.class.isAssignableFrom(type))
return BASIC;
@@ -271,7 +273,8 @@ public class PersistenceMetaDataDefaults
Annotation[] annos;
String name;
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++) {
name = annos[j].annotationType().getName();
if ((name.startsWith("javax.persistence.")
@@ -317,7 +320,9 @@ public class PersistenceMetaDataDefaults
private boolean isAnnotatedTransient(Member member) {
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) {
diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
index e025b3088..665aea56c 100644
--- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
+++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/PersistenceMetaDataFactory.java
@@ -293,18 +293,26 @@ public class PersistenceMetaDataFactory
return null;
Collection classes = repos.loadPersistentTypes(false, loader);
for (Class cls : (Collection) classes) {
- if (cls.isAnnotationPresent(NamedQuery.class) && hasNamedQuery
+ if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(cls, NamedQuery.class)))
+ .booleanValue() && hasNamedQuery
(queryName, (NamedQuery) cls.getAnnotation(NamedQuery.class)))
return cls;
- if (cls.isAnnotationPresent(NamedQueries.class) &&
+ if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(cls, NamedQueries.class)))
+ .booleanValue() &&
hasNamedQuery(queryName, ((NamedQueries) cls.
getAnnotation(NamedQueries.class)).value()))
return cls;
- if (cls.isAnnotationPresent(NamedNativeQuery.class) &&
+ if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(cls, NamedNativeQuery.class)))
+ .booleanValue() &&
hasNamedNativeQuery(queryName, (NamedNativeQuery) cls.
getAnnotation(NamedNativeQuery.class)))
return cls;
- if (cls.isAnnotationPresent(NamedNativeQueries.class) &&
+ if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(cls, NamedNativeQueries.class)))
+ .booleanValue() &&
hasNamedNativeQuery(queryName, ((NamedNativeQueries) cls.
getAnnotation(NamedNativeQueries.class)).value()))
return cls;
@@ -320,13 +328,17 @@ public class PersistenceMetaDataFactory
Collection classes = repos.loadPersistentTypes(false, loader);
for (Class cls : (Collection) classes) {
-
- if (cls.isAnnotationPresent(SqlResultSetMapping.class) &&
+
+ if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(cls, SqlResultSetMapping.class)))
+ .booleanValue() &&
hasRSMapping(rsMappingName, (SqlResultSetMapping) cls.
getAnnotation(SqlResultSetMapping.class)))
return cls;
-
- if (cls.isAnnotationPresent(SqlResultSetMappings.class) &&
+
+ if (((Boolean) AccessController.doPrivileged(J2DoPrivHelper
+ .isAnnotationPresentAction(cls, SqlResultSetMappings.class)))
+ .booleanValue() &&
hasRSMapping(rsMappingName, ((SqlResultSetMappings) cls.
getAnnotation(SqlResultSetMappings.class)).value()))
return cls;