diff --git a/environments/common/src/main/java/org/jboss/weld/environment/deployment/discovery/ClassPathBeanArchiveScanner.java b/environments/common/src/main/java/org/jboss/weld/environment/deployment/discovery/ClassPathBeanArchiveScanner.java index bfbcdb3762..e524d8ba0c 100644 --- a/environments/common/src/main/java/org/jboss/weld/environment/deployment/discovery/ClassPathBeanArchiveScanner.java +++ b/environments/common/src/main/java/org/jboss/weld/environment/deployment/discovery/ClassPathBeanArchiveScanner.java @@ -25,7 +25,6 @@ import java.io.IOException; import java.net.URI; import java.net.URL; -import java.security.AccessController; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -44,7 +43,6 @@ import org.jboss.weld.config.ConfigurationKey; import org.jboss.weld.environment.deployment.AbstractWeldDeployment; import org.jboss.weld.environment.logging.CommonLogger; -import org.jboss.weld.security.GetSystemPropertyAction; import org.jboss.weld.util.collections.ImmutableList; import org.jboss.weld.util.collections.ImmutableSet; @@ -82,7 +80,7 @@ public ClassPathBeanArchiveScanner(Bootstrap bootstrap, BeanDiscoveryMode emptyB @Override public List scan() { - String javaClassPath = AccessController.doPrivileged(new GetSystemPropertyAction(JAVA_CLASS_PATH_SYSTEM_PROPERTY)); + String javaClassPath = System.getProperty(JAVA_CLASS_PATH_SYSTEM_PROPERTY); if (javaClassPath == null) { throw CommonLogger.LOG.cannotReadJavaClassPathSystemProperty(); } diff --git a/environments/se/core/src/main/java/org/jboss/weld/environment/se/Weld.java b/environments/se/core/src/main/java/org/jboss/weld/environment/se/Weld.java index 042baf8fca..3ab939738a 100644 --- a/environments/se/core/src/main/java/org/jboss/weld/environment/se/Weld.java +++ b/environments/se/core/src/main/java/org/jboss/weld/environment/se/Weld.java @@ -30,7 +30,6 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.security.AccessController; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -95,8 +94,6 @@ import org.jboss.weld.resources.ClassLoaderResourceLoader; import org.jboss.weld.resources.spi.ClassFileServices; import org.jboss.weld.resources.spi.ResourceLoader; -import org.jboss.weld.security.GetClassLoaderAction; -import org.jboss.weld.security.GetSystemPropertyAction; import org.jboss.weld.util.Preconditions; import org.jboss.weld.util.ServiceLoader; import org.jboss.weld.util.Services; @@ -1327,7 +1324,7 @@ protected boolean isEnabled(String key, boolean defaultValue) { if (value != null) { return Boolean.TRUE.equals(value); } - String system = AccessController.doPrivileged(new GetSystemPropertyAction(key)); + String system = System.getProperty(key); if (system != null) { return Boolean.valueOf(system); } @@ -1365,8 +1362,7 @@ private void parseAdditionalBeanDefiningAnnotations() { } // parse from system properties - String stringValue = AccessController - .doPrivileged(new GetSystemPropertyAction(ADDITIONAL_BEAN_DEFINING_ANNOTATIONS_PROPERTY)); + String stringValue = System.getProperty(ADDITIONAL_BEAN_DEFINING_ANNOTATIONS_PROPERTY); if (stringValue != null) { for (String className : stringValue.split(",")) { if (!className.isEmpty()) { @@ -1400,8 +1396,7 @@ private static class PackInfo { this.packName = packClass.getPackage().getName(); this.packClassName = packClass.getName(); this.scanRecursively = recursiveScan; - this.classLoaderRef = new WeakReference( - AccessController.doPrivileged(new GetClassLoaderAction(packClass))); + this.classLoaderRef = new WeakReference(packClass.getClassLoader()); } PackInfo(Package pack, boolean recursiveScan) { diff --git a/environments/servlet/core/src/main/java/org/jboss/weld/environment/tomcat/WeldForwardingInstanceManager.java b/environments/servlet/core/src/main/java/org/jboss/weld/environment/tomcat/WeldForwardingInstanceManager.java index ab9f3f217b..2084987886 100644 --- a/environments/servlet/core/src/main/java/org/jboss/weld/environment/tomcat/WeldForwardingInstanceManager.java +++ b/environments/servlet/core/src/main/java/org/jboss/weld/environment/tomcat/WeldForwardingInstanceManager.java @@ -15,8 +15,6 @@ import org.jboss.weld.environment.servlet.logging.TomcatLogger; import org.jboss.weld.environment.util.Reflections; import org.jboss.weld.manager.api.WeldManager; -import org.jboss.weld.security.FieldLookupAction; -import org.jboss.weld.security.MethodLookupAction; import org.jboss.weld.util.collections.Arrays2; /** @@ -113,15 +111,15 @@ private static StandardContext getStandardContext(ServletContext context) { } private static Object getContextFieldValue(E obj, Class clazz) throws NoSuchFieldException, IllegalAccessException { - Field field = FieldLookupAction.lookupField(clazz, CONTEXT_FIELD_NAME); + Field field = org.jboss.weld.util.reflection.Reflections.lookupField(clazz, CONTEXT_FIELD_NAME); org.jboss.weld.util.reflection.Reflections.ensureAccessible(field, obj); return field.get(obj); } private static InstanceManager getInstanceManager(StandardContext stdContext) { try { - Method method = MethodLookupAction.lookupMethod(stdContext.getClass(), INSTANCE_MANAGER_GETTER_NAME, - Arrays2.EMPTY_CLASS_ARRAY); + Method method = org.jboss.weld.util.reflection.Reflections.lookupMethod(stdContext.getClass(), + INSTANCE_MANAGER_GETTER_NAME, Arrays2.EMPTY_CLASS_ARRAY); org.jboss.weld.util.reflection.Reflections.ensureAccessible(method, stdContext); try { return Reflections.cast(method.invoke(stdContext)); @@ -132,7 +130,8 @@ private static InstanceManager getInstanceManager(StandardContext stdContext) { // Getter/setter not found } try { - Field field = FieldLookupAction.lookupField(stdContext.getClass(), INSTANCE_MANAGER_FIELD_NAME); + Field field = org.jboss.weld.util.reflection.Reflections.lookupField(stdContext.getClass(), + INSTANCE_MANAGER_FIELD_NAME); org.jboss.weld.util.reflection.Reflections.ensureAccessible(field, stdContext); try { return Reflections.cast(field.get(stdContext)); @@ -147,7 +146,8 @@ private static InstanceManager getInstanceManager(StandardContext stdContext) { private static void setInstanceManager(StandardContext stdContext, InstanceManager instanceManager) { try { - Method method = MethodLookupAction.lookupMethod(stdContext.getClass(), INSTANCE_MANAGER_SETTER_NAME, + Method method = org.jboss.weld.util.reflection.Reflections.lookupMethod(stdContext.getClass(), + INSTANCE_MANAGER_SETTER_NAME, new Class[] { InstanceManager.class }); org.jboss.weld.util.reflection.Reflections.ensureAccessible(method, stdContext); try { @@ -160,7 +160,8 @@ private static void setInstanceManager(StandardContext stdContext, InstanceManag // Getter/setter not found } try { - Field field = FieldLookupAction.lookupField(stdContext.getClass(), INSTANCE_MANAGER_FIELD_NAME); + Field field = org.jboss.weld.util.reflection.Reflections.lookupField(stdContext.getClass(), + INSTANCE_MANAGER_FIELD_NAME); org.jboss.weld.util.reflection.Reflections.ensureAccessible(field, stdContext); try { field.set(stdContext, instanceManager); diff --git a/impl/src/main/java/org/jboss/weld/annotated/runtime/InvokableAnnotatedMethod.java b/impl/src/main/java/org/jboss/weld/annotated/runtime/InvokableAnnotatedMethod.java index b11eca15bb..c913220226 100644 --- a/impl/src/main/java/org/jboss/weld/annotated/runtime/InvokableAnnotatedMethod.java +++ b/impl/src/main/java/org/jboss/weld/annotated/runtime/InvokableAnnotatedMethod.java @@ -26,9 +26,9 @@ import jakarta.enterprise.inject.spi.AnnotatedMethod; -import org.jboss.weld.security.MethodLookupAction; import org.jboss.weld.util.annotated.ForwardingAnnotatedMethod; import org.jboss.weld.util.collections.WeldCollections; +import org.jboss.weld.util.reflection.Reflections; /** * An implementation of {@link AnnotatedMethod} used at runtime for invoking Java methods. @@ -81,7 +81,7 @@ public X invokeOnInstance(Object instance, Object... parameters) throws Ille // the same method may be written to the map twice, but that is ok // lookupMethod is very slow Method delegate = annotatedMethod.getJavaMember(); - method = MethodLookupAction.lookupMethod(instance.getClass(), delegate.getName(), delegate.getParameterTypes()); + method = Reflections.lookupMethod(instance.getClass(), delegate.getName(), delegate.getParameterTypes()); if (method != null && !method.canAccess(instance)) { method.setAccessible(true); } diff --git a/impl/src/main/java/org/jboss/weld/bean/builtin/ee/StaticEEResourceProducerField.java b/impl/src/main/java/org/jboss/weld/bean/builtin/ee/StaticEEResourceProducerField.java index 82b1b1e886..2b83143625 100644 --- a/impl/src/main/java/org/jboss/weld/bean/builtin/ee/StaticEEResourceProducerField.java +++ b/impl/src/main/java/org/jboss/weld/bean/builtin/ee/StaticEEResourceProducerField.java @@ -19,7 +19,6 @@ import static org.jboss.weld.util.reflection.Reflections.cast; import java.lang.reflect.Field; -import java.security.AccessController; import jakarta.enterprise.context.spi.CreationalContext; import jakarta.enterprise.inject.spi.BeanAttributes; @@ -35,7 +34,6 @@ import org.jboss.weld.injection.ResourceInjection; import org.jboss.weld.injection.ResourceInjectionFactory; import org.jboss.weld.manager.BeanManagerImpl; -import org.jboss.weld.security.GetAccessibleCopyOfMember; import org.jboss.weld.util.reflection.Reflections; /** @@ -63,7 +61,7 @@ protected StaticEEResourceProducerField(BeanAttributes attributes, EnhancedAn ServiceRegistry services) { super(attributes, field, declaringBean, disposalMethod, manager, services); this.resourceInjection = getResourceInjection(field, declaringBean, manager); - this.accessibleField = AccessController.doPrivileged(new GetAccessibleCopyOfMember(field.getJavaMember())); + this.accessibleField = Reflections.getAccessibleCopyOfMember(field.getJavaMember()); this.injectionContext = new InjectionContextImpl(manager, declaringBean.getInjectionTarget(), declaringBean.getAnnotated(), null) { @Override diff --git a/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java b/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java index 346aab7c59..5f9c3392cc 100644 --- a/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java +++ b/impl/src/main/java/org/jboss/weld/bean/proxy/DecoratorProxyFactory.java @@ -21,7 +21,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; -import java.security.AccessController; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashSet; @@ -40,12 +39,11 @@ import org.jboss.weld.injection.attributes.WeldInjectionPointAttributes; import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy; import org.jboss.weld.logging.BeanLogger; -import org.jboss.weld.security.GetDeclaredMethodAction; -import org.jboss.weld.security.GetDeclaredMethodsAction; import org.jboss.weld.util.bytecode.BytecodeUtils; import org.jboss.weld.util.bytecode.MethodInformation; import org.jboss.weld.util.bytecode.RuntimeMethodInformation; import org.jboss.weld.util.bytecode.StaticMethodInformation; +import org.jboss.weld.util.reflection.Reflections; /** * This special proxy factory is mostly used for abstract decorators. When a @@ -141,7 +139,7 @@ private void decoratorMethods(Class cls, Set all) { if (cls == null) { return; } - all.addAll(Arrays.asList(AccessController.doPrivileged(new GetDeclaredMethodsAction(cls)))); + all.addAll(Arrays.asList(cls.getDeclaredMethods())); decoratorMethods(cls.getSuperclass(), all); @@ -292,10 +290,8 @@ public void getDeclaredMethod(ClassMethod classMethod, String declaringClass, St // and store it in the array code.aastore(); } - code.invokestatic(GetDeclaredMethodAction.class.getName(), "wrapException", - "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/security/PrivilegedAction;"); - code.invokestatic(AccessController.class.getName(), "doPrivileged", - "(Ljava/security/PrivilegedAction;)Ljava/lang/Object;"); + code.invokestatic(Reflections.class.getName(), "wrapException", + "(Ljava/lang/Class;Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method;"); code.checkcast(Method.class); } diff --git a/impl/src/main/java/org/jboss/weld/bean/proxy/DefaultBytecodeMethodResolver.java b/impl/src/main/java/org/jboss/weld/bean/proxy/DefaultBytecodeMethodResolver.java index 6a2de5ffa8..453da5583e 100644 --- a/impl/src/main/java/org/jboss/weld/bean/proxy/DefaultBytecodeMethodResolver.java +++ b/impl/src/main/java/org/jboss/weld/bean/proxy/DefaultBytecodeMethodResolver.java @@ -18,14 +18,13 @@ package org.jboss.weld.bean.proxy; import java.lang.reflect.Method; -import java.security.AccessController; import java.util.concurrent.atomic.AtomicLong; import org.jboss.classfilewriter.AccessFlag; import org.jboss.classfilewriter.ClassFile; import org.jboss.classfilewriter.ClassMethod; import org.jboss.classfilewriter.code.CodeAttribute; -import org.jboss.weld.security.GetDeclaredMethodAction; +import org.jboss.weld.logging.ReflectionLogger; import org.jboss.weld.util.bytecode.BytecodeUtils; /** @@ -88,7 +87,11 @@ private void addInitMethod(final String declaringClass, final String methodName, } public static Method getMethod(Class javaClass, String methodName, Class... parameterTypes) { - return AccessController.doPrivileged(GetDeclaredMethodAction.wrapException(javaClass, methodName, parameterTypes)); + try { + return javaClass.getDeclaredMethod(methodName, parameterTypes); + } catch (NoSuchMethodException e) { + throw ReflectionLogger.LOG.noSuchMethodWrapper(e, e.getMessage()); + } } } diff --git a/impl/src/main/java/org/jboss/weld/bean/proxy/InterceptedProxyFactory.java b/impl/src/main/java/org/jboss/weld/bean/proxy/InterceptedProxyFactory.java index 7a5b023775..2f01ed2d9e 100644 --- a/impl/src/main/java/org/jboss/weld/bean/proxy/InterceptedProxyFactory.java +++ b/impl/src/main/java/org/jboss/weld/bean/proxy/InterceptedProxyFactory.java @@ -22,7 +22,6 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Type; -import java.security.AccessController; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; @@ -39,7 +38,6 @@ import org.jboss.weld.exceptions.WeldException; import org.jboss.weld.injection.InterceptionFactoryImpl; import org.jboss.weld.logging.BeanLogger; -import org.jboss.weld.security.GetDeclaredMethodsAction; import org.jboss.weld.util.bytecode.BytecodeUtils; import org.jboss.weld.util.bytecode.MethodInformation; import org.jboss.weld.util.bytecode.RuntimeMethodInformation; @@ -100,7 +98,7 @@ protected void addMethodsFromClass(ClassFile proxyClassType, ClassMethod staticC for (Class cls : classes) { Set declaredBridgeMethods = new HashSet(); - for (Method method : AccessController.doPrivileged(new GetDeclaredMethodsAction(cls))) { + for (Method method : cls.getDeclaredMethods()) { final MethodSignatureImpl methodSignature = new MethodSignatureImpl(method); diff --git a/impl/src/main/java/org/jboss/weld/bean/proxy/InterceptedSubclassFactory.java b/impl/src/main/java/org/jboss/weld/bean/proxy/InterceptedSubclassFactory.java index 68eaf90300..970bbb0634 100644 --- a/impl/src/main/java/org/jboss/weld/bean/proxy/InterceptedSubclassFactory.java +++ b/impl/src/main/java/org/jboss/weld/bean/proxy/InterceptedSubclassFactory.java @@ -26,7 +26,6 @@ import java.lang.reflect.Modifier; import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; -import java.security.AccessController; import java.util.Arrays; import java.util.Collection; import java.util.HashSet; @@ -49,7 +48,6 @@ import org.jboss.weld.interceptor.proxy.LifecycleMixin; import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy; import org.jboss.weld.logging.BeanLogger; -import org.jboss.weld.security.GetDeclaredMethodsAction; import org.jboss.weld.util.bytecode.BytecodeUtils; import org.jboss.weld.util.bytecode.MethodInformation; import org.jboss.weld.util.bytecode.RuntimeMethodInformation; @@ -210,7 +208,7 @@ protected void addMethodsFromClass(ClassFile proxyClassType, ClassMethod staticC while (cls != null) { Set declaredBridgeMethods = new HashSet(); Collection classDeclaredMethods = Arrays - .asList(AccessController.doPrivileged(new GetDeclaredMethodsAction(cls)).clone()); + .asList(cls.getDeclaredMethods().clone()); for (Method method : classDeclaredMethods) { final MethodSignatureImpl methodSignature = new MethodSignatureImpl(method); @@ -732,4 +730,4 @@ public String toString() { } -} \ No newline at end of file +} diff --git a/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java b/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java index 80edd00087..5d430de779 100644 --- a/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java +++ b/impl/src/main/java/org/jboss/weld/bean/proxy/ProxyFactory.java @@ -31,7 +31,6 @@ import java.lang.reflect.Type; import java.nio.file.Files; import java.nio.file.StandardOpenOption; -import java.security.AccessController; import java.security.ProtectionDomain; import java.util.ArrayList; import java.util.Arrays; @@ -63,9 +62,6 @@ import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy; import org.jboss.weld.logging.BeanLogger; import org.jboss.weld.proxy.WeldConstruct; -import org.jboss.weld.security.GetDeclaredConstructorsAction; -import org.jboss.weld.security.GetDeclaredMethodsAction; -import org.jboss.weld.security.GetProtectionDomainAction; import org.jboss.weld.serialization.spi.BeanIdentifier; import org.jboss.weld.serialization.spi.ContextualStore; import org.jboss.weld.serialization.spi.ProxyServices; @@ -504,7 +500,7 @@ private Class createProxyClass(Class originalClass, String proxyClassName) // Dump proxy type bytecode if necessary dumpToFile(proxyClassName, proxyClassType.toBytecode()); - ProtectionDomain domain = AccessController.doPrivileged(new GetProtectionDomainAction(proxiedBeanType)); + ProtectionDomain domain = proxiedBeanType.getProtectionDomain(); if (proxiedBeanType.getPackage() == null || proxiedBeanType.getPackage().getName().isEmpty() || proxiedBeanType.equals(Object.class)) { @@ -553,8 +549,7 @@ protected void addConstructors(ClassFile proxyClassType, List ConstructorUtils.addDefaultConstructor(proxyClassType, initialValueBytecode, !useConstructedFlag()); } else { boolean constructorFound = false; - for (Constructor constructor : AccessController - .doPrivileged(new GetDeclaredConstructorsAction(getBeanType()))) { + for (Constructor constructor : getBeanType().getDeclaredConstructors()) { if ((constructor.getModifiers() & Modifier.PRIVATE) == 0) { constructorFound = true; String[] exceptions = new String[constructor.getExceptionTypes().length]; @@ -663,7 +658,7 @@ protected void addMethodsFromClass(ClassFile proxyClassType, ClassMethod staticC private void addMethods(Class cls, ClassFile proxyClassType, ClassMethod staticConstructor, Set foundFinalmethods) { - for (Method method : AccessController.doPrivileged(new GetDeclaredMethodsAction(cls))) { + for (Method method : cls.getDeclaredMethods()) { MethodSignature methodSignature = new MethodSignatureImpl(method); if (Modifier.isFinal(method.getModifiers())) { foundFinalmethods.add(methodSignature); diff --git a/impl/src/main/java/org/jboss/weld/bootstrap/FastAnnotatedTypeLoader.java b/impl/src/main/java/org/jboss/weld/bootstrap/FastAnnotatedTypeLoader.java index add4b4284b..dcff7dc212 100644 --- a/impl/src/main/java/org/jboss/weld/bootstrap/FastAnnotatedTypeLoader.java +++ b/impl/src/main/java/org/jboss/weld/bootstrap/FastAnnotatedTypeLoader.java @@ -17,7 +17,6 @@ package org.jboss.weld.bootstrap; import java.lang.reflect.Method; -import java.security.AccessController; import java.util.Collections; import java.util.Set; @@ -36,7 +35,6 @@ import org.jboss.weld.resources.spi.ClassFileInfoException; import org.jboss.weld.resources.spi.ClassFileServices; import org.jboss.weld.resources.spi.ResourceLoadingException; -import org.jboss.weld.security.GetDeclaredMethodAction; import org.jboss.weld.util.Beans; import org.jboss.weld.util.bytecode.BytecodeUtils; import org.jboss.weld.util.reflection.Reflections; @@ -140,8 +138,7 @@ private boolean initCheckTypeModifiers() { new ClassLoaderResourceLoader(classFileServices.getClass().getClassLoader())); if (classInfoclass != null) { try { - Method setFlags = AccessController - .doPrivileged(GetDeclaredMethodAction.of(classInfoclass, "setFlags", short.class)); + Method setFlags = classInfoclass.getDeclaredMethod("setFlags", short.class); return setFlags != null; } catch (Exception exceptionIgnored) { BootstrapLogger.LOG.usingOldJandexVersion(); diff --git a/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java b/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java index 073b09b3a7..1593878018 100644 --- a/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java +++ b/impl/src/main/java/org/jboss/weld/bootstrap/Validator.java @@ -27,7 +27,6 @@ import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.lang.reflect.WildcardType; -import java.security.AccessController; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; @@ -105,8 +104,6 @@ import org.jboss.weld.metadata.cache.MetaAnnotationStore; import org.jboss.weld.metadata.cache.StereotypeModel; import org.jboss.weld.module.PlugableValidator; -import org.jboss.weld.security.GetDeclaredFieldsAction; -import org.jboss.weld.security.GetDeclaredMethodsAction; import org.jboss.weld.util.AnnotatedTypes; import org.jboss.weld.util.BeanMethods; import org.jboss.weld.util.Beans; @@ -760,13 +757,13 @@ private boolean isAlternativeCandidate(Class enabledClass, BeanManagerImpl be } // declares producer with alternative // Intentionally do not process the class hierarchy - - for (Method declaredMethod : AccessController.doPrivileged(new GetDeclaredMethodsAction(enabledClass))) { + for (Method declaredMethod : enabledClass.getDeclaredMethods()) { if (declaredMethod.isAnnotationPresent(Produces.class) && isAlternativeOrHasAlternativeStereotype(declaredMethod, beanManager)) { return true; } } - for (Field declaredField : AccessController.doPrivileged(new GetDeclaredFieldsAction(enabledClass))) { + for (Field declaredField : enabledClass.getDeclaredFields()) { if (declaredField.isAnnotationPresent(Produces.class) && isAlternativeOrHasAlternativeStereotype(declaredField, beanManager)) { return true; diff --git a/impl/src/main/java/org/jboss/weld/config/WeldConfiguration.java b/impl/src/main/java/org/jboss/weld/config/WeldConfiguration.java index 7b10c18f60..59d30a5e40 100644 --- a/impl/src/main/java/org/jboss/weld/config/WeldConfiguration.java +++ b/impl/src/main/java/org/jboss/weld/config/WeldConfiguration.java @@ -20,7 +20,6 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.security.AccessController; import java.util.Collections; import java.util.EnumMap; import java.util.HashSet; @@ -42,7 +41,6 @@ import org.jboss.weld.resources.WeldClassLoaderResourceLoader; import org.jboss.weld.resources.spi.ResourceLoader; import org.jboss.weld.resources.spi.ResourceLoadingException; -import org.jboss.weld.security.GetSystemPropertyAction; import org.jboss.weld.util.Preconditions; import org.jboss.weld.util.collections.ImmutableMap; import org.jboss.weld.util.reflection.Reflections; @@ -239,7 +237,7 @@ static void checkRequiredType(ConfigurationKey key, Class requiredType) { */ static String getSystemProperty(String key) { try { - return AccessController.doPrivileged(new GetSystemPropertyAction(key)); + return System.getProperty(key); } catch (Throwable ignore) { return null; } diff --git a/impl/src/main/java/org/jboss/weld/injection/ConstructorInjectionPoint.java b/impl/src/main/java/org/jboss/weld/injection/ConstructorInjectionPoint.java index 6833a01718..f09f49399b 100644 --- a/impl/src/main/java/org/jboss/weld/injection/ConstructorInjectionPoint.java +++ b/impl/src/main/java/org/jboss/weld/injection/ConstructorInjectionPoint.java @@ -20,7 +20,6 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -38,7 +37,6 @@ import org.jboss.weld.contexts.CreationalContextImpl; import org.jboss.weld.exceptions.WeldException; import org.jboss.weld.manager.BeanManagerImpl; -import org.jboss.weld.security.GetAccessibleCopyOfMember; import org.jboss.weld.util.collections.Arrays2; import org.jboss.weld.util.reflection.Reflections; @@ -65,8 +63,7 @@ protected ConstructorInjectionPoint(EnhancedAnnotatedConstructor constructor, super(constructor, declaringBean, declaringComponentClass, false, factory, manager); this.constructor = constructor.slim(); this.signature = constructor.getSignature(); - this.accessibleConstructor = AccessController - .doPrivileged(new GetAccessibleCopyOfMember>(constructor.getJavaMember())); + this.accessibleConstructor = Reflections.getAccessibleCopyOfMember(constructor.getJavaMember()); } public T newInstance(BeanManagerImpl manager, CreationalContext ctx) { diff --git a/impl/src/main/java/org/jboss/weld/injection/Exceptions.java b/impl/src/main/java/org/jboss/weld/injection/Exceptions.java index d28c9d6cc4..b22450b088 100644 --- a/impl/src/main/java/org/jboss/weld/injection/Exceptions.java +++ b/impl/src/main/java/org/jboss/weld/injection/Exceptions.java @@ -17,14 +17,10 @@ package org.jboss.weld.injection; import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; -import java.security.PrivilegedActionException; import jakarta.enterprise.inject.CreationException; import org.jboss.weld.exceptions.WeldException; -import org.jboss.weld.security.GetDeclaredConstructorAction; -import org.jboss.weld.security.NewInstanceAction; class Exceptions { @@ -37,9 +33,8 @@ private static void rethrowException(Throwable t, Class FieldInjectionPoint silent(FieldInjectionPointAttribu protected FieldInjectionPoint(FieldInjectionPointAttributes attributes) { this.attributes = attributes; this.cacheable = isCacheableInjectionPoint(attributes); - this.accessibleField = AccessController.doPrivileged(new GetAccessibleCopyOfMember(attributes.getMember())); + this.accessibleField = Reflections.getAccessibleCopyOfMember(attributes.getMember()); } protected static boolean isCacheableInjectionPoint(WeldInjectionPointAttributes attributes) { diff --git a/impl/src/main/java/org/jboss/weld/injection/FieldResourceInjection.java b/impl/src/main/java/org/jboss/weld/injection/FieldResourceInjection.java index 16d5bc4f2f..37f11a9130 100644 --- a/impl/src/main/java/org/jboss/weld/injection/FieldResourceInjection.java +++ b/impl/src/main/java/org/jboss/weld/injection/FieldResourceInjection.java @@ -19,12 +19,10 @@ import static org.jboss.weld.injection.Exceptions.rethrowException; import java.lang.reflect.Field; -import java.security.AccessController; import org.jboss.weld.bean.proxy.DecoratorProxy; import org.jboss.weld.injection.spi.ResourceReferenceFactory; import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy; -import org.jboss.weld.security.GetAccessibleCopyOfMember; import org.jboss.weld.util.reflection.Reflections; /** @@ -46,8 +44,7 @@ class FieldResourceInjection extends AbstractResourceInjection { */ FieldResourceInjection(FieldInjectionPoint fieldInjectionPoint, ResourceReferenceFactory factory) { super(factory); - this.accessibleField = AccessController - .doPrivileged(new GetAccessibleCopyOfMember(fieldInjectionPoint.getAnnotated().getJavaMember())); + this.accessibleField = Reflections.getAccessibleCopyOfMember(fieldInjectionPoint.getAnnotated().getJavaMember()); } @Override diff --git a/impl/src/main/java/org/jboss/weld/injection/SetterResourceInjection.java b/impl/src/main/java/org/jboss/weld/injection/SetterResourceInjection.java index cc1427af63..c77ea7386c 100644 --- a/impl/src/main/java/org/jboss/weld/injection/SetterResourceInjection.java +++ b/impl/src/main/java/org/jboss/weld/injection/SetterResourceInjection.java @@ -20,14 +20,12 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -import java.security.AccessController; import jakarta.enterprise.inject.spi.AnnotatedMethod; import org.jboss.weld.bean.proxy.DecoratorProxy; import org.jboss.weld.injection.spi.ResourceReferenceFactory; import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy; -import org.jboss.weld.security.GetAccessibleCopyOfMember; import org.jboss.weld.util.reflection.Reflections; /** @@ -50,8 +48,7 @@ class SetterResourceInjection extends AbstractResourceInjection { SetterResourceInjection(ParameterInjectionPoint injectionPoint, ResourceReferenceFactory factory) { super(factory); AnnotatedMethod annotatedMethod = (AnnotatedMethod) injectionPoint.getAnnotated().getDeclaringCallable(); - accessibleMethod = AccessController - .doPrivileged(new GetAccessibleCopyOfMember(annotatedMethod.getJavaMember())); + accessibleMethod = Reflections.getAccessibleCopyOfMember(annotatedMethod.getJavaMember()); } @Override @@ -79,4 +76,4 @@ Method getMember() { return accessibleMethod; } -} \ No newline at end of file +} diff --git a/impl/src/main/java/org/jboss/weld/injection/StaticMethodInjectionPoint.java b/impl/src/main/java/org/jboss/weld/injection/StaticMethodInjectionPoint.java index f260fdf1c5..bb0f229d7d 100644 --- a/impl/src/main/java/org/jboss/weld/injection/StaticMethodInjectionPoint.java +++ b/impl/src/main/java/org/jboss/weld/injection/StaticMethodInjectionPoint.java @@ -34,8 +34,8 @@ import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedMethod; import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedParameter; import org.jboss.weld.manager.BeanManagerImpl; -import org.jboss.weld.security.GetAccessibleCopyOfMember; import org.jboss.weld.util.collections.Arrays2; +import org.jboss.weld.util.reflection.Reflections; /** * {@link MethodInjectionPoint} that delegates to a static method. @@ -55,7 +55,7 @@ class StaticMethodInjectionPoint extends MethodInjectionPoint { Bean declaringBean, Class declaringComponentClass, Set> specialParameterMarkers, InjectionPointFactory factory, BeanManagerImpl manager) { super(methodInjectionPointType, enhancedMethod, declaringBean, declaringComponentClass, factory, manager); - this.accessibleMethod = GetAccessibleCopyOfMember.of(enhancedMethod.getJavaMember()); + this.accessibleMethod = Reflections.getAccessibleCopyOfMember(enhancedMethod.getJavaMember()); this.annotatedMethod = enhancedMethod.slim(); this.specialInjectionPointIndex = initSpecialInjectionPointIndex(enhancedMethod, specialParameterMarkers); } diff --git a/impl/src/main/java/org/jboss/weld/injection/VirtualMethodInjectionPoint.java b/impl/src/main/java/org/jboss/weld/injection/VirtualMethodInjectionPoint.java index 5537f75f5f..6aead398fa 100644 --- a/impl/src/main/java/org/jboss/weld/injection/VirtualMethodInjectionPoint.java +++ b/impl/src/main/java/org/jboss/weld/injection/VirtualMethodInjectionPoint.java @@ -32,7 +32,6 @@ import org.jboss.weld.bean.AbstractClassBean; import org.jboss.weld.bean.AbstractProducerBean; import org.jboss.weld.manager.BeanManagerImpl; -import org.jboss.weld.security.MethodLookupAction; import org.jboss.weld.util.collections.ImmutableMap; import org.jboss.weld.util.reflection.Reflections; @@ -73,7 +72,7 @@ protected Method getMethod(Object receiver) throws NoSuchMethodException { // Initializer methods and decorated beans - overriding does not apply to private methods and package-private methods where the subclass is in a different package method = accessibleMethod; } else { - method = MethodLookupAction.lookupMethod(receiver.getClass(), delegate.getName(), delegate.getParameterTypes()); + method = Reflections.lookupMethod(receiver.getClass(), delegate.getName(), delegate.getParameterTypes()); Reflections.ensureAccessible(method, receiver); } final Map, Method> newMethods = ImmutableMap., Method> builder().putAll(methods) diff --git a/impl/src/main/java/org/jboss/weld/injection/producer/DecoratorInjectionTarget.java b/impl/src/main/java/org/jboss/weld/injection/producer/DecoratorInjectionTarget.java index 9e96c8ba06..991b13bb5d 100644 --- a/impl/src/main/java/org/jboss/weld/injection/producer/DecoratorInjectionTarget.java +++ b/impl/src/main/java/org/jboss/weld/injection/producer/DecoratorInjectionTarget.java @@ -18,7 +18,6 @@ import java.lang.reflect.Field; import java.lang.reflect.Type; -import java.security.AccessController; import java.util.Set; import jakarta.enterprise.context.spi.CreationalContext; @@ -39,8 +38,8 @@ import org.jboss.weld.injection.attributes.WeldInjectionPointAttributes; import org.jboss.weld.logging.UtilLogger; import org.jboss.weld.manager.BeanManagerImpl; -import org.jboss.weld.security.GetAccessibleCopyOfMember; import org.jboss.weld.util.Decorators; +import org.jboss.weld.util.reflection.Reflections; /** * {@link InjectionTarget} implementation used for decorators. @@ -59,8 +58,7 @@ public DecoratorInjectionTarget(EnhancedAnnotatedType type, Bean bean, Bea this.delegateInjectionPoint = Decorators.findDelegateInjectionPoint(type, getInjectionPoints()); if (delegateInjectionPoint instanceof FieldInjectionPoint) { FieldInjectionPoint fip = (FieldInjectionPoint) delegateInjectionPoint; - this.accessibleField = AccessController - .doPrivileged(new GetAccessibleCopyOfMember(fip.getAnnotated().getJavaMember())); + this.accessibleField = Reflections.getAccessibleCopyOfMember(fip.getAnnotated().getJavaMember()); } else { this.accessibleField = null; } diff --git a/impl/src/main/java/org/jboss/weld/injection/producer/DefaultLifecycleCallbackInvoker.java b/impl/src/main/java/org/jboss/weld/injection/producer/DefaultLifecycleCallbackInvoker.java index 985f396f3e..cde7f07733 100644 --- a/impl/src/main/java/org/jboss/weld/injection/producer/DefaultLifecycleCallbackInvoker.java +++ b/impl/src/main/java/org/jboss/weld/injection/producer/DefaultLifecycleCallbackInvoker.java @@ -17,7 +17,6 @@ package org.jboss.weld.injection.producer; import java.lang.reflect.Method; -import java.security.AccessController; import java.util.List; import jakarta.annotation.PostConstruct; @@ -27,9 +26,9 @@ import org.jboss.weld.annotated.enhanced.EnhancedAnnotatedType; import org.jboss.weld.interceptor.util.InterceptionUtils; import org.jboss.weld.logging.BeanLogger; -import org.jboss.weld.security.GetAccessibleCopyOfMember; import org.jboss.weld.util.BeanMethods; import org.jboss.weld.util.collections.ImmutableList; +import org.jboss.weld.util.reflection.Reflections; /** * If the component is not intercepted this implementation takes care of invoking its lifecycle callback methods. If the @@ -55,7 +54,7 @@ public DefaultLifecycleCallbackInvoker(EnhancedAnnotatedType type) { private List initMethodList(List> methods) { return methods.stream() - .map((method) -> AccessController.doPrivileged(new GetAccessibleCopyOfMember(method.getJavaMember()))) + .map((method) -> Reflections.getAccessibleCopyOfMember(method.getJavaMember())) .collect(ImmutableList.collector()); } @@ -98,4 +97,4 @@ public boolean hasPreDestroyMethods() { public boolean hasPostConstructMethods() { return !accessiblePostConstructMethods.isEmpty(); } -} \ No newline at end of file +} diff --git a/impl/src/main/java/org/jboss/weld/injection/producer/ProducerFieldProducer.java b/impl/src/main/java/org/jboss/weld/injection/producer/ProducerFieldProducer.java index 175e9ed76b..a16e86fcf2 100644 --- a/impl/src/main/java/org/jboss/weld/injection/producer/ProducerFieldProducer.java +++ b/impl/src/main/java/org/jboss/weld/injection/producer/ProducerFieldProducer.java @@ -19,7 +19,6 @@ import static org.jboss.weld.util.reflection.Reflections.cast; import java.lang.reflect.Field; -import java.security.AccessController; import java.util.Collections; import java.util.Set; @@ -37,7 +36,6 @@ import org.jboss.weld.interceptor.util.proxy.TargetInstanceProxy; import org.jboss.weld.logging.BeanLogger; import org.jboss.weld.logging.UtilLogger; -import org.jboss.weld.security.GetAccessibleCopyOfMember; import org.jboss.weld.util.reflection.Formats; import org.jboss.weld.util.reflection.Reflections; @@ -53,8 +51,7 @@ public abstract class ProducerFieldProducer extends AbstractMemberProducer public ProducerFieldProducer(EnhancedAnnotatedField enhancedField, DisposalMethod disposalMethod) { super(enhancedField, disposalMethod); - this.accessibleField = AccessController - .doPrivileged(new GetAccessibleCopyOfMember(enhancedField.getJavaMember())); + this.accessibleField = Reflections.getAccessibleCopyOfMember(enhancedField.getJavaMember()); checkProducerField(enhancedField); } diff --git a/impl/src/main/java/org/jboss/weld/injection/producer/ProducerMethodProducer.java b/impl/src/main/java/org/jboss/weld/injection/producer/ProducerMethodProducer.java index 45d6c4b1c4..0719c29c1c 100644 --- a/impl/src/main/java/org/jboss/weld/injection/producer/ProducerMethodProducer.java +++ b/impl/src/main/java/org/jboss/weld/injection/producer/ProducerMethodProducer.java @@ -18,8 +18,6 @@ import java.lang.reflect.Modifier; import java.lang.reflect.Type; -import java.security.AccessController; -import java.security.PrivilegedActionException; import java.util.Set; import jakarta.enterprise.context.spi.CreationalContext; @@ -39,7 +37,6 @@ import org.jboss.weld.injection.MethodInjectionPoint; import org.jboss.weld.injection.MethodInjectionPoint.MethodInjectionPointType; import org.jboss.weld.logging.BeanLogger; -import org.jboss.weld.security.GetMethodAction; import org.jboss.weld.util.reflection.Formats; import org.jboss.weld.util.reflection.Reflections; @@ -85,11 +82,10 @@ protected void checkProducerMethod(EnhancedAnnotatedMethod method) for (Type type : getDeclaringBean().getTypes()) { Class clazz = Reflections.getRawType(type); try { - AccessController - .doPrivileged(new GetMethodAction(clazz, method.getName(), method.getParameterTypesAsArray())); + clazz.getMethod(method.getName(), method.getParameterTypesAsArray()); methodDeclaredOnTypes = true; break; - } catch (PrivilegedActionException ignored) { + } catch (NoSuchMethodException ignored) { } } if (!methodDeclaredOnTypes) { diff --git a/impl/src/main/java/org/jboss/weld/metadata/FilterPredicate.java b/impl/src/main/java/org/jboss/weld/metadata/FilterPredicate.java index 95f9c62c20..b469fd7422 100644 --- a/impl/src/main/java/org/jboss/weld/metadata/FilterPredicate.java +++ b/impl/src/main/java/org/jboss/weld/metadata/FilterPredicate.java @@ -1,6 +1,5 @@ package org.jboss.weld.metadata; -import java.security.AccessController; import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -12,7 +11,6 @@ import org.jboss.weld.bootstrap.spi.WeldFilter; import org.jboss.weld.resources.spi.ResourceLoader; import org.jboss.weld.resources.spi.ResourceLoadingException; -import org.jboss.weld.security.GetSystemPropertyAction; /** * A predicate which selects classes to process based on a filter. @@ -70,7 +68,7 @@ public FilterPredicate(Metadata filter, ResourceLoader resourceLoader) { propertyName = removeInversion(propertyName); } - String actualPropertyValue = AccessController.doPrivileged(new GetSystemPropertyAction(propertyName)); + String actualPropertyValue = System.getProperty(propertyName); if (requiredPropertyValue == null) { active = active && isNotNull(actualPropertyValue, propertyNameInverted); } else { diff --git a/impl/src/main/java/org/jboss/weld/metadata/cache/InterceptorBindingModel.java b/impl/src/main/java/org/jboss/weld/metadata/cache/InterceptorBindingModel.java index 89aea812ba..08450cee11 100644 --- a/impl/src/main/java/org/jboss/weld/metadata/cache/InterceptorBindingModel.java +++ b/impl/src/main/java/org/jboss/weld/metadata/cache/InterceptorBindingModel.java @@ -21,7 +21,6 @@ import java.lang.annotation.ElementType; import java.lang.annotation.Target; import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; import java.util.Arrays; import java.util.Collections; import java.util.Set; @@ -34,7 +33,6 @@ import org.jboss.weld.exceptions.WeldException; import org.jboss.weld.logging.MetadataLogger; import org.jboss.weld.logging.ReflectionLogger; -import org.jboss.weld.security.SetAccessibleAction; import org.jboss.weld.util.collections.Arrays2; import org.jboss.weld.util.reflection.Reflections; @@ -144,7 +142,7 @@ public boolean isEqual(Annotation instance, Annotation other, boolean includeNon for (AnnotatedMethod annotatedMethod : getAnnotatedAnnotation().getMethods()) { if (includeNonBindingTypes || !getNonBindingMembers().contains(annotatedMethod)) { try { - AccessController.doPrivileged(SetAccessibleAction.of(annotatedMethod.getJavaMember())); + annotatedMethod.getJavaMember().setAccessible(true); Object thisValue = annotatedMethod.getJavaMember().invoke(instance); Object thatValue = annotatedMethod.getJavaMember().invoke(other); if (!thisValue.equals(thatValue)) { diff --git a/impl/src/main/java/org/jboss/weld/metadata/cache/QualifierModel.java b/impl/src/main/java/org/jboss/weld/metadata/cache/QualifierModel.java index 489869d661..7677166668 100644 --- a/impl/src/main/java/org/jboss/weld/metadata/cache/QualifierModel.java +++ b/impl/src/main/java/org/jboss/weld/metadata/cache/QualifierModel.java @@ -24,7 +24,6 @@ import java.lang.annotation.Annotation; import java.lang.annotation.Target; import java.lang.reflect.InvocationTargetException; -import java.security.AccessController; import java.util.Collections; import java.util.Set; @@ -36,7 +35,6 @@ import org.jboss.weld.exceptions.WeldException; import org.jboss.weld.logging.MetadataLogger; import org.jboss.weld.logging.ReflectionLogger; -import org.jboss.weld.security.SetAccessibleAction; import org.jboss.weld.util.collections.Arrays2; import org.jboss.weld.util.reflection.Reflections; @@ -123,7 +121,7 @@ public boolean isEqual(Annotation instance, Annotation other) { for (AnnotatedMethod annotatedMethod : getAnnotatedAnnotation().getMethods()) { if (!getNonBindingMembers().contains(annotatedMethod)) { try { - AccessController.doPrivileged(SetAccessibleAction.of(annotatedMethod.getJavaMember())); + annotatedMethod.getJavaMember().setAccessible(true); Object thisValue = annotatedMethod.getJavaMember().invoke(instance); Object thatValue = annotatedMethod.getJavaMember().invoke(other); if (!thisValue.equals(thatValue)) { diff --git a/impl/src/main/java/org/jboss/weld/security/AbstractGenericReflectionAction.java b/impl/src/main/java/org/jboss/weld/security/AbstractGenericReflectionAction.java deleted file mode 100644 index 7cc3527d6b..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/AbstractGenericReflectionAction.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -public abstract class AbstractGenericReflectionAction { - - protected final Class javaClass; - - public AbstractGenericReflectionAction(Class javaClass) { - this.javaClass = javaClass; - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/AbstractReflectionAction.java b/impl/src/main/java/org/jboss/weld/security/AbstractReflectionAction.java deleted file mode 100644 index 10138596c7..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/AbstractReflectionAction.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -public abstract class AbstractReflectionAction { - - protected final Class javaClass; - - public AbstractReflectionAction(Class javaClass) { - this.javaClass = javaClass; - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/ConstructorNewInstanceAction.java b/impl/src/main/java/org/jboss/weld/security/ConstructorNewInstanceAction.java deleted file mode 100644 index 486fcf4718..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/ConstructorNewInstanceAction.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2015, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.InvocationTargetException; -import java.security.PrivilegedExceptionAction; - -public class ConstructorNewInstanceAction extends AbstractGenericReflectionAction - implements PrivilegedExceptionAction { - - private final Class[] constructorParamTypes; - private final Object[] constructorParamInstances; - - public static ConstructorNewInstanceAction of(Class javaClass, Class[] constructorParamTypes, - Object... constructorParamInstances) { - return new ConstructorNewInstanceAction(javaClass, constructorParamTypes, constructorParamInstances); - } - - public ConstructorNewInstanceAction(Class javaClass, Class[] constructorParamTypes, - Object... constructorParamInstances) { - super(javaClass); - this.constructorParamTypes = constructorParamTypes.clone(); - this.constructorParamInstances = constructorParamInstances; - } - - @Override - public T run() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException { - return javaClass.getConstructor(constructorParamTypes).newInstance(constructorParamInstances); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/FieldLookupAction.java b/impl/src/main/java/org/jboss/weld/security/FieldLookupAction.java deleted file mode 100644 index 4b2072bcb9..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/FieldLookupAction.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Field; -import java.security.PrivilegedExceptionAction; - -/** - * Returns a field from the class or any class/interface in the inheritance hierarchy - * - * @author Jozef Hartinger - * @author Martin Kouba - */ -public class FieldLookupAction extends GetDeclaredFieldAction implements PrivilegedExceptionAction { - - public FieldLookupAction(Class javaClass, String fieldName) { - super(javaClass, fieldName); - } - - @Override - public Field run() throws NoSuchFieldException { - return lookupField(javaClass, fieldName); - } - - public static Field lookupField(Class javaClass, String fieldName) throws NoSuchFieldException { - for (Class inspectedClass = javaClass; inspectedClass != null; inspectedClass = inspectedClass.getSuperclass()) { - for (Class inspectedInterface : inspectedClass.getInterfaces()) { - try { - return lookupField(inspectedInterface, fieldName); - } catch (NoSuchFieldException e) { - // Expected, nothing to see here. - } - } - try { - return inspectedClass.getDeclaredField(fieldName); - } catch (NoSuchFieldException nsme) { - // Expected, nothing to see here. - } - } - throw new NoSuchFieldException(); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetAccessibleCopyOfMember.java b/impl/src/main/java/org/jboss/weld/security/GetAccessibleCopyOfMember.java deleted file mode 100644 index bccbcba05b..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetAccessibleCopyOfMember.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.lang.reflect.Member; -import java.lang.reflect.Method; -import java.security.PrivilegedAction; - -public class GetAccessibleCopyOfMember implements PrivilegedAction { - - private static final String UNABLE_TO_OBTAIN_AN_ACCESSIBLE_COPY_OF = "Unable to obtain an accessible copy of "; - - private final T originalMember; - - public GetAccessibleCopyOfMember(T originalMember) { - this.originalMember = originalMember; - } - - public static T of(T member) { - T copy = copyMember(member); - copy.setAccessible(true); - return copy; - } - - @Override - public T run() { - return of(originalMember); - } - - @SuppressWarnings("unchecked") - private static T copyMember(T originalMember) { - Class declaringClass = originalMember.getDeclaringClass(); - try { - if (originalMember instanceof Field) { - return (T) copyField((Field) originalMember, declaringClass); - } - if (originalMember instanceof Constructor) { - return (T) copyConstructor((Constructor) originalMember, declaringClass); - } - if (originalMember instanceof Method) { - return (T) copyMethod((Method) originalMember, declaringClass); - } - } catch (Exception e) { - throw new IllegalArgumentException(UNABLE_TO_OBTAIN_AN_ACCESSIBLE_COPY_OF + originalMember, e); - } - throw new IllegalArgumentException(UNABLE_TO_OBTAIN_AN_ACCESSIBLE_COPY_OF + originalMember); - } - - private static Field copyField(Field field, Class declaringClass) throws NoSuchFieldException { - return declaringClass.getDeclaredField(field.getName()); - } - - private static Method copyMethod(Method method, Class declaringClass) throws NoSuchMethodException { - return declaringClass.getDeclaredMethod(method.getName(), method.getParameterTypes()); - } - - private static Constructor copyConstructor(Constructor constructor, Class declaringClass) - throws NoSuchMethodException { - return declaringClass.getDeclaredConstructor(constructor.getParameterTypes()); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetClassLoaderAction.java b/impl/src/main/java/org/jboss/weld/security/GetClassLoaderAction.java deleted file mode 100644 index 50917e1f53..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetClassLoaderAction.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2014, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.security.PrivilegedAction; - -/** - * Privileged action that obtains the CL. - * - * @author Martin Kouba - * - */ -public class GetClassLoaderAction extends AbstractReflectionAction implements PrivilegedAction { - - public GetClassLoaderAction(Class javaClass) { - super(javaClass); - } - - @Override - public ClassLoader run() { - return javaClass.getClassLoader(); - } - -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetConstructorAction.java b/impl/src/main/java/org/jboss/weld/security/GetConstructorAction.java deleted file mode 100644 index 95a7135134..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetConstructorAction.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Constructor; -import java.security.PrivilegedExceptionAction; - -public class GetConstructorAction extends AbstractGenericReflectionAction - implements PrivilegedExceptionAction> { - - public static GetConstructorAction of(Class javaClass, Class... parameterTypes) { - return new GetConstructorAction(javaClass, parameterTypes); - } - - private final Class[] parameterTypes; - - private GetConstructorAction(Class javaClass, Class... parameterTypes) { - super(javaClass); - this.parameterTypes = parameterTypes; - } - - @Override - public Constructor run() throws NoSuchMethodException { - return javaClass.getConstructor(parameterTypes); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetConstructorsAction.java b/impl/src/main/java/org/jboss/weld/security/GetConstructorsAction.java deleted file mode 100644 index 4ca2b1d439..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetConstructorsAction.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Constructor; -import java.security.PrivilegedAction; - -public class GetConstructorsAction extends AbstractReflectionAction implements PrivilegedAction[]> { - - public GetConstructorsAction(Class javaClass) { - super(javaClass); - } - - @Override - public Constructor[] run() { - return javaClass.getConstructors(); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetContextClassLoaderAction.java b/impl/src/main/java/org/jboss/weld/security/GetContextClassLoaderAction.java deleted file mode 100644 index cab638561a..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetContextClassLoaderAction.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2014, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.security.PrivilegedAction; - -/** - * Privileged action that obtains the TCCL. - * - * @author Jozef Hartinger - * - */ -public class GetContextClassLoaderAction implements PrivilegedAction { - - public static final GetContextClassLoaderAction INSTANCE = new GetContextClassLoaderAction(); - - private GetContextClassLoaderAction() { - } - - @Override - public ClassLoader run() { - return Thread.currentThread().getContextClassLoader(); - } - -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetDeclaredConstructorAction.java b/impl/src/main/java/org/jboss/weld/security/GetDeclaredConstructorAction.java deleted file mode 100644 index 3b83872a35..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetDeclaredConstructorAction.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Constructor; -import java.security.PrivilegedExceptionAction; - -public class GetDeclaredConstructorAction extends AbstractGenericReflectionAction - implements PrivilegedExceptionAction> { - - public static GetDeclaredConstructorAction of(Class javaClass, Class... parameterTypes) { - return new GetDeclaredConstructorAction(javaClass, parameterTypes); - } - - private final Class[] parameterTypes; - - private GetDeclaredConstructorAction(Class javaClass, Class... parameterTypes) { - super(javaClass); - this.parameterTypes = parameterTypes; - } - - @Override - public Constructor run() throws NoSuchMethodException { - return javaClass.getDeclaredConstructor(parameterTypes); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetDeclaredConstructorsAction.java b/impl/src/main/java/org/jboss/weld/security/GetDeclaredConstructorsAction.java deleted file mode 100644 index 182b7c8632..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetDeclaredConstructorsAction.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Constructor; -import java.security.PrivilegedAction; - -public class GetDeclaredConstructorsAction extends AbstractReflectionAction implements PrivilegedAction[]> { - - public GetDeclaredConstructorsAction(Class javaClass) { - super(javaClass); - } - - @Override - public Constructor[] run() { - return javaClass.getDeclaredConstructors(); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetDeclaredFieldAction.java b/impl/src/main/java/org/jboss/weld/security/GetDeclaredFieldAction.java deleted file mode 100644 index 67516f2713..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetDeclaredFieldAction.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Field; -import java.security.PrivilegedExceptionAction; - -public class GetDeclaredFieldAction extends AbstractReflectionAction implements PrivilegedExceptionAction { - - protected final String fieldName; - - public GetDeclaredFieldAction(Class javaClass, String fieldName) { - super(javaClass); - this.fieldName = fieldName; - } - - @Override - public Field run() throws NoSuchFieldException { - return javaClass.getDeclaredField(fieldName); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetDeclaredFieldsAction.java b/impl/src/main/java/org/jboss/weld/security/GetDeclaredFieldsAction.java deleted file mode 100644 index ac316329f8..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetDeclaredFieldsAction.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Field; -import java.security.PrivilegedAction; - -public class GetDeclaredFieldsAction extends AbstractReflectionAction implements PrivilegedAction { - - public GetDeclaredFieldsAction(Class javaClass) { - super(javaClass); - } - - @Override - public Field[] run() { - return javaClass.getDeclaredFields(); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetDeclaredMethodAction.java b/impl/src/main/java/org/jboss/weld/security/GetDeclaredMethodAction.java deleted file mode 100644 index 7c94e9a3b6..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetDeclaredMethodAction.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Method; -import java.security.PrivilegedAction; -import java.security.PrivilegedExceptionAction; - -import org.jboss.weld.exceptions.WeldException; -import org.jboss.weld.logging.ReflectionLogger; - -public abstract class GetDeclaredMethodAction extends AbstractReflectionAction { - - public static PrivilegedExceptionAction of(Class javaClass, String methodName, Class... parameterTypes) { - return new ExceptionAction(javaClass, methodName, parameterTypes); - } - - /** - * Returns {@link PrivilegedAction} instead of {@link PrivilegedExceptionAction}. If {@link NoSuchMethodException} is thrown - * it is wrapped within {@link WeldException} using - * {@link ReflectionLogger#noSuchMethodWrapper(NoSuchMethodException, String)}. - */ - public static PrivilegedAction wrapException(Class javaClass, String methodName, Class... parameterTypes) { - return new WrappingAction(javaClass, methodName, parameterTypes); - } - - protected final String methodName; - protected final Class[] parameterTypes; - - public GetDeclaredMethodAction(Class javaClass, String methodName, Class... parameterTypes) { - super(javaClass); - this.methodName = methodName; - this.parameterTypes = parameterTypes; - } - - public Method run() throws NoSuchMethodException { - return javaClass.getDeclaredMethod(methodName, parameterTypes); - } - - private static class ExceptionAction extends GetDeclaredMethodAction implements PrivilegedExceptionAction { - public ExceptionAction(Class javaClass, String methodName, Class[] parameterTypes) { - super(javaClass, methodName, parameterTypes); - } - } - - private static class WrappingAction extends GetDeclaredMethodAction implements PrivilegedAction { - - public WrappingAction(Class javaClass, String methodName, Class[] parameterTypes) { - super(javaClass, methodName, parameterTypes); - } - - @Override - public Method run() { - try { - return super.run(); - } catch (NoSuchMethodException e) { - throw ReflectionLogger.LOG.noSuchMethodWrapper(e, e.getMessage()); - } - } - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetDeclaredMethodsAction.java b/impl/src/main/java/org/jboss/weld/security/GetDeclaredMethodsAction.java deleted file mode 100644 index 505d1e1471..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetDeclaredMethodsAction.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Method; -import java.security.PrivilegedAction; - -public class GetDeclaredMethodsAction extends AbstractReflectionAction implements PrivilegedAction { - - public GetDeclaredMethodsAction(Class javaClass) { - super(javaClass); - } - - @Override - public Method[] run() { - return javaClass.getDeclaredMethods(); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetFieldAction.java b/impl/src/main/java/org/jboss/weld/security/GetFieldAction.java deleted file mode 100644 index d5e231bbbb..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetFieldAction.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Field; -import java.security.PrivilegedExceptionAction; - -public class GetFieldAction extends AbstractReflectionAction implements PrivilegedExceptionAction { - - private final String fieldName; - - public GetFieldAction(Class javaClass, String fieldName) { - super(javaClass); - this.fieldName = fieldName; - } - - @Override - public Field run() throws NoSuchFieldException { - return javaClass.getField(fieldName); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetFieldsAction.java b/impl/src/main/java/org/jboss/weld/security/GetFieldsAction.java deleted file mode 100644 index 01c6bc9e85..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetFieldsAction.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Field; -import java.security.PrivilegedAction; - -public class GetFieldsAction extends AbstractReflectionAction implements PrivilegedAction { - - public GetFieldsAction(Class javaClass) { - super(javaClass); - } - - @Override - public Field[] run() { - return javaClass.getFields(); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetMethodAction.java b/impl/src/main/java/org/jboss/weld/security/GetMethodAction.java deleted file mode 100644 index 798b429f99..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetMethodAction.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Method; -import java.security.PrivilegedExceptionAction; - -public class GetMethodAction extends AbstractReflectionAction implements PrivilegedExceptionAction { - - private final String methodName; - private final Class[] parameterTypes; - - public GetMethodAction(Class javaClass, String methodName, Class... parameterTypes) { - super(javaClass); - this.methodName = methodName; - this.parameterTypes = parameterTypes; - } - - @Override - public Method run() throws NoSuchMethodException { - return javaClass.getMethod(methodName, parameterTypes); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetMethodsAction.java b/impl/src/main/java/org/jboss/weld/security/GetMethodsAction.java deleted file mode 100644 index 1ba84e081d..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetMethodsAction.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Method; -import java.security.PrivilegedAction; - -public class GetMethodsAction extends AbstractReflectionAction implements PrivilegedAction { - - public GetMethodsAction(Class javaClass) { - super(javaClass); - } - - @Override - public Method[] run() { - return javaClass.getMethods(); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetProtectionDomainAction.java b/impl/src/main/java/org/jboss/weld/security/GetProtectionDomainAction.java deleted file mode 100644 index 24bed8a0c2..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetProtectionDomainAction.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2014, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.security.PrivilegedAction; -import java.security.ProtectionDomain; - -public final class GetProtectionDomainAction implements PrivilegedAction { - - private final Class clazz; - - public GetProtectionDomainAction(Class clazz) { - this.clazz = clazz; - } - - @Override - public ProtectionDomain run() { - return clazz.getProtectionDomain(); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/GetSystemPropertyAction.java b/impl/src/main/java/org/jboss/weld/security/GetSystemPropertyAction.java deleted file mode 100644 index 2c339b4fcb..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/GetSystemPropertyAction.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.security.PrivilegedAction; - -public class GetSystemPropertyAction implements PrivilegedAction { - - private final String propertyName; - - public GetSystemPropertyAction(String propertyName) { - this.propertyName = propertyName; - } - - @Override - public String run() { - return System.getProperty(propertyName); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/MethodLookupAction.java b/impl/src/main/java/org/jboss/weld/security/MethodLookupAction.java deleted file mode 100644 index 96828e821d..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/MethodLookupAction.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Method; -import java.security.PrivilegedExceptionAction; -import java.util.Arrays; - -/** - * Returns a method from the class or any class/interface in the inheritance hierarchy - * - * @author Jozef Hartinger - * - */ -public class MethodLookupAction extends GetDeclaredMethodAction implements PrivilegedExceptionAction { - - public MethodLookupAction(Class javaClass, String methodName, Class[] parameterTypes) { - super(javaClass, methodName, parameterTypes); - } - - @Override - public Method run() throws NoSuchMethodException { - return lookupMethod(javaClass, methodName, parameterTypes); - } - - public static Method lookupMethod(Class javaClass, String methodName, Class[] parameterTypes) - throws NoSuchMethodException { - for (Class inspectedClass = javaClass; inspectedClass != null; inspectedClass = inspectedClass.getSuperclass()) { - for (Class inspectedInterface : inspectedClass.getInterfaces()) { - try { - return lookupMethod(inspectedInterface, methodName, parameterTypes); - } catch (NoSuchMethodException e) { - // Expected, nothing to see here. - } - } - try { - return inspectedClass.getDeclaredMethod(methodName, parameterTypes); - } catch (NoSuchMethodException nsme) { - // Expected, nothing to see here. - } - } - throw new NoSuchMethodException( - javaClass + ", method: " + methodName + ", paramTypes: " + Arrays.toString(parameterTypes)); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/NewInstanceAction.java b/impl/src/main/java/org/jboss/weld/security/NewInstanceAction.java deleted file mode 100644 index fde8b0c198..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/NewInstanceAction.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.security.PrivilegedExceptionAction; - -public class NewInstanceAction extends AbstractGenericReflectionAction implements PrivilegedExceptionAction { - - public static NewInstanceAction of(Constructor constructor, Object... params) { - return new NewInstanceAction(constructor, params); - } - - private final Constructor constructor; - private final Object[] params; - - public NewInstanceAction(Constructor constructor, Object... params) { - super(constructor.getDeclaringClass()); - this.constructor = constructor; - this.params = params; - } - - @Override - public T run() throws InvocationTargetException, InstantiationException, IllegalAccessException { - return constructor.newInstance(params); - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/SetAccessibleAction.java b/impl/src/main/java/org/jboss/weld/security/SetAccessibleAction.java deleted file mode 100644 index 22da5301d4..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/SetAccessibleAction.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2013, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.lang.reflect.AccessibleObject; -import java.security.PrivilegedAction; - -public class SetAccessibleAction implements PrivilegedAction { - - public static SetAccessibleAction of(T object) { - return of(object, true); - } - - public static SetAccessibleAction of(T object, boolean value) { - return new SetAccessibleAction(object, value); - } - - private final T object; - private final boolean value; - - private SetAccessibleAction(T object, boolean value) { - this.object = object; - this.value = value; - } - - @Override - public T run() { - object.setAccessible(value); - return object; - } -} diff --git a/impl/src/main/java/org/jboss/weld/security/SetContextClassLoaderAction.java b/impl/src/main/java/org/jboss/weld/security/SetContextClassLoaderAction.java deleted file mode 100644 index 9352043977..0000000000 --- a/impl/src/main/java/org/jboss/weld/security/SetContextClassLoaderAction.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2019, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.security; - -import java.security.PrivilegedAction; - -/** - * Privileged action that sets the TCCL. - * - * @author Matej Novotny - * - */ -public class SetContextClassLoaderAction implements PrivilegedAction { - - private ClassLoader tccl; - - public SetContextClassLoaderAction(ClassLoader tccl) { - this.tccl = tccl; - } - - @Override - public Void run() { - Thread.currentThread().setContextClassLoader(tccl); - return null; - } -} diff --git a/impl/src/main/java/org/jboss/weld/serialization/ConstructorHolder.java b/impl/src/main/java/org/jboss/weld/serialization/ConstructorHolder.java index 1ab7de7066..37e6a9ed8b 100644 --- a/impl/src/main/java/org/jboss/weld/serialization/ConstructorHolder.java +++ b/impl/src/main/java/org/jboss/weld/serialization/ConstructorHolder.java @@ -17,8 +17,6 @@ package org.jboss.weld.serialization; import java.lang.reflect.Constructor; -import java.security.AccessController; -import java.security.PrivilegedAction; import org.jboss.weld.logging.ReflectionLogger; import org.jboss.weld.util.reflection.DeclaredMemberIndexer; @@ -29,8 +27,7 @@ * @author Jozef Hartinger * */ -public class ConstructorHolder extends AbstractSerializableHolder> - implements PrivilegedAction> { +public class ConstructorHolder extends AbstractSerializableHolder> { private static final long serialVersionUID = -6439218442811003152L; @@ -49,15 +46,11 @@ public ConstructorHolder(Constructor constructor) { @Override protected Constructor initialize() { - return AccessController.doPrivileged(this); - } - - @Override - public Constructor run() { try { return DeclaredMemberIndexer.getConstructorForIndex(index, declaringClass); } catch (Exception e) { throw ReflectionLogger.LOG.unableToGetConstructorOnDeserialization(declaringClass, index, e); } } + } diff --git a/impl/src/main/java/org/jboss/weld/serialization/FieldHolder.java b/impl/src/main/java/org/jboss/weld/serialization/FieldHolder.java index f7ce87895f..d57329afbd 100644 --- a/impl/src/main/java/org/jboss/weld/serialization/FieldHolder.java +++ b/impl/src/main/java/org/jboss/weld/serialization/FieldHolder.java @@ -17,8 +17,6 @@ package org.jboss.weld.serialization; import java.lang.reflect.Field; -import java.security.AccessController; -import java.security.PrivilegedAction; import org.jboss.weld.logging.ReflectionLogger; @@ -28,7 +26,7 @@ * @author Jozef Hartinger * */ -public class FieldHolder extends AbstractSerializableHolder implements PrivilegedAction { +public class FieldHolder extends AbstractSerializableHolder { private static final long serialVersionUID = 407021346356682729L; @@ -43,11 +41,6 @@ public FieldHolder(Field field) { @Override protected Field initialize() { - return AccessController.doPrivileged(this); - } - - @Override - public Field run() { try { return declaringClass.getDeclaredField(fieldName); } catch (Exception e) { diff --git a/impl/src/main/java/org/jboss/weld/serialization/MethodHolder.java b/impl/src/main/java/org/jboss/weld/serialization/MethodHolder.java index 8ce612450f..dd5cf9dd11 100644 --- a/impl/src/main/java/org/jboss/weld/serialization/MethodHolder.java +++ b/impl/src/main/java/org/jboss/weld/serialization/MethodHolder.java @@ -17,8 +17,6 @@ package org.jboss.weld.serialization; import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedAction; import java.util.Objects; import jakarta.enterprise.inject.spi.AnnotatedMethod; @@ -32,7 +30,7 @@ * @author Jozef Hartinger * */ -public class MethodHolder extends AbstractSerializableHolder implements PrivilegedAction { +public class MethodHolder extends AbstractSerializableHolder { private static final long serialVersionUID = -3033089710155551280L; @@ -55,11 +53,6 @@ public static MethodHolder of(AnnotatedMethod method) { @Override protected Method initialize() { - return AccessController.doPrivileged(this); - } - - @Override - public Method run() { try { return DeclaredMemberIndexer.getMethodForIndex(index, declaringClass); } catch (Exception e) { diff --git a/impl/src/main/java/org/jboss/weld/util/AccessControllers.java b/impl/src/main/java/org/jboss/weld/util/AccessControllers.java deleted file mode 100644 index 25cbfc78cf..0000000000 --- a/impl/src/main/java/org/jboss/weld/util/AccessControllers.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2015, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.util; - -import java.security.AccessController; -import java.security.PrivilegedAction; -import java.security.PrivilegedExceptionAction; - -/** - * Utils for working with PrivilegedActions, PrivilegedActionExceptions and AccessControllers. - * - * @author Jozef Hartinger - * - */ -public class AccessControllers { - - private AccessControllers() { - } - - /** - * Removes the ambiguity between {@link PrivilegedAction} and {@link PrivilegedExceptionAction} that normally occurs when a - * lambda is passed to - * {@link AccessController#doPrivileged()} - */ - public static PrivilegedAction action(PrivilegedAction action) { - return action; - } - -} diff --git a/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java b/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java index e3ba53e46e..014e709db3 100644 --- a/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java +++ b/impl/src/main/java/org/jboss/weld/util/AnnotatedTypes.java @@ -25,7 +25,6 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Type; -import java.security.AccessController; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; @@ -57,7 +56,6 @@ import jakarta.inject.Scope; import org.jboss.weld.logging.MetadataLogger; -import org.jboss.weld.security.GetDeclaredMethodsAction; import org.jboss.weld.util.collections.ImmutableSet; import org.jboss.weld.util.reflection.Reflections; @@ -315,7 +313,7 @@ protected static String createAnnotationCollectionId(Collection anno builder.append('@'); builder.append(a.annotationType().getName()); builder.append('('); - Method[] declaredMethods = AccessController.doPrivileged(new GetDeclaredMethodsAction(a.annotationType())); + Method[] declaredMethods = a.annotationType().getDeclaredMethods(); List methods = new ArrayList(declaredMethods.length); Collections.addAll(methods, declaredMethods); Collections.sort(methods, MethodComparator.INSTANCE); diff --git a/impl/src/main/java/org/jboss/weld/util/Observers.java b/impl/src/main/java/org/jboss/weld/util/Observers.java index 2aa33f2674..dc30be7389 100644 --- a/impl/src/main/java/org/jboss/weld/util/Observers.java +++ b/impl/src/main/java/org/jboss/weld/util/Observers.java @@ -18,7 +18,6 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Method; -import java.security.AccessController; import java.util.Set; import jakarta.enterprise.inject.Any; @@ -56,7 +55,6 @@ import org.jboss.weld.event.SyntheticObserverMethod; import org.jboss.weld.logging.EventLogger; import org.jboss.weld.manager.BeanManagerImpl; -import org.jboss.weld.security.GetDeclaredMethodsAction; import org.jboss.weld.util.collections.ImmutableSet; import org.jboss.weld.util.reflection.Reflections; @@ -180,7 +178,7 @@ private static boolean hasNotifyOverriden(Class clazz, ObserverMethod obse if (clazz.isInterface()) { return false; } - for (Method method : AccessController.doPrivileged(new GetDeclaredMethodsAction(clazz))) { + for (Method method : clazz.getDeclaredMethods()) { if (NOTIFY_METHOD_NAME.equals(method.getName()) && method.getParameterCount() == 1) { return true; } diff --git a/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java b/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java index feaf9029a6..f96ca93fb3 100644 --- a/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java +++ b/impl/src/main/java/org/jboss/weld/util/reflection/Reflections.java @@ -20,6 +20,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.AccessibleObject; import java.lang.reflect.Array; +import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.GenericArrayType; import java.lang.reflect.InvocationTargetException; @@ -30,7 +31,6 @@ import java.lang.reflect.Type; import java.lang.reflect.TypeVariable; import java.lang.reflect.WildcardType; -import java.security.AccessController; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -43,7 +43,6 @@ import org.jboss.weld.logging.ReflectionLogger; import org.jboss.weld.resources.spi.ResourceLoader; import org.jboss.weld.resources.spi.ResourceLoadingException; -import org.jboss.weld.security.GetDeclaredMethodsAction; import org.jboss.weld.util.Types; /** @@ -169,9 +168,9 @@ public static boolean isTypeOrAnyMethodFinal(Class type) { return isFinal(type) || getNonPrivateNonStaticFinalMethod(type) != null; } - public static Method getNonPrivateNonStaticFinalMethod(Class type) {// TODO grep for access controller + public static Method getNonPrivateNonStaticFinalMethod(Class type) { for (Class clazz = type; clazz != null && clazz != Object.class; clazz = clazz.getSuperclass()) { - for (Method method : AccessController.doPrivileged(new GetDeclaredMethodsAction(clazz))) { + for (Method method : clazz.getDeclaredMethods()) { if (isFinal(method) && !isPrivate(method) && !isStatic(method) && !method.isSynthetic()) { return method; } @@ -442,10 +441,10 @@ public static void checkDeclaringClassLoadable(Class c) { * * @param clazz the given class * @param methodName the given method name - * @return method method with the given name declared by the given class or null if no such method exists + * @return method with the given name declared by the given class or null if no such method exists */ public static Method findDeclaredMethodByName(Class clazz, String methodName) { - for (Method method : AccessController.doPrivileged(new GetDeclaredMethodsAction(clazz))) { + for (Method method : clazz.getDeclaredMethods()) { if (methodName.equals(method.getName())) { return method; } @@ -576,4 +575,122 @@ public static void ensureAccessible(AccessibleObject accessibleObject, Object in } } } + + /** + * Creates a copy of the given Java member (field, method, constructor) and makes it accessible. + * + * @param member + * @return + * @param + */ + public static T getAccessibleCopyOfMember(T member) { + T copy = copyMember(member); + copy.setAccessible(true); + return copy; + } + + private static T copyMember(T originalMember) { + final String unableToObtainAccessibleCopyOf = "Unable to obtain an accessible copy of "; + Class declaringClass = originalMember.getDeclaringClass(); + try { + if (originalMember instanceof Field) { + return (T) copyField((Field) originalMember, declaringClass); + } + if (originalMember instanceof Constructor) { + return (T) copyConstructor((Constructor) originalMember, declaringClass); + } + if (originalMember instanceof Method) { + return (T) copyMethod((Method) originalMember, declaringClass); + } + } catch (Exception e) { + throw new IllegalArgumentException(unableToObtainAccessibleCopyOf + originalMember, e); + } + throw new IllegalArgumentException(unableToObtainAccessibleCopyOf + originalMember); + } + + private static Field copyField(Field field, Class declaringClass) throws NoSuchFieldException { + return declaringClass.getDeclaredField(field.getName()); + } + + private static Method copyMethod(Method method, Class declaringClass) throws NoSuchMethodException { + return declaringClass.getDeclaredMethod(method.getName(), method.getParameterTypes()); + } + + private static Constructor copyConstructor(Constructor constructor, Class declaringClass) + throws NoSuchMethodException { + return declaringClass.getDeclaredConstructor(constructor.getParameterTypes()); + } + + /** + * Looks up a field with given name within the class and any of its superclasses. + * + * @param javaClass + * @param fieldName + * @return + * @throws NoSuchMethodException + */ + public static Field lookupField(Class javaClass, String fieldName) throws NoSuchFieldException { + for (Class inspectedClass = javaClass; inspectedClass != null; inspectedClass = inspectedClass.getSuperclass()) { + for (Class inspectedInterface : inspectedClass.getInterfaces()) { + try { + return lookupField(inspectedInterface, fieldName); + } catch (NoSuchFieldException e) { + // Expected, nothing to see here. + } + } + try { + return inspectedClass.getDeclaredField(fieldName); + } catch (NoSuchFieldException nsme) { + // Expected, nothing to see here. + } + } + throw new NoSuchFieldException(); + } + + /** + * Looks up a method with given name and parameters within the class and any of its superclasses. + * + * @param javaClass + * @param methodName + * @param parameterTypes + * @return + * @throws NoSuchMethodException + */ + public static Method lookupMethod(Class javaClass, String methodName, Class[] parameterTypes) + throws NoSuchMethodException { + for (Class inspectedClass = javaClass; inspectedClass != null; inspectedClass = inspectedClass.getSuperclass()) { + for (Class inspectedInterface : inspectedClass.getInterfaces()) { + try { + return lookupMethod(inspectedInterface, methodName, parameterTypes); + } catch (NoSuchMethodException e) { + // Expected, nothing to see here. + } + } + try { + return inspectedClass.getDeclaredMethod(methodName, parameterTypes); + } catch (NoSuchMethodException nsme) { + // Expected, nothing to see here. + } + } + throw new NoSuchMethodException( + javaClass + ", method: " + methodName + ", paramTypes: " + Arrays.toString(parameterTypes)); + } + + /** + * Attempts to look up a method based on provided name and parameter types within given class. + * If the method exists, it is returned; otherwise, the exception throws is wrapped in + * {@link ReflectionLogger#noSuchMethodWrapper(NoSuchMethodException, String)} + * + * @param javaClass class that should contain the method + * @param methodName method name + * @param parameterTypes method parameter types + * @return + */ + public static Method wrapException(Class javaClass, String methodName, Class... parameterTypes) { + try { + return javaClass.getDeclaredMethod(methodName, parameterTypes); + } catch (NoSuchMethodException e) { + throw ReflectionLogger.LOG.noSuchMethodWrapper(e, e.getMessage()); + } + } } diff --git a/impl/src/test/java/org/jboss/weld/tests/unit/security/ReflectionTest.java b/impl/src/test/java/org/jboss/weld/tests/unit/security/ReflectionTest.java deleted file mode 100644 index 683b7e136e..0000000000 --- a/impl/src/test/java/org/jboss/weld/tests/unit/security/ReflectionTest.java +++ /dev/null @@ -1,259 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.tests.unit.security; - -import static org.junit.Assert.fail; - -import java.lang.reflect.AccessibleObject; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.PrivilegedActionException; - -import org.jboss.weld.security.FieldLookupAction; -import org.jboss.weld.security.GetConstructorAction; -import org.jboss.weld.security.GetConstructorsAction; -import org.jboss.weld.security.GetDeclaredConstructorAction; -import org.jboss.weld.security.GetDeclaredConstructorsAction; -import org.jboss.weld.security.GetDeclaredFieldAction; -import org.jboss.weld.security.GetDeclaredFieldsAction; -import org.jboss.weld.security.GetDeclaredMethodAction; -import org.jboss.weld.security.GetDeclaredMethodsAction; -import org.jboss.weld.security.GetFieldAction; -import org.jboss.weld.security.GetFieldsAction; -import org.jboss.weld.security.GetMethodAction; -import org.jboss.weld.security.GetMethodsAction; -import org.jboss.weld.security.MethodLookupAction; -import org.jboss.weld.security.NewInstanceAction; -import org.jboss.weld.security.SetAccessibleAction; -import org.junit.Assert; -import org.junit.Test; - -public class ReflectionTest { - - @Test - public void testGetField() throws PrivilegedActionException { - Assert.assertNotNull(AccessController.doPrivileged(new GetFieldAction(TestObject.class, "publicField"))); - } - - @Test(expected = NoSuchFieldException.class) - public void testGetFieldNotFound() throws Throwable { - try { - AccessController.doPrivileged(new GetFieldAction(TestObject.class, "eioota")); - } catch (PrivilegedActionException e) { - throw e.getCause(); - } - } - - @Test - public void testGetDeclaredField() throws PrivilegedActionException { - Assert.assertNotNull(AccessController.doPrivileged(new GetDeclaredFieldAction(TestObject.class, "publicField"))); - } - - @Test(expected = NoSuchFieldException.class) - public void testGetDeclaredFieldNotFound() throws Throwable { - try { - AccessController.doPrivileged(new GetDeclaredFieldAction(TestObject.class, "eioota")); - } catch (PrivilegedActionException e) { - throw e.getCause(); - } - } - - @Test - public void testGetFields() { - Assert.assertEquals(1, AccessController.doPrivileged(new GetFieldsAction(TestObject.class)).length); - } - - @Test - public void testGetDeclaredFields() { - Assert.assertEquals(2, AccessController.doPrivileged(new GetDeclaredFieldsAction(TestObject.class)).length); - } - - @Test - public void testFieldAccess() { - testAllAccessible(grantAccess(AccessController.doPrivileged(new GetDeclaredFieldsAction(TestObject.class)))); - } - - private AccessibleObject[] grantAccess(AccessibleObject[] objects) { - for (AccessibleObject object : objects) { - AccessController.doPrivileged(SetAccessibleAction.of(object)); - } - return objects; - } - - private void testAllAccessible(AccessibleObject[] objects) { - for (AccessibleObject object : objects) { - if (!object.isAccessible()) { - Assert.fail(); - } - } - } - - @Test - public void testGetMethod() throws PrivilegedActionException { - Assert.assertNotNull(AccessController - .doPrivileged(new GetMethodAction(TestObject.class, "publicTest", new Class[] { String.class }))); - } - - @Test(expected = NoSuchMethodException.class) - public void testGetMethodNotFound() throws Throwable { - try { - AccessController - .doPrivileged(new GetMethodAction(TestObject.class, "xpublicTest", new Class[] { String.class })); - } catch (PrivilegedActionException e) { - throw e.getCause(); - } - } - - @Test - public void testGetDeclaredMethod() throws PrivilegedActionException { - Assert.assertNotNull(AccessController - .doPrivileged(GetDeclaredMethodAction.of(TestObject.class, "publicTest", new Class[] { String.class }))); - } - - @Test(expected = NoSuchMethodException.class) - public void testGetDeclaredMethodNotFound() throws Throwable { - try { - AccessController - .doPrivileged(GetDeclaredMethodAction.of(TestObject.class, "xpublicTest", new Class[] { String.class })); - } catch (PrivilegedActionException e) { - throw e.getCause(); - } - } - - @Test - public void testGetMethods() { - Assert.assertEquals(10, AccessController.doPrivileged(new GetMethodsAction(TestObject.class)).length); - } - - @Test - public void testGetDeclaredMethods() { - Assert.assertEquals(2, AccessController.doPrivileged(new GetDeclaredMethodsAction(TestObject.class)).length); - } - - @Test - public void testMethodAccess() { - testAllAccessible(grantAccess(AccessController.doPrivileged(new GetDeclaredMethodsAction(TestObject.class)))); - } - - @Test - public void testGetConstructor() throws PrivilegedActionException { - Assert.assertNotNull( - AccessController.doPrivileged(GetConstructorAction.of(TestObject.class, new Class[] { Integer.class }))); - } - - @Test(expected = NoSuchMethodException.class) - public void testGetConstructorNotFound() throws Throwable { - try { - AccessController.doPrivileged(GetConstructorAction.of(TestObject.class, new Class[] { Float.class })); - } catch (PrivilegedActionException e) { - throw e.getCause(); - } - } - - @Test - public void testGetDeclaredConstructor() throws PrivilegedActionException { - Assert.assertNotNull(AccessController - .doPrivileged(GetDeclaredConstructorAction.of(TestObject.class, new Class[] { String.class }))); - } - - @Test(expected = NoSuchMethodException.class) - public void testGetDeclaredConstructorNotFound() throws Throwable { - try { - AccessController.doPrivileged(GetDeclaredConstructorAction.of(TestObject.class, new Class[] { Float.class })); - } catch (PrivilegedActionException e) { - throw e.getCause(); - } - } - - @Test - public void testGetConstructors() { - Assert.assertEquals(2, AccessController.doPrivileged(new GetConstructorsAction(TestObject.class)).length); - } - - @Test - public void testGetDeclaredConstructors() { - Assert.assertEquals(3, AccessController.doPrivileged(new GetDeclaredConstructorsAction(TestObject.class)).length); - } - - @Test - public void testConstructorAccess() { - testAllAccessible(grantAccess(AccessController.doPrivileged(new GetDeclaredConstructorsAction(TestObject.class)))); - } - - @Test - public void testNewInstance() throws PrivilegedActionException { - Assert.assertNotNull(AccessController.doPrivileged( - NewInstanceAction.of(AccessController.doPrivileged(GetDeclaredConstructorAction.of(TestObject.class))))); - } - - @Test - public void testInvoke() throws SecurityException, NoSuchMethodException, IllegalArgumentException, IllegalAccessException, - InvocationTargetException { - TestObject to = new TestObject(); - Method m = TestObject.class.getMethod("publicTest", new Class[] { String.class }); - Assert.assertEquals("foo", m.invoke(to, "")); - } - - @Test - public void testLookupMethod() throws PrivilegedActionException, NoSuchMethodException { - Assert.assertNotNull( - AccessController.doPrivileged(new MethodLookupAction(TestObject.class, "rootOfAllEvil", new Class[] {}))); - Assert.assertNotNull(MethodLookupAction.lookupMethod(TestObject.class, "rootOfAllEvil", new Class[] {})); - } - - @Test - public void testLookupMethodNotFound() throws Throwable { - try { - AccessController.doPrivileged(new MethodLookupAction(TestObject.class, "eioota", new Class[] {})); - fail(); - } catch (PrivilegedActionException e) { - if (!(e.getCause() instanceof NoSuchMethodException)) { - fail(); - } - } - try { - MethodLookupAction.lookupMethod(TestObject.class, "eioota", new Class[] {}); - fail(); - } catch (NoSuchMethodException e) { - } - } - - @Test - public void testLookupField() throws PrivilegedActionException, NoSuchFieldException { - Assert.assertNotNull(AccessController.doPrivileged(new FieldLookupAction(TestObject.class, "privateField"))); - Assert.assertNotNull(FieldLookupAction.lookupField(TestObject.class, "privateField")); - } - - @Test - public void testLookupFieldNotFound() throws Throwable { - try { - AccessController.doPrivileged(new FieldLookupAction(TestObject.class, "eioota")); - fail(); - } catch (PrivilegedActionException e) { - if (!(e.getCause() instanceof NoSuchFieldException)) { - fail(); - } - } - try { - FieldLookupAction.lookupField(TestObject.class, "eioota"); - fail(); - } catch (NoSuchFieldException e) { - } - } - -} diff --git a/impl/src/test/java/org/jboss/weld/tests/unit/security/SecurityTest.java b/impl/src/test/java/org/jboss/weld/tests/unit/security/SecurityTest.java deleted file mode 100644 index 1c32c4d5a6..0000000000 --- a/impl/src/test/java/org/jboss/weld/tests/unit/security/SecurityTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.tests.unit.security; - -import java.lang.reflect.Field; - -import org.junit.Assert; -import org.junit.Test; - -/** - * @author pmuir - */ -public class SecurityTest { - - @SuppressWarnings("unused") - private String foo; - - @Test - public void testSetAccessibleDoesNotPropagate() throws Exception { - Field field = SecurityTest.class.getDeclaredField("foo"); - Assert.assertFalse(field.isAccessible()); - field.setAccessible(true); - Assert.assertTrue(field.isAccessible()); - Assert.assertFalse(SecurityTest.class.getDeclaredField("foo").isAccessible()); - Assert.assertFalse(SecurityTest.class.getDeclaredField("foo") == SecurityTest.class.getDeclaredField("foo")); - } - -} diff --git a/impl/src/test/java/org/jboss/weld/tests/unit/security/SuperTestObject.java b/impl/src/test/java/org/jboss/weld/tests/unit/security/SuperTestObject.java deleted file mode 100644 index e8089edf71..0000000000 --- a/impl/src/test/java/org/jboss/weld/tests/unit/security/SuperTestObject.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.tests.unit.security; - -public class SuperTestObject { - protected void rootOfAllEvil() { - } - -} diff --git a/impl/src/test/java/org/jboss/weld/tests/unit/security/TestObject.java b/impl/src/test/java/org/jboss/weld/tests/unit/security/TestObject.java deleted file mode 100644 index 30ceee5f4c..0000000000 --- a/impl/src/test/java/org/jboss/weld/tests/unit/security/TestObject.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * JBoss, Home of Professional Open Source - * Copyright 2010, Red Hat, Inc., and individual contributors - * by the @authors tag. See the copyright.txt in the distribution for a - * full listing of individual contributors. - * - * Licensed 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.jboss.weld.tests.unit.security; - -/** - * A test object which has some private members that we try to access with - * reflection in {@link ReflectionTest}. - * - * @author Pete Muir - */ -public class TestObject extends SuperTestObject { - @SuppressWarnings("unused") - private String privateField; - public String publicField; - - @SuppressWarnings("unused") - private TestObject(String test) { - } - - public TestObject() { - } - - public TestObject(Integer test) { - } - - @SuppressWarnings("unused") - private void privateTest(String test) { - } - - public String publicTest(String test) { - return "foo"; - } -} diff --git a/impl/src/test/java/org/jboss/weld/tests/unit/util/reflection/FormatsTest.java b/impl/src/test/java/org/jboss/weld/tests/unit/util/reflection/FormatsTest.java index bb28ffc15e..a430afeacb 100644 --- a/impl/src/test/java/org/jboss/weld/tests/unit/util/reflection/FormatsTest.java +++ b/impl/src/test/java/org/jboss/weld/tests/unit/util/reflection/FormatsTest.java @@ -22,15 +22,12 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Member; import java.lang.reflect.Method; -import java.security.AccessController; import java.util.Arrays; import java.util.List; import jakarta.enterprise.inject.spi.BeanManager; import jakarta.enterprise.util.TypeLiteral; -import org.jboss.weld.security.GetDeclaredConstructorsAction; -import org.jboss.weld.security.GetDeclaredMethodsAction; import org.jboss.weld.util.reflection.Formats; import org.junit.Test; @@ -86,7 +83,7 @@ void assertLineFound(Member member) { Constructor findConstructor(Class javaClass, Class... parameterTypes) { Class clazz = javaClass; while (clazz != Object.class && clazz != null) { - for (Constructor constructor : AccessController.doPrivileged(new GetDeclaredConstructorsAction(clazz))) { + for (Constructor constructor : clazz.getDeclaredConstructors()) { if (Arrays.equals(constructor.getParameterTypes(), parameterTypes)) { return constructor; } @@ -99,7 +96,7 @@ Constructor findConstructor(Class javaClass, Class... parameterTypes) { Method findMethod(Class javaClass, String name, Class... parameterTypes) { Class clazz = javaClass; while (clazz != Object.class && clazz != null) { - for (Method method : AccessController.doPrivileged(new GetDeclaredMethodsAction(clazz))) { + for (Method method : clazz.getDeclaredMethods()) { if (method.getName().equals(name) && Arrays.equals(method.getParameterTypes(), parameterTypes)) { return method; } diff --git a/modules/ejb/src/main/java/org/jboss/weld/module/ejb/SessionBeanProxyInstantiator.java b/modules/ejb/src/main/java/org/jboss/weld/module/ejb/SessionBeanProxyInstantiator.java index 02fed72eaa..12a39a1c05 100644 --- a/modules/ejb/src/main/java/org/jboss/weld/module/ejb/SessionBeanProxyInstantiator.java +++ b/modules/ejb/src/main/java/org/jboss/weld/module/ejb/SessionBeanProxyInstantiator.java @@ -17,8 +17,6 @@ package org.jboss.weld.module.ejb; import java.lang.reflect.Constructor; -import java.security.AccessController; -import java.security.PrivilegedActionException; import jakarta.enterprise.context.Dependent; import jakarta.enterprise.context.spi.CreationalContext; @@ -27,12 +25,9 @@ import org.jboss.weld.bean.SessionBean; import org.jboss.weld.bean.proxy.EnterpriseTargetBeanInstance; import org.jboss.weld.bean.proxy.ProxyFactory; -import org.jboss.weld.exceptions.WeldException; import org.jboss.weld.injection.producer.Instantiator; import org.jboss.weld.logging.BeanLogger; import org.jboss.weld.manager.BeanManagerImpl; -import org.jboss.weld.security.GetDeclaredConstructorAction; -import org.jboss.weld.security.NewInstanceAction; /** * Instantiator implementation that instantiates a proxy for a session bean. @@ -52,22 +47,13 @@ class SessionBeanProxyInstantiator implements Instantiator { @Override public T newInstance(CreationalContext ctx, BeanManagerImpl manager) { try { - T instance = AccessController.doPrivileged( - NewInstanceAction.of(AccessController.doPrivileged(GetDeclaredConstructorAction.of(proxyClass)))); + T instance = proxyClass.getDeclaredConstructor().newInstance(); if (!bean.getScope().equals(Dependent.class)) { ctx.push(instance); } ProxyFactory.setBeanInstance(bean.getBeanManager().getContextId(), instance, createEnterpriseTargetBeanInstance(), bean); return instance; - } catch (PrivilegedActionException e) { - if (e.getCause() instanceof InstantiationException) { - throw new WeldException(BeanLogger.LOG.proxyInstantiationFailed(this), e.getCause()); - } else if (e.getCause() instanceof IllegalAccessException) { - throw new WeldException(BeanLogger.LOG.proxyInstantiationBeanAccessFailed(this), e.getCause()); - } else { - throw new WeldException(e.getCause()); - } } catch (Exception e) { throw BeanLogger.LOG.sessionBeanProxyInstantiationFailed(bean, proxyClass, e); } diff --git a/modules/web/src/main/java/org/jboss/weld/module/web/ServletContextBean.java b/modules/web/src/main/java/org/jboss/weld/module/web/ServletContextBean.java index 2783f51759..8512e12238 100644 --- a/modules/web/src/main/java/org/jboss/weld/module/web/ServletContextBean.java +++ b/modules/web/src/main/java/org/jboss/weld/module/web/ServletContextBean.java @@ -17,7 +17,6 @@ package org.jboss.weld.module.web; import java.lang.annotation.Annotation; -import java.security.AccessController; import jakarta.enterprise.context.RequestScoped; import jakarta.enterprise.context.spi.CreationalContext; @@ -28,7 +27,6 @@ import org.jboss.weld.manager.BeanManagerImpl; import org.jboss.weld.module.web.logging.ServletLogger; import org.jboss.weld.module.web.servlet.ServletContextService; -import org.jboss.weld.security.GetContextClassLoaderAction; /** * Built-in bean exposing {@link ServletContext}. @@ -49,8 +47,7 @@ public ServletContextBean(BeanManagerImpl beanManager) { protected ServletContext newInstance(InjectionPoint ip, CreationalContext creationalContext) { final ServletContext ctx = servletContexts.getCurrentServletContext(); if (ctx == null) { - final ClassLoader cl = AccessController.doPrivileged(GetContextClassLoaderAction.INSTANCE); - throw ServletLogger.LOG.cannotInjectServletContext(cl, servletContexts); + throw ServletLogger.LOG.cannotInjectServletContext(Thread.currentThread().getContextClassLoader(), servletContexts); } return ctx; }