From 73dfbf3e677f329c1eb3d1f6edbb3d81c5931be8 Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 20 Dec 2011 19:32:07 +0000 Subject: TUSCANY-3992: Apply patch from Greg Dritschler to fix AccessControlException occurs when calling SCAClientFactory.getService git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1221454 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/impl/JavaInterfaceIntrospectorImpl.java | 56 ++++++++++++---------- .../java/impl/JavaIntrospectionHelper.java | 10 ---- 2 files changed, 32 insertions(+), 34 deletions(-) (limited to 'sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache') diff --git a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java index d3b813f7aa..6611c6af79 100644 --- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java +++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaInterfaceIntrospectorImpl.java @@ -28,6 +28,8 @@ import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.rmi.Remote; import java.rmi.RemoteException; +import java.security.AccessController; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -147,33 +149,39 @@ public class JavaInterfaceIntrospectorImpl { // Check if any methods have disallowed annotations // Check if any private methods have illegal annotations that should be raised as errors - Set methods = JavaIntrospectionHelper.getMethods(clazz); - for (Method method : methods) { - checkMethodAnnotations(method, javaInterface); - } // end for + checkMethodAnnotations(clazz, javaInterface); } // end method introspectInterface - private void checkMethodAnnotations(Method method, JavaInterface javaInterface) throws InvalidAnnotationException { - for ( Annotation a : method.getAnnotations() ) { - if( a instanceof Remotable ) { - // [JCA90053] @Remotable annotation cannot be on a method that is not a setter method - if( !JavaIntrospectionHelper.isSetter(method) ) { - throw new InvalidAnnotationException("[JCA90053] @Remotable annotation present on an interface method" + - " which is not a Setter method: " + javaInterface.getName() + "/" + method.getName(), Remotable.class); - } // end if - } // end if - } // end for + private void checkMethodAnnotations(Class clazz, JavaInterface javaInterface) throws InvalidAnnotationException { - // Parameter annotations - for (Annotation[] parmAnnotations : method.getParameterAnnotations()) { - for (Annotation annotation : parmAnnotations) { - if (annotation instanceof Remotable ) { - throw new InvalidAnnotationException("[JCA90053] @Remotable annotation present on an interface method" + - " parameter: " + javaInterface.getName() + "/" + method.getName(), Remotable.class); - } // end if - } // end for - } // end for - method.getParameterAnnotations(); + final Class _clazz = clazz; + Method[] declaredMethods = (Method[])AccessController.doPrivileged(new PrivilegedAction() { + public Method[] run() { + return _clazz.getDeclaredMethods(); + } + }); + + for (final Method method : declaredMethods) { + for ( Annotation a : method.getAnnotations() ) { + if( a instanceof Remotable ) { + // [JCA90053] @Remotable annotation cannot be on a method that is not a setter method + if( !JavaIntrospectionHelper.isSetter(method) ) { + throw new InvalidAnnotationException("[JCA90053] @Remotable annotation present on an interface method" + + " which is not a Setter method: " + javaInterface.getName() + "/" + method.getName(), Remotable.class); + } // end if + } // end if + } // end for + + // Parameter annotations + for (Annotation[] parmAnnotations : method.getParameterAnnotations()) { + for (Annotation annotation : parmAnnotations) { + if (annotation instanceof Remotable ) { + throw new InvalidAnnotationException("[JCA90053] @Remotable annotation present on an interface method" + + " parameter: " + javaInterface.getName() + "/" + method.getName(), Remotable.class); + } // end if + } // end for + } // end for + } } // end method checkMethodAnnotations private Class[] getActualTypes(Type[] types, Class[] rawTypes, Map typeBindings, boolean ignoreAsyncHolder) { diff --git a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaIntrospectionHelper.java b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaIntrospectionHelper.java index a363c1ff16..c207245a0e 100644 --- a/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaIntrospectionHelper.java +++ b/sca-java-2.x/trunk/modules/interface-java/src/main/java/org/apache/tuscany/sca/interfacedef/java/impl/JavaIntrospectionHelper.java @@ -616,16 +616,6 @@ public final class JavaIntrospectionHelper { return Class.forName(buf.toString(), false, componentType.getClassLoader()); } - public static Set getMethods(Class clazz) { - Set methods = new HashSet(); - Method[] declaredMethods = clazz.getDeclaredMethods(); - for (final Method declaredMethod : declaredMethods) { - methods.add(declaredMethod); - } // end for - - return methods; - } // end method getMethods - public static Set getPrivateFields(Class clazz) { Set fields = new HashSet(); Field[] declaredFields = clazz.getDeclaredFields(); -- cgit v1.2.3