[jboss-cvs] JBossAS SVN: r78089 - projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Sep 5 11:33:32 EDT 2008
Author: adrian at jboss.org
Date: 2008-09-05 11:33:32 -0400 (Fri, 05 Sep 2008)
New Revision: 78089
Added:
projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/SecurityActions.java
Modified:
projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
Log:
[JBMDR-42] - Use privileged blocks for ReflectionsUtils.find* when there is a security manager
Modified: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java 2008-09-05 15:24:10 UTC (rev 78088)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/AnnotatedElementMetaDataLoader.java 2008-09-05 15:33:32 UTC (rev 78089)
@@ -46,7 +46,6 @@
import org.jboss.metadata.spi.signature.MethodParametersSignature;
import org.jboss.metadata.spi.signature.MethodSignature;
import org.jboss.metadata.spi.signature.Signature;
-import org.jboss.reflect.plugins.introspection.ReflectionUtils;
import org.jboss.util.JBossStringBuilder;
import org.jboss.util.Strings;
@@ -131,7 +130,7 @@
ConstructorSignature constructorSignature = (ConstructorSignature) signature;
Constructor<?> constructor = constructorSignature.getConstructor();
if (constructor == null)
- constructor = ReflectionUtils.findConstructor(clazz, signature.getParametersTypes(clazz));
+ constructor = SecurityActions.findConstructor(clazz, signature.getParametersTypes(clazz));
if (constructor == null)
{
if (log.isTraceEnabled())
@@ -145,7 +144,7 @@
MethodSignature methodSignature = (MethodSignature) signature;
Method method = methodSignature.getMethod();
if (method == null)
- method = ReflectionUtils.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ method = SecurityActions.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
if (method == null)
{
if (log.isTraceEnabled())
@@ -163,7 +162,7 @@
clazz = getDeclaringClass(clazz, methodSignature.getDeclaringClass());
if (clazz == null)
return null;
- method = ReflectionUtils.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ method = SecurityActions.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
}
if (method == null)
{
@@ -178,7 +177,7 @@
MethodParametersSignature methodParametersSignature = (MethodParametersSignature) signature;
Method method = methodParametersSignature.getMethod();
if (method == null)
- method = ReflectionUtils.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
+ method = SecurityActions.findMethod(clazz, signature.getName(), signature.getParametersTypes(clazz));
if (method == null)
{
if (log.isTraceEnabled())
@@ -193,7 +192,7 @@
ConstructorParametersSignature constructorParametersSignature = (ConstructorParametersSignature) signature;
Constructor<?> constructor = constructorParametersSignature.getConstructor();
if (constructor == null)
- constructor = ReflectionUtils.findConstructor(clazz, signature.getParametersTypes(clazz));
+ constructor = SecurityActions.findConstructor(clazz, signature.getParametersTypes(clazz));
if (constructor == null)
{
if (log.isTraceEnabled())
@@ -208,7 +207,7 @@
FieldSignature fieldSignature = (FieldSignature) signature;
Field field = fieldSignature.getField();
if (field == null)
- field = ReflectionUtils.findField(clazz, signature.getName());
+ field = SecurityActions.findField(clazz, signature.getName());
if (field == null)
{
if (log.isTraceEnabled())
Added: projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/SecurityActions.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/SecurityActions.java (rev 0)
+++ projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/loader/reflection/SecurityActions.java 2008-09-05 15:33:32 UTC (rev 78089)
@@ -0,0 +1,107 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.loader.reflection;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import org.jboss.reflect.plugins.introspection.ReflectionUtils;
+
+/**
+ * SecurityActions.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+class SecurityActions
+{
+ /**
+ * Find the method by name and parameters.
+ *
+ * @param clazz the class to look for method
+ * @param name the name
+ * @param parameterTypes the types
+ * @return method or null if not found
+ */
+ static Method findMethod(final Class<?> clazz, final String name, final Class<?>... parameterTypes)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return ReflectionUtils.findMethod(clazz, name, parameterTypes);
+
+ return AccessController.doPrivileged(new PrivilegedAction<Method>()
+ {
+ public Method run()
+ {
+ return ReflectionUtils.findMethod(clazz, name, parameterTypes);
+ }
+ });
+ }
+
+
+ /**
+ * Find the field by name.
+ *
+ * @param clazz the class to look for field
+ * @param name the name
+ * @return field or null if not found
+ */
+ static Field findField(final Class<?> clazz, final String name)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return ReflectionUtils.findField(clazz, name);
+
+ return AccessController.doPrivileged(new PrivilegedAction<Field>()
+ {
+ public Field run()
+ {
+ return ReflectionUtils.findField(clazz, name);
+ }
+ });
+ }
+
+ /**
+ * Find the constructor by parameters.
+ *
+ * @param clazz the class to look for constructor
+ * @param parameterTypes the types
+ * @return constructor or null if not found
+ */
+ static Constructor<?> findConstructor(final Class<?> clazz, final Class<?>... parameterTypes)
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm == null)
+ return ReflectionUtils.findConstructor(clazz, parameterTypes);
+
+ return AccessController.doPrivileged(new PrivilegedAction<Constructor<?>>()
+ {
+ public Constructor<?> run()
+ {
+ return ReflectionUtils.findConstructor(clazz, parameterTypes);
+ }
+ });
+ }
+}
More information about the jboss-cvs-commits
mailing list