Skip to content

Commit

Permalink
remove support for Security Manager
Browse files Browse the repository at this point in the history
The Security Manager was deprecated for removal in Java 17 (see JEP 411).
It is about time to remove support for it in CDI.
  • Loading branch information
Ladicek authored and manovotn committed Nov 11, 2024
1 parent ca235a4 commit c057683
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 577 deletions.
21 changes: 0 additions & 21 deletions api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -334,27 +334,6 @@
<systemPropertyVariables>
<serviceDir>${project.build.testOutputDirectory}/META-INF/services/</serviceDir>
</systemPropertyVariables>
<excludes>
<exclude>**/privileged/**</exclude>
</excludes>
<useModulePath>false</useModulePath>
</configuration>
</execution>
<execution>
<id>privileged-test</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<systemPropertyVariables>
<serviceDir>${project.build.testOutputDirectory}/META-INF/services/</serviceDir>
</systemPropertyVariables>
<includes>
<include>**/privileged/**</include>
</includes>
<argLine>-Djava.security.manager -Djava.security.policy="${project.build.testOutputDirectory}/java.policy"</argLine>
<forkCount>1</forkCount>
<useModulePath>false</useModulePath>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ private static void discoverFactories() {
Set<BuildServices> factories = new TreeSet<>(
Comparator.comparingInt(BuildServices::getPriority).reversed());

ServiceLoader<BuildServices> loader = SecurityActions.loadService(
BuildServices.class, BuildServicesResolver.class.getClassLoader());
ServiceLoader<BuildServices> loader = ServiceLoader.load(BuildServices.class,
BuildServicesResolver.class.getClassLoader());

if (!loader.iterator().hasNext()) {
throw new IllegalStateException("Unable to locate BuildServices implementation");
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion api/src/main/java/jakarta/enterprise/inject/spi/CDI.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private static void findAllProviders() {
ServiceLoader<CDIProvider> providerLoader;
Set<CDIProvider> providers = new TreeSet<>(Comparator.comparingInt(CDIProvider::getPriority).reversed());

providerLoader = SecurityActions.loadService(CDIProvider.class, CDI.class.getClassLoader());
providerLoader = ServiceLoader.load(CDIProvider.class, CDI.class.getClassLoader());

if (!providerLoader.iterator().hasNext()) {
throw new IllegalStateException("Unable to locate CDIProvider");
Expand Down

This file was deleted.

11 changes: 4 additions & 7 deletions api/src/main/java/jakarta/enterprise/util/AnnotationLiteral.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
* </p>
*
* <p>
* Reflection operations are using {@link SecurityActions} utility class to support security manager.
* </p>
*
* <p>
* An instance of an annotation type may be obtained by subclassing <code>AnnotationLiteral</code>.
* The subclass must implement the annotation interface to satisfy the {@link Annotation} contract.
* </p>
Expand Down Expand Up @@ -79,7 +75,7 @@ protected AnnotationLiteral() {

private Method[] getMembers() {
if (members == null) {
members = SecurityActions.getDeclaredMethods(annotationType());
members = annotationType().getDeclaredMethods();
if (members.length > 0 && !annotationType().isAssignableFrom(this.getClass())) {
throw new RuntimeException(getClass() + " does not implement the annotation type with members "
+ annotationType().getName());
Expand Down Expand Up @@ -288,8 +284,9 @@ private static Object getMemberValue(Method member, Annotation instance) {

private static Object invoke(Method method, Object instance) {
try {
if (!method.canAccess(instance))
SecurityActions.setAccessible(method);
if (!method.canAccess(instance)) {
method.setAccessible(true);
}
return method.invoke(instance);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException e) {
throw new RuntimeException("Error checking value of member method " + method.getName() + " on "
Expand Down
69 changes: 0 additions & 69 deletions api/src/main/java/jakarta/enterprise/util/SecurityActions.java

This file was deleted.

44 changes: 26 additions & 18 deletions api/src/test/java/org/jboss/cdi/api/test/AnnotationLiteralTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
package org.jboss.cdi.api.test;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertNotNull;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.BeforeDestroyed;
Expand Down Expand Up @@ -67,21 +68,40 @@ public void testNullMemberValueOnToString() {
new FooLiteral(null).hashCode();
}

@SuppressWarnings("serial")
@Test
public void toStringShouldWork() {
assertNotNull(new FooLiteral("foo").toString());
}

@Test
public void annotationTypeShouldWork() {
assertEquals(Foo.class, new FooLiteral("foo").annotationType());
}

@Test
public void equalsShouldWork() {
FooLiteral foo = new FooLiteral("foo");
FooLiteral foo2 = new FooLiteral("foo");
assertEquals(foo, foo2);
}

@Test
public void hashCodeShouldWork() {
assertNotEquals(new FooLiteral("foo").hashCode(), 0);
}

@Test
public void testDefaultLiteral() {
assertEquals(new AnnotationLiteral<Default>() {
}, Default.Literal.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testAnyLiteral() {
assertEquals(new AnnotationLiteral<Any>() {
}, Any.Literal.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testNonbindingLiteral() {
assertEquals(new AnnotationLiteral<Nonbinding>() {
Expand All @@ -90,11 +110,10 @@ public void testNonbindingLiteral() {

@Test
public void testTypedLiteral() {
assertTrue(Typed.Literal.INSTANCE.value().length == 0);
assertTrue(Typed.Literal.of(new Class[] { String.class }).value()[0] == String.class);
assertEquals(Typed.Literal.INSTANCE.value().length, 0);
assertEquals(Typed.Literal.of(new Class[] { String.class }).value()[0], String.class);
}

@SuppressWarnings("serial")
@Test
public void testAlternativeLiteral() {
assertEquals(new AnnotationLiteral<Alternative>() {
Expand All @@ -107,14 +126,12 @@ public void testNamedLiteral() {
assertEquals(NamedLiteral.of("foo").value(), "foo");
}

@SuppressWarnings("serial")
@Test
public void testQualifierLiteral() {
assertEquals(new AnnotationLiteral<Qualifier>() {
}, QualifierLiteral.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testSingletonLiteral() {
assertEquals(new AnnotationLiteral<Singleton>() {
Expand Down Expand Up @@ -144,63 +161,54 @@ public void testBeforeDestroyedLiteral() {
assertEquals(BeforeDestroyed.Literal.APPLICATION.value(), ApplicationScoped.class);
}

@SuppressWarnings("serial")
@Test
public void testApplicationScopedLiteral() {
assertEquals(new AnnotationLiteral<ApplicationScoped>() {
}, ApplicationScoped.Literal.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testRequestScopedLiteral() {
assertEquals(new AnnotationLiteral<RequestScoped>() {
}, RequestScoped.Literal.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testSessionScopedLiteral() {
assertEquals(new AnnotationLiteral<SessionScoped>() {
}, SessionScoped.Literal.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testConversationScopedLiteral() {
assertEquals(new AnnotationLiteral<ConversationScoped>() {
}, ConversationScoped.Literal.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testDependentLiteral() {
assertEquals(new AnnotationLiteral<Dependent>() {
}, Dependent.Literal.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testVetoedLiteral() {
assertEquals(new AnnotationLiteral<Vetoed>() {
}, Vetoed.Literal.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testInjectLiteral() {
assertEquals(new AnnotationLiteral<Inject>() {
}, InjectLiteral.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testSpecializesLiteral() {
assertEquals(new AnnotationLiteral<Specializes>() {
}, Specializes.Literal.INSTANCE);
}

@SuppressWarnings("serial")
@Test
public void testTransientReferenceLiteral() {
assertEquals(new AnnotationLiteral<TransientReference>() {
Expand Down
Loading

0 comments on commit c057683

Please sign in to comment.