You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by as...@apache.org on 2013/07/24 18:44:02 UTC
svn commit: r1506621 - in /cxf/branches/2.7.x-fixes:
api/src/main/java/org/apache/cxf/common/injection/
api/src/main/java/org/apache/cxf/common/logging/
api/src/main/java/org/apache/cxf/common/util/
api/src/main/java/org/apache/cxf/wsdl/ rt/core/src/ma...
Author: asoldano
Date: Wed Jul 24 16:44:02 2013
New Revision: 1506621
URL: http://svn.apache.org/r1506621
Log:
[CXF-5142] Initial set of changes for running jaxws client with security manager on
Modified:
cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java
cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java?rev=1506621&r1=1506620&r2=1506621&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java (original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/injection/ResourceInjector.java Wed Jul 24 16:44:02 2013
@@ -24,6 +24,8 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
@@ -388,14 +390,14 @@ public class ResourceInjector extends Ab
Collection<Method> methods = new LinkedList<Method>();
addAnnotatedMethods(acls, getTarget().getClass().getMethods(), methods);
- addAnnotatedMethods(acls, getTarget().getClass().getDeclaredMethods(), methods);
+ addAnnotatedMethods(acls, ReflectionUtil.getDeclaredMethods(getTarget().getClass()), methods);
if (getTargetClass() != getTarget().getClass()) {
addAnnotatedMethods(acls, getTargetClass().getMethods(), methods);
- addAnnotatedMethods(acls, getTargetClass().getDeclaredMethods(), methods);
+ addAnnotatedMethods(acls, ReflectionUtil.getDeclaredMethods(getTargetClass()), methods);
}
return methods;
- }
-
+ }
+
private void addAnnotatedMethods(Class<? extends Annotation> acls, Method[] methods,
Collection<Method> annotatedMethods) {
for (Method method : methods) {
Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java?rev=1506621&r1=1506620&r2=1506621&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java (original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/logging/LogUtils.java Wed Jul 24 16:44:02 2013
@@ -235,7 +235,7 @@ public final class LogUtils {
ClassLoader orig = Thread.currentThread().getContextClassLoader();
ClassLoader n = cls.getClassLoader();
if (n != null) {
- Thread.currentThread().setContextClassLoader(n);
+ setContextClassLoader(n);
}
String bundleName = name;
try {
@@ -304,10 +304,19 @@ public final class LogUtils {
return logger;
} finally {
if (n != orig) {
- Thread.currentThread().setContextClassLoader(orig);
+ setContextClassLoader(orig);
}
}
}
+
+ private static void setContextClassLoader(final ClassLoader classLoader) {
+ AccessController.doPrivileged(new PrivilegedAction<Object>() {
+ public Object run() {
+ Thread.currentThread().setContextClassLoader(classLoader);
+ return null;
+ }
+ });
+ }
/**
* Allows both parameter substitution and a typed Throwable to be logged.
Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java?rev=1506621&r1=1506620&r2=1506621&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java (original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/common/util/ReflectionUtil.java Wed Jul 24 16:44:02 2013
@@ -32,6 +32,8 @@ import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.security.AccessController;
import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.List;
@@ -113,6 +115,25 @@ public final class ReflectionUtil {
}
});
}
+
+ public static Method getDeclaredMethod(final Class<?> clazz, final String name,
+ final Class<?>... parameterTypes) throws NoSuchMethodException {
+ try {
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Method>() {
+ public Method run() throws Exception {
+ return clazz.getDeclaredMethod(name, parameterTypes);
+ }
+ });
+ } catch (PrivilegedActionException pae) {
+ Exception e = pae.getException();
+ if (e instanceof NoSuchMethodException) {
+ throw (NoSuchMethodException)e;
+ } else {
+ throw new SecurityException(e);
+ }
+ }
+ }
+
public static Field[] getDeclaredFields(final Class<?> cls) {
return AccessController.doPrivileged(new PrivilegedAction<Field[]>() {
public Field[] run() {
Modified: cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java?rev=1506621&r1=1506620&r2=1506621&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java (original)
+++ cxf/branches/2.7.x-fixes/api/src/main/java/org/apache/cxf/wsdl/JAXBExtensionHelper.java Wed Jul 24 16:44:02 2013
@@ -54,6 +54,7 @@ import org.apache.cxf.common.jaxb.JAXBCo
import org.apache.cxf.common.jaxb.JAXBContextCache.CachedContextAndSchemas;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.common.util.ReflectionUtil;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.helpers.CastUtils;
import org.apache.cxf.staxutils.StaxUtils;
@@ -118,9 +119,9 @@ public class JAXBExtensionHelper impleme
JAXBExtensionHelper helper = new JAXBExtensionHelper(cls, namespace);
boolean found = false;
try {
- Class<?> objectFactory = Class.forName(PackageUtils.getPackageName(cls) + ".ObjectFactory",
- true, cls.getClassLoader());
- Method methods[] = objectFactory.getDeclaredMethods();
+ Class<?> objectFactory = Class.forName(PackageUtils.getPackageName(cls) + ".ObjectFactory", true,
+ cls.getClassLoader());
+ Method methods[] = ReflectionUtil.getDeclaredMethods(objectFactory);
for (Method method : methods) {
if (method.getParameterTypes().length == 1
&& method.getParameterTypes()[0].equals(cls)) {
Modified: cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java?rev=1506621&r1=1506620&r2=1506621&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java (original)
+++ cxf/branches/2.7.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/extension/ExtensionManagerImpl.java Wed Jul 24 16:44:02 2013
@@ -23,6 +23,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
import java.util.Collection;
import java.util.Enumeration;
import java.util.LinkedHashMap;
@@ -159,8 +162,17 @@ public class ExtensionManagerImpl implem
Enumeration<URL> urls = l.getResources(resource);
while (urls.hasMoreElements()) {
- URL url = urls.nextElement();
- InputStream is = url.openStream();
+ final URL url = urls.nextElement();
+ InputStream is;
+ try {
+ is = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() {
+ public InputStream run() throws Exception {
+ return url.openStream();
+ }
+ });
+ } catch (PrivilegedActionException pae) {
+ throw (IOException)pae.getException();
+ }
try {
List<Extension> exts;
if (resource.endsWith("xml")) {
Modified: cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java?rev=1506621&r1=1506620&r2=1506621&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java (original)
+++ cxf/branches/2.7.x-fixes/rt/databinding/jaxb/src/main/java/org/apache/cxf/jaxb/JAXBDataBinding.java Wed Jul 24 16:44:02 2013
@@ -27,6 +27,8 @@ import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -803,9 +805,10 @@ public class JAXBDataBinding extends Abs
objectFactory);
}
- private static Field getElField(String partName, Class<?> wrapperType) {
+ private static Field getElField(String partName, final Class<?> wrapperType) {
String fieldName = JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.VARIABLE);
- for (Field field : wrapperType.getDeclaredFields()) {
+ Field[] fields = ReflectionUtil.getDeclaredFields(wrapperType);
+ for (Field field : fields) {
XmlElement el = field.getAnnotation(XmlElement.class);
if (el != null
&& partName.equals(el.name())) {
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java?rev=1506621&r1=1506620&r2=1506621&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ServiceImpl.java Wed Jul 24 16:44:02 2013
@@ -59,6 +59,7 @@ import org.apache.cxf.binding.BindingFac
import org.apache.cxf.binding.soap.wsdl.extensions.SoapAddress;
import org.apache.cxf.binding.soap.wsdl.extensions.SoapBinding;
import org.apache.cxf.common.i18n.Message;
+import org.apache.cxf.common.i18n.UncheckedException;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.PackageUtils;
import org.apache.cxf.common.util.StringUtils;
@@ -196,6 +197,9 @@ public class ServiceImpl extends Service
} catch (WebServiceException e) {
throw e;
} catch (Throwable e) {
+ if (e instanceof UncheckedException && LOG.isLoggable(Level.FINE)) {
+ LOG.log(Level.FINE, e.getLocalizedMessage(), e);
+ }
WSDLServiceFactory sf = new WSDLServiceFactory(bus, wsdlURL, serviceName);
Service service = sf.create();
for (ServiceInfo si : service.getServiceInfos()) {
Modified: cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java?rev=1506621&r1=1506620&r2=1506621&view=diff
==============================================================================
--- cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java (original)
+++ cxf/branches/2.7.x-fixes/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/support/JaxWsServiceFactoryBean.java Wed Jul 24 16:44:02 2013
@@ -56,6 +56,7 @@ import org.apache.cxf.common.i18n.Messag
import org.apache.cxf.common.injection.NoJSR250Annotations;
import org.apache.cxf.common.logging.LogUtils;
import org.apache.cxf.common.util.PackageUtils;
+import org.apache.cxf.common.util.ReflectionUtil;
import org.apache.cxf.common.util.StringUtils;
import org.apache.cxf.common.util.XMLSchemaQNames;
import org.apache.cxf.databinding.DataBinding;
@@ -263,16 +264,17 @@ public class JaxWsServiceFactoryBean ext
try {
// Find the Async method which returns a Response
- Method responseMethod = method.getDeclaringClass().getDeclaredMethod(method.getName() + "Async",
- method.getParameterTypes());
+ Method responseMethod = ReflectionUtil.getDeclaredMethod(method.getDeclaringClass(),
+ method.getName() + "Async",
+ method.getParameterTypes());
// Find the Async method whic has a Future & AsyncResultHandler
List<Class<?>> asyncHandlerParams = Arrays.asList(method.getParameterTypes());
//copy it to may it non-readonly
asyncHandlerParams = new ArrayList<Class<?>>(asyncHandlerParams);
asyncHandlerParams.add(AsyncHandler.class);
- Method futureMethod = method.getDeclaringClass()
- .getDeclaredMethod(method.getName() + "Async",
+ Method futureMethod = ReflectionUtil
+ .getDeclaredMethod(method.getDeclaringClass(), method.getName() + "Async",
asyncHandlerParams.toArray(new Class<?>[asyncHandlerParams.size()]));
getMethodDispatcher().bind(op, method, responseMethod, futureMethod);
@@ -283,7 +285,7 @@ public class JaxWsServiceFactoryBean ext
getMethodDispatcher().bind(op, method);
}
}
-
+
@Override
protected void initializeWSDLOperations() {
if (implInfo.isWebServiceProvider()) {