Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WELD-2789 Review SecurityManager usage for Weld 6 #2983

Merged
merged 4 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions docs/reference/src/main/asciidoc/extend.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -349,10 +349,10 @@ objects managed by another framework to be injected into beans.
The most common kind of CDI portable extension registers a bean (or
beans) with the container.

In this example, we make a framework class, `SecurityManager` available
In this example, we make a framework class, `FrameworkManager` available
for injection. To make things a bit more interesting, we're going to
delegate back to the container's `InjectionTarget` to perform
instantiation and injection upon the `SecurityManager` instance.
instantiation and injection upon the `FrameworkManager` instance.

[source.JAVA, java]
-------------------------------------------------------------------------------------------
Expand All @@ -363,15 +363,15 @@ import java.lang.reflect.Type;
import jakarta.enterprise.inject.spi.InjectionPoint;
...

public class SecurityManagerExtension implements Extension {
public class FrameworkManagerExtension implements Extension {

void afterBeanDiscovery(@Observes AfterBeanDiscovery event, BeanManager bm) {
event.addBean()
/* read annotations of the class and create an InjectionTarget used to instantiate the class and inject dependencies */
.read(bm.createAnnotatedType(SecurityManager.class))
.beanClass(SecurityManager.class)
.read(bm.createAnnotatedType(FrameworkManager.class))
.beanClass(FrameworkManager.class)
.scope(ApplicationScoped.class)
.name("securityManager");
.name("frameworkManager");
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -82,7 +80,7 @@ public ClassPathBeanArchiveScanner(Bootstrap bootstrap, BeanDiscoveryMode emptyB

@Override
public List<ScanResult> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@ public static JandexDiscoveryStrategy createJandexDiscoveryStrategy(ResourceLoad

Class<JandexDiscoveryStrategy> strategyClass = Reflections.loadClass(resourceLoader,
JANDEX_DISCOVERY_STRATEGY_CLASS_NAME);
return SecurityActions
.newConstructorInstance(strategyClass,
new Class<?>[] { ResourceLoader.class, Bootstrap.class, Set.class, BeanDiscoveryMode.class },
resourceLoader, bootstrap,
return strategyClass.getConstructor(ResourceLoader.class, Bootstrap.class, Set.class, BeanDiscoveryMode.class)
.newInstance(resourceLoader, bootstrap,
initialBeanDefiningAnnotations, emptyBeansXmlDiscoveryMode);

}

}

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -477,7 +474,7 @@ public Weld addExtensions(Extension... extensions) {
public Weld addExtensions(Class<? extends Extension>... extensionClasses) {
for (Class<? extends Extension> extensionClass : extensionClasses) {
try {
Extension extension = SecurityActions.newInstance(extensionClass);
Extension extension = extensionClass.getDeclaredConstructor().newInstance();
addExtension(extension);
} catch (Exception ex) {
CommonLogger.LOG.unableToInstantiate(extensionClass, new Object[] {}, ex);
Expand Down Expand Up @@ -1172,7 +1169,7 @@ protected Iterable<Metadata<Extension>> getExtensions() {
}
if (weldSEBeanRegistrant == null) {
try {
weldSEBeanRegistrant = SecurityActions.newInstance(WeldSEBeanRegistrant.class);
weldSEBeanRegistrant = WeldSEBeanRegistrant.class.getDeclaredConstructor().newInstance();
result.add(new MetadataImpl<Extension>(weldSEBeanRegistrant,
SYNTHETIC_LOCATION_PREFIX + WeldSEBeanRegistrant.class.getName()));
} catch (Exception e) {
Expand All @@ -1187,8 +1184,8 @@ protected Iterable<Metadata<Extension>> getExtensions() {
if (!allBce.isEmpty()) {
try {
result.add(new MetadataImpl<Extension>(
SecurityActions.newInstance(SecurityActions.getDeclaredConstructor(LiteExtensionTranslator.class,
Collection.class, ClassLoader.class), allBce, Thread.currentThread().getContextClassLoader()),
LiteExtensionTranslator.class.getDeclaredConstructor(Collection.class, ClassLoader.class)
.newInstance(allBce, Thread.currentThread().getContextClassLoader()),
SYNTHETIC_LOCATION_PREFIX + LiteExtensionTranslator.class.getName()));
} catch (Exception e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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()) {
Expand Down Expand Up @@ -1400,8 +1396,7 @@ private static class PackInfo {
this.packName = packClass.getPackage().getName();
this.packClassName = packClass.getName();
this.scanRecursively = recursiveScan;
this.classLoaderRef = new WeakReference<ClassLoader>(
AccessController.doPrivileged(new GetClassLoaderAction(packClass)));
this.classLoaderRef = new WeakReference<ClassLoader>(packClass.getClassLoader());
}

PackInfo(Package pack, boolean recursiveScan) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static void endInitialization(WeldContainer container, boolean isShutdownHookEna
synchronized (LOCK) {
if (shutdownHook == null) {
shutdownHook = new ShutdownHook();
SecurityActions.addShutdownHook(shutdownHook);
Runtime.getRuntime().addShutdownHook(shutdownHook);
}
}
}
Expand Down
Loading
Loading