Skip to content

Commit 8b06c87

Browse files
committed
DELTASPIKE-1483 remove SecurityManager
1 parent 359dbb2 commit 8b06c87

File tree

6 files changed

+11
-138
lines changed

6 files changed

+11
-138
lines changed

deltaspike/core/api/obsolete/src/main/java/org/apache/deltaspike/core/util/metadata/builder/AnnotatedTypeBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
package org.apache.deltaspike.core.util.metadata.builder;
2121

2222
import org.apache.deltaspike.core.util.ReflectionUtils;
23-
import org.apache.deltaspike.core.util.securitymanaged.SetAccessiblePrivilegedAction;
2423

2524
import jakarta.enterprise.inject.spi.Annotated;
2625
import jakarta.enterprise.inject.spi.AnnotatedConstructor;

deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ClassUtils.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@
2525
import java.lang.reflect.Modifier;
2626
import java.lang.reflect.ParameterizedType;
2727
import java.lang.reflect.Type;
28-
import java.security.AccessController;
29-
import java.security.PrivilegedAction;
3028
import java.util.jar.Manifest;
3129
import java.util.jar.Attributes;
3230
import java.net.URL;
@@ -61,37 +59,9 @@ private ClassUtils()
6159
*/
6260
public static ClassLoader getClassLoader(Object o)
6361
{
64-
if (System.getSecurityManager() != null)
65-
{
66-
return AccessController.doPrivileged(new GetClassLoaderAction(o));
67-
}
68-
else
69-
{
70-
return getClassLoaderInternal(o);
71-
}
62+
return getClassLoaderInternal(o);
7263
}
7364

74-
static class GetClassLoaderAction implements PrivilegedAction<ClassLoader>
75-
{
76-
private Object object;
77-
GetClassLoaderAction(Object object)
78-
{
79-
this.object = object;
80-
}
81-
82-
@Override
83-
public ClassLoader run()
84-
{
85-
try
86-
{
87-
return getClassLoaderInternal(object);
88-
}
89-
catch (Exception e)
90-
{
91-
return null;
92-
}
93-
}
94-
}
9565

