Skip to content

Commit 1f3fc83

Browse files
authored
Merge pull request #1164 from arjantijms/build_24
2 parents 2a9275c + ea4392c commit 1f3fc83

File tree

6 files changed

+146
-119
lines changed

6 files changed

+146
-119
lines changed

examples/security-lockdown/runner/pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4+
Copyright (c) 2025 Contributors to Eclipse Foundation.
45
Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
56
67
This program and the accompanying materials are made available under the
@@ -87,7 +88,7 @@
8788
<groupId>org.apache.maven.plugins</groupId>
8889
<artifactId>maven-surefire-plugin</artifactId>
8990
<configuration>
90-
<argLine>-Dlocal.repo=${settings.localRepository} -Dbuild.dir=${project.build.directory} -Djava.security.manager -Djava.security.policy=${project.build.directory}/test-classes/policy.txt @{surefireArgLineExtra}</argLine>
91+
<argLine>-Dlocal.repo=${settings.localRepository} -Dbuild.dir=${project.build.directory} ${activate.securitymanager} -Djava.security.policy=${project.build.directory}/test-classes/policy.txt @{surefireArgLineExtra}</argLine>
9192
<!-- -Djava.security.debug=access,failure,domain -->
9293
</configuration>
9394
</plugin>

examples/security-lockdown/runner/src/test/java/org/glassfish/securitylockdown/test/SecurityLockdownTest.java

+26-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2025 Contributors to Eclipse Foundation.
23
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
34
* Copyright (c) 2020 Payara Services Ltd.
45
*
@@ -17,22 +18,30 @@
1718

1819
package org.glassfish.securitylockdown.test;
1920

20-
import org.junit.Assert;
21+
import com.alice.application.AliceApp;
22+
import com.mallory.application.MalloryApp;
2123

2224
import org.glassfish.hk2.api.MultiException;
25+
import org.junit.Assert;
26+
import org.junit.Before;
2327
import org.junit.Test;
2428
import org.jvnet.hk2.testing.junit.HK2Runner;
2529

26-
import com.alice.application.AliceApp;
27-
import com.mallory.application.MalloryApp;
30+
import static org.junit.Assume.assumeTrue;
2831

2932
/**
30-
*
33+
*
3134
* @author jwells
3235
*
3336
*/
3437
public class SecurityLockdownTest extends HK2Runner {
35-
38+
39+
@Before
40+
public void beforeMethod() {
41+
// Security Manager tests using "AccessController.checkPermission(p);" don't work in JDK24+
42+
assumeTrue(System.getProperty("java.vm.specification.version").compareTo("24") < 0);
43+
}
44+
3645
/**
3746
* Tests that we can do a lookup of AliceApp
3847
*/
@@ -41,7 +50,7 @@ public void testAliceApp() {
4150
AliceApp aa = testLocator.getService(AliceApp.class);
4251
Assert.assertNotNull(aa);
4352
}
44-
53+
4554
/**
4655
* Tests that we can do a lookup of AliceApp
4756
*/
@@ -50,26 +59,26 @@ public void testMalloryApp() {
5059
MalloryApp ma = testLocator.getService(MalloryApp.class);
5160
Assert.assertNotNull(ma);
5261
}
53-
62+
5463
/**
5564
* Tests that we can have Alice perform an operation on Mallory's behalf
5665
*/
5766
@Test
5867
public void testMalloryCanLegallyHaveAliceDoAnOperation() {
5968
MalloryApp ma = testLocator.getService(MalloryApp.class);
6069
Assert.assertNotNull(ma);
61-
70+
6271
ma.doAnApprovedOperation();
6372
}
64-
73+
6574
/**
6675
* Tests that we can have Alice perform an operation on Mallory's behalf
6776
*/
6877
@Test
6978
public void testMalloryCannotGetTheAuditServiceHimself() {
7079
MalloryApp ma = testLocator.getService(MalloryApp.class);
7180
Assert.assertNotNull(ma);
72-
81+
7382
try {
7483
ma.tryToGetTheAuditServiceMyself();
7584
Assert.fail("Mallory should not be able to get the audit service himself");
@@ -78,15 +87,15 @@ public void testMalloryCannotGetTheAuditServiceHimself() {
7887
// Good, should have failed for him!
7988
}
8089
}
81-
90+
8291
/**
8392
* Tests that Mallory cannot advertise a service
8493
*/
8594
@Test
8695
public void testMalloryCannotAdvertiseAService() {
8796
MalloryApp ma = testLocator.getService(MalloryApp.class);
8897
Assert.assertNotNull(ma);
89-
98+
9099
try {
91100
ma.tryToAdvertiseAService();
92101
Assert.fail("Mallory should not be able to advertise a service himself");
@@ -95,15 +104,15 @@ public void testMalloryCannotAdvertiseAService() {
95104
// Good, should have failed for him!
96105
}
97106
}
98-
107+
99108
/**
100109
* Tests that Mallory cannot advertise a service
101110
*/
102111
@Test
103112
public void testMalloryCannotUnAdvertiseAService() {
104113
MalloryApp ma = testLocator.getService(MalloryApp.class);
105114
Assert.assertNotNull(ma);
106-
115+
107116
try {
108117
ma.tryToUnAdvertiseAService();
109118
Assert.fail("Mallory should not be able to unadvertise a service");
@@ -112,21 +121,21 @@ public void testMalloryCannotUnAdvertiseAService() {
112121
// Good, should have failed for him!
113122
}
114123
}
115-
124+
116125
/**
117126
* Tests that Mallory cannot have a service that injects something it cannot
118127
*/
119128
@Test
120129
public void testMalloryCannotInjectAnUnAuthorizedThing() {
121130
MalloryApp ma = testLocator.getService(MalloryApp.class);
122131
Assert.assertNotNull(ma);
123-
132+
124133
try {
125134
ma.tryToInstantiateAServiceWithABadInjectionPoint();
126135
Assert.fail("Mallory should not be able to inject a service it has no rights to");
127136
}
128137
catch (MultiException multi) {
129-
Assert.assertTrue(multi.getMessage(), multi.getMessage().contains("There was no object available in " + SecurityLockdownTest.class.getCanonicalName()
138+
Assert.assertTrue(multi.getMessage(), multi.getMessage().contains("There was no object available in " + SecurityLockdownTest.class.getCanonicalName()
130139
+ " for injection at SystemInjecteeImpl"));
131140
}
132141
}

hk2-api/pom.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4+
Copyright (c) 2025 Contributors to Eclipse Foundation.
45
Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved.
56
Copyright (c) 2019, 2020 Payara Services Ltd.
67
@@ -83,7 +84,7 @@
8384
<groupId>org.apache.maven.plugins</groupId>
8485
<artifactId>maven-surefire-plugin</artifactId>
8586
<configuration>
86-
<argLine>-Dlocal.repo=${settings.localRepository} -Dbuild.dir=${project.build.directory} -Djava.security.manager -Djava.security.policy=${project.build.directory}/test-classes/policy.txt @{surefireArgLineExtra}</argLine>
87+
<argLine>-Dlocal.repo=${settings.localRepository} -Dbuild.dir=${project.build.directory} ${activate.securitymanager} -Djava.security.policy=${project.build.directory}/test-classes/policy.txt @{surefireArgLineExtra}</argLine>
8788
<!-- -Djava.security.debug=access,failure,domain -->
8889
</configuration>
8990
</plugin>

0 commit comments

Comments
 (0)