You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@deltaspike.apache.org by st...@apache.org on 2012/04/24 20:09:00 UTC

git commit: DELTASPIKE-167 remove public static doPrivileged helper

Updated Branches:
  refs/heads/master 973586980 -> 35eb43892


DELTASPIKE-167 remove public static doPrivileged helper


Project: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/commit/35eb4389
Tree: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/tree/35eb4389
Diff: http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/diff/35eb4389

Branch: refs/heads/master
Commit: 35eb438923bb817dae17f75026d108641ff6aabb
Parents: 9735869
Author: Mark Struberg <st...@apache.org>
Authored: Tue Apr 24 20:06:18 2012 +0200
Committer: Mark Struberg <st...@apache.org>
Committed: Tue Apr 24 20:07:51 2012 +0200

----------------------------------------------------------------------
 .../deltaspike/core/util/ReflectionUtils.java      |   44 +-------------
 .../core/util/SetAccessiblePrivilegedAction.java   |   47 ---------------
 .../metadata/builder/AnnotatedTypeBuilder.java     |    6 +-
 .../SetAccessiblePrivilegedAction.java             |   47 +++++++++++++++
 4 files changed, 54 insertions(+), 90 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/35eb4389/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ReflectionUtils.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ReflectionUtils.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ReflectionUtils.java
index 2953203..31b87fb 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ReflectionUtils.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ReflectionUtils.java
@@ -20,10 +20,7 @@
 package org.apache.deltaspike.core.util;
 
 import javax.enterprise.inject.Typed;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedType;
 import java.io.Serializable;
-import java.lang.reflect.AccessibleObject;
 import java.lang.reflect.Field;
 import java.lang.reflect.Member;
 import java.lang.reflect.Method;
@@ -36,6 +33,8 @@ import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
 
+import org.apache.deltaspike.core.util.securitymanaged.SetAccessiblePrivilegedAction;
+
 /**
  * Utilities for common reflection based actions. Some are basic Java Reflection based, others are CDI based.
  */
@@ -114,27 +113,6 @@ public abstract class ReflectionUtils
     }
 
     /**
-     * Search the annotatedType for the field, returning the
-     * {@link AnnotatedField}
-     *
-     * @param annotatedType The annotatedType to search
-     * @param field         the field to search for
-     * @return The {@link AnnotatedField} found, or null if no field is found
-     */
-    public static <X> AnnotatedField<? super X> getField(AnnotatedType<X> annotatedType, Field field)
-    {
-        for (AnnotatedField<? super X> annotatedField : annotatedType.getFields())
-        {
-            if (annotatedField.getDeclaringType().getJavaClass().equals(field.getDeclaringClass()) &&
-                    annotatedField.getJavaMember().getName().equals(field.getName()))
-            {
-                return annotatedField;
-            }
-        }
-        return null;
-    }
-
-    /**
      * Get all the declared methods on the class hierarchy. This <b>will</b>
      * return overridden methods.
      *
@@ -167,22 +145,6 @@ public abstract class ReflectionUtils
     }
 
     /**
-     * Set the accessibility flag on the {@link AccessibleObject} as described in
-     * {@link AccessibleObject#setAccessible(boolean)} within the context of
-     * a {@link java.security.PrivilegedAction}.
-     *
-     * @param <A>    member the accessible object type
-     * @param member the accessible object
-     * @return the accessible object after the accessible flag has been altered
-     */
-    @Deprecated //X TODO use SecurityService of OWB
-    public static <A extends AccessibleObject> A setAccessible(A member)
-    {
-        AccessController.doPrivileged(new SetAccessiblePrivilegedAction(member));
-        return member;
-    }
-
-    /**
      * <p>
      * Invoke the method on the instance, with any arguments specified, casting
      * the result of invoking the method to the expected return type.
@@ -233,7 +195,7 @@ public abstract class ReflectionUtils
     {
         if (setAccessible && !method.isAccessible())
         {
-            setAccessible(method);
+            AccessController.doPrivileged(new SetAccessiblePrivilegedAction(method));
         }
 
         try

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/35eb4389/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/SetAccessiblePrivilegedAction.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/SetAccessiblePrivilegedAction.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/SetAccessiblePrivilegedAction.java
deleted file mode 100644
index ff5c315..0000000
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/SetAccessiblePrivilegedAction.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.deltaspike.core.util;
-
-import javax.enterprise.inject.Typed;
-import java.lang.reflect.AccessibleObject;
-import java.security.PrivilegedAction;
-
-/**
- * PrivilegedAction instance to enabling access to the specified {@link AccessibleObject}.
- */
-@Typed()
-//TODO replace it with the SecurityService of OWB
-public class SetAccessiblePrivilegedAction implements PrivilegedAction<Void>
-{
-
-    private final AccessibleObject member;
-
-    public SetAccessiblePrivilegedAction(AccessibleObject member)
-    {
-        this.member = member;
-    }
-
-    public Void run()
-    {
-        member.setAccessible(true);
-        return null;
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/35eb4389/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotatedTypeBuilder.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotatedTypeBuilder.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotatedTypeBuilder.java
index 9aa072e..07ef1d9 100644
--- a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotatedTypeBuilder.java
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotatedTypeBuilder.java
@@ -20,6 +20,7 @@
 package org.apache.deltaspike.core.util.metadata.builder;
 
 import org.apache.deltaspike.core.util.ReflectionUtils;
+import org.apache.deltaspike.core.util.securitymanaged.SetAccessiblePrivilegedAction;
 
 import javax.enterprise.inject.spi.Annotated;
 import javax.enterprise.inject.spi.AnnotatedConstructor;
@@ -32,6 +33,7 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
+import java.security.AccessController;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -657,7 +659,7 @@ public class AnnotatedTypeBuilder<X>
                 annotationBuilder = new AnnotationBuilder();
                 fields.put(field, annotationBuilder);
             }
-            ReflectionUtils.setAccessible(field);
+            AccessController.doPrivileged(new SetAccessiblePrivilegedAction(field));
 
             for (Annotation annotation : field.getAnnotations())
             {
@@ -676,7 +678,7 @@ public class AnnotatedTypeBuilder<X>
                 annotationBuilder = new AnnotationBuilder();
                 methods.put(method, annotationBuilder);
             }
-            ReflectionUtils.setAccessible(method);
+            AccessController.doPrivileged(new SetAccessiblePrivilegedAction(method));
 
             for (Annotation annotation : method.getAnnotations())
             {

http://git-wip-us.apache.org/repos/asf/incubator-deltaspike/blob/35eb4389/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/securitymanaged/SetAccessiblePrivilegedAction.java
----------------------------------------------------------------------
diff --git a/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/securitymanaged/SetAccessiblePrivilegedAction.java b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/securitymanaged/SetAccessiblePrivilegedAction.java
new file mode 100644
index 0000000..e995a8e
--- /dev/null
+++ b/deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/securitymanaged/SetAccessiblePrivilegedAction.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.deltaspike.core.util.securitymanaged;
+
+import javax.enterprise.inject.Typed;
+import java.lang.reflect.AccessibleObject;
+import java.security.PrivilegedAction;
+
+/**
+ * PrivilegedAction instance to enabling access to the specified {@link AccessibleObject}.
+ */
+@Typed()
+//TODO replace it with the SecurityService of OWB
+public class SetAccessiblePrivilegedAction implements PrivilegedAction<Void>
+{
+
+    private final AccessibleObject member;
+
+    public SetAccessiblePrivilegedAction(AccessibleObject member)
+    {
+        this.member = member;
+    }
+
+    public Void run()
+    {
+        member.setAccessible(true);
+        return null;
+    }
+
+}