cxf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Kulp <dk...@apache.org>
Subject Re: svn commit: r1400082 - in /cxf/trunk: api/src/main/java/org/apache/cxf/configuration/spring/ rt/transports/http/src/main/java/org/apache/cxf/transport/http/ testutils/src/main/java/org/apache/cxf/testutil/common/
Date Fri, 19 Oct 2012 14:00:25 GMT

Colm,

We have a utility for this:

ReflectionUtil.setAccessible(….)

Ideally, the calls to cls.getDeclaredField  would be replaced with calls to ReflectionUtil.getDeclaredField(…)
as well for the same reason.

Dan



On Oct 19, 2012, at 9:14 AM, coheigea@apache.org wrote:

> Author: coheigea
> Date: Fri Oct 19 13:14:25 2012
> New Revision: 1400082
> 
> URL: http://svn.apache.org/viewvc?rev=1400082&view=rev
> Log:
> Minor cleanup
> 
> Modified:
>    cxf/trunk/api/src/main/java/org/apache/cxf/configuration/spring/SpringBeanQNameMap.java
>    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java
>    cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractClientServerTestBase.java
> 
> Modified: cxf/trunk/api/src/main/java/org/apache/cxf/configuration/spring/SpringBeanQNameMap.java
> URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/configuration/spring/SpringBeanQNameMap.java?rev=1400082&r1=1400081&r2=1400082&view=diff
> ==============================================================================
> --- cxf/trunk/api/src/main/java/org/apache/cxf/configuration/spring/SpringBeanQNameMap.java
(original)
> +++ cxf/trunk/api/src/main/java/org/apache/cxf/configuration/spring/SpringBeanQNameMap.java
Fri Oct 19 13:14:25 2012
> @@ -19,6 +19,8 @@
> package org.apache.cxf.configuration.spring;
> 
> import java.lang.reflect.Field;
> +import java.security.AccessController;
> +import java.security.PrivilegedAction;
> import java.util.ArrayList;
> import java.util.Collection;
> 
> @@ -83,8 +85,14 @@ public class SpringBeanQNameMap<V> 
>                 if (ids == null && staticFieldName != null) {
>                     Class<?> cls = context.getType(beanNames[i]);
>                     try {
> -                        Field f = cls.getDeclaredField(staticFieldName);
> -                        f.setAccessible(true);
> +                        final Field f = cls.getDeclaredField(staticFieldName);
> +                        AccessController.doPrivileged(new PrivilegedAction<Void>()
{
> +                            public Void run() {
> +                                f.setAccessible(true);
> +                                return null;
> +                            }
> +                        });
> +
>                         Collection<QName> sids = CastUtils.cast((Collection<?>)f.get(null));
>                         if (sids != null) {
>                             ids = new ArrayList<QName>(sids);
> 
> Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java
> URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java?rev=1400082&r1=1400081&r2=1400082&view=diff
> ==============================================================================
> --- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java
(original)
> +++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/transport/http/CXFAuthenticator.java
Fri Oct 19 13:14:25 2012
> @@ -24,6 +24,8 @@ import java.lang.reflect.Method;
> import java.lang.reflect.Modifier;
> import java.net.Authenticator;
> import java.net.PasswordAuthentication;
> +import java.security.AccessController;
> +import java.security.PrivilegedAction;
> 
> import org.apache.cxf.message.Exchange;
> import org.apache.cxf.message.Message;
> @@ -40,9 +42,15 @@ public class CXFAuthenticator extends Au
> 
>     public CXFAuthenticator() {
>         try {
> -            for (Field f : Authenticator.class.getDeclaredFields()) {
> +            for (final Field f : Authenticator.class.getDeclaredFields()) {
>                 if (f.getType().equals(Authenticator.class)) {
> -                    f.setAccessible(true);
> +                    AccessController.doPrivileged(new PrivilegedAction<Void>()
{
> +                        public Void run() {
> +                            f.setAccessible(true);
> +                            return null;
> +                        }
> +                    });
> +
>                     wrapped = (Authenticator)f.get(null);
>                 }
>             }
> @@ -66,14 +74,24 @@ public class CXFAuthenticator extends Au
>         PasswordAuthentication auth = null;
>         if (wrapped != null) {
>             try {
> -                for (Field f : Authenticator.class.getDeclaredFields()) {
> +                for (final Field f : Authenticator.class.getDeclaredFields()) {
>                     if (!Modifier.isStatic(f.getModifiers())) {
> -                        f.setAccessible(true);
> +                        AccessController.doPrivileged(new PrivilegedAction<Void>()
{
> +                            public Void run() {
> +                                f.setAccessible(true);
> +                                return null;
> +                            }
> +                        });
>                         f.set(wrapped, f.get(this));
>                     }
>                 }
> -                Method m = Authenticator.class.getDeclaredMethod("getPasswordAuthentication");
> -                m.setAccessible(true);
> +                final Method m = Authenticator.class.getDeclaredMethod("getPasswordAuthentication");
> +                AccessController.doPrivileged(new PrivilegedAction<Void>() {
> +                    public Void run() {
> +                        m.setAccessible(true);
> +                        return null;
> +                    }
> +                });
>                 auth = (PasswordAuthentication)m.invoke(wrapped);
>             } catch (Throwable t) {
>                 //ignore
> 
> Modified: cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractClientServerTestBase.java
> URL: http://svn.apache.org/viewvc/cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractClientServerTestBase.java?rev=1400082&r1=1400081&r2=1400082&view=diff
> ==============================================================================
> --- cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractClientServerTestBase.java
(original)
> +++ cxf/trunk/testutils/src/main/java/org/apache/cxf/testutil/common/AbstractClientServerTestBase.java
Fri Oct 19 13:14:25 2012
> @@ -25,6 +25,8 @@ import java.lang.reflect.Method;
> import java.lang.reflect.Proxy;
> import java.net.MalformedURLException;
> import java.net.URL;
> +import java.security.AccessController;
> +import java.security.PrivilegedAction;
> import java.util.ArrayList;
> import java.util.List;
> import java.util.Map;
> @@ -147,8 +149,14 @@ public abstract class AbstractClientServ
>         }
>         if (c == null) {
>             try {
> -                Method m = o.getClass().getDeclaredMethod("getClient");
> -                m.setAccessible(true);
> +                final Method m = o.getClass().getDeclaredMethod("getClient");
> +                AccessController.doPrivileged(new PrivilegedAction<Void>() {
> +                    public Void run() {
> +                        m.setAccessible(true);
> +                        return null;
> +                    }
> +                });
> +
>                 c = (Client)m.invoke(o);
>             } catch (Throwable t) {
>                 //ignore
> 
> 

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Mime
View raw message