9666
private static ClassLoader getClassLoaderInternal(Object o)
9767
{

deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/ReflectionUtils.java

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,15 @@
3131
import java.lang.reflect.ParameterizedType;
3232
import java.lang.reflect.Type;
3333
import java.lang.reflect.WildcardType;
34-
import java.security.AccessController;
3534
import java.util.Arrays;
3635
import java.util.Collections;
3736
import java.util.HashSet;
3837
import java.util.Set;
3938

40-
import org.apache.deltaspike.core.util.securitymanaged.SetAccessiblePrivilegedAction;
4139

4240
/**
4341
* Utilities for common reflection based actions. Some are basic Java Reflection based, others are CDI based.
4442
*/
45-
//X TODO: Look at merging this with some of the other classes from CODI, or if they're really needed
46-
//X TODO: Also some methods need JavaDoc
4743
@Vetoed
4844
public abstract class ReflectionUtils
4945
{
@@ -179,14 +175,7 @@ public static <T> T invokeMethod(Object instance,
179175
{
180176
if (setAccessible && !method.isAccessible())
181177
{
182-
if (System.getSecurityManager() != null)
183-
{
184-
AccessController.doPrivileged(new SetAccessiblePrivilegedAction(method));
185-
}
186-
else
187-
{
188-
method.setAccessible(true);
189-
}
178+
method.setAccessible(true);
190179
}
191180

192181
try

deltaspike/core/api/src/main/java/org/apache/deltaspike/core/util/securitymanaged/SetAccessiblePrivilegedAction.java

Lines changed: 0 additions & 45 deletions
This file was deleted.

deltaspike/modules/data/impl/src/main/java/org/apache/deltaspike/data/impl/property/Reflections.java

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import java.lang.reflect.Field;
2525
import java.lang.reflect.InvocationTargetException;
2626
import java.lang.reflect.Method;
27-
import java.security.AccessController;
28-
import java.security.PrivilegedAction;
2927
import java.util.HashSet;
3028
import java.util.Set;
3129

@@ -153,25 +151,19 @@ private static String buildInvokeMethodErrorMessage(Method method, Object obj, O
153151

154152
/**
155153
* Set the accessibility flag on the {@link AccessibleObject} as described in
156-
* {@link AccessibleObject#setAccessible(boolean)} within the context of a {@link PrivilegedAction}.
154+
* {@link AccessibleObject#setAccessible(boolean)}.
157155
*
158156
* @param <A>
159157
* member the accessible object type
160158
* @param member
161159
* the accessible object
162160
* @return the accessible object after the accessible flag has been altered
161+
* @deprecated call method directly as SecurityManager got deprecated and will soon be removed from Java
163162
*/
163+
@Deprecated
164164
public static <A extends AccessibleObject> A setAccessible(final A member)
165165
{
166-
AccessController.doPrivileged(new PrivilegedAction<Void>()
167-
{
168-
@Override
169-
public Void run()
170-
{
171-
member.setAccessible(true);
172-
return null;
173-
}
174-
});
166+
member.setAccessible(true);
175167
return member;
176168
}
177169

@@ -202,7 +194,7 @@ public static Object invokeMethod(Method method, Object instance, Object... args
202194
* </p>
203195
* <p/>
204196
* <p>
205-
* This method attempts to set the accessible flag of the method in a {@link PrivilegedAction} before invoking the
197+
* This method attempts to set the accessible flag of the method before invoking the
206198
* method if the first argument is true.
207199
* </p>
208200
* <p/>
@@ -252,7 +244,7 @@ public static <T> T invokeMethod(Method method, Class<T> expectedReturnType, Obj
252244
* </p>
253245
* <p/>
254246
* <p>
255-
* If instructed, this method attempts to set the accessible flag of the method in a {@link PrivilegedAction} before
247+
* If instructed, this method attempts to set the accessible flag of the method before
256248
* invoking the method.
257249
* </p>
258250
*
@@ -329,8 +321,7 @@ public static <T> T invokeMethod(boolean setAccessible, Method method, Class<T>
329321
* <p/>
330322
* <p>
331323
* This method provides the same functionality and throws the same exceptions as
332-
* {@link Reflections#setFieldValue(boolean, Method, Class, Object, Object...)}, honoring the accessibility of the
333-
* field.
324+
* {@link Reflections#setFieldValue(boolean, Field, Object, Object)}
334325
* </p>
335326
*/
336327
public static void setFieldValue(Field field, Object instance, Object value)
@@ -349,7 +340,7 @@ public static void setFieldValue(Field field, Object instance, Object value)
349340
* </p>
350341
* <p/>
351342
* <p>
352-
* If instructed, this method attempts to set the accessible flag of the method in a {@link PrivilegedAction} before
343+
* If instructed, this method attempts to set the accessible flag of the method before
353344
* invoking the method.
354345
* </p>
355346
*

deltaspike/test-utils/src/main/java/org/apache/deltaspike/test/utils/CdiContainerUnderTest.java

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
package org.apache.deltaspike.test.utils;
2020

2121
import java.net.URL;
22-
import java.security.AccessController;
23-
import java.security.PrivilegedAction;
2422
import java.util.jar.Attributes;
2523
import java.util.jar.Manifest;
2624

@@ -121,14 +119,7 @@ private static Class loadClassForName(String name) throws ClassNotFoundException
121119

122120
private static ClassLoader getClassLoader(Object o)
123121
{
124-
if (System.getSecurityManager() != null)
125-
{
126-
return AccessController.doPrivileged(new GetClassLoaderAction(o));
127-
}
128-
else
129-
{
130-
return getClassLoaderInternal(o);
131-
}
122+
return getClassLoaderInternal(o);
132123
}
133124

134125
private static ClassLoader getClassLoaderInternal(Object o)
@@ -203,26 +194,4 @@ private static String getManifestLocation(Class targetClass)
203194
return classLocation.substring(0, classLocation.indexOf(classFilePath) - 1) + manifestFilePath;
204195
}
205196

206-
private static class GetClassLoaderAction implements PrivilegedAction<ClassLoader>
207-
{
208-
private Object object;
209-
210-
GetClassLoaderAction(Object object)
211-
{
212-
this.object = object;
213-
}
214-
215-
@Override
216-
public ClassLoader run()
217-
{
218-
try
219-
{
220-
return getClassLoaderInternal(object);
221-
}
222-
catch (Exception e)
223-
{
224-
return null;
225-
}
226-
}
227-
}
228197
}

0 commit comments

Comments
 (0)