Skip to content

Commit 1d0e315

Browse files
mattrpavjeanouii
authored andcommitted
[AMQ-9563] Add a SubjectShim to support JAAS API JDK 24+
1 parent e1cc526 commit 1d0e315

File tree

4 files changed

+107
-3
lines changed

4 files changed

+107
-3
lines changed

activemq-broker/pom.xml

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@
242242
</plugins>
243243
</build>
244244
</profile>
245-
<profile>
245+
<profile>
246246
<id>activemq.tests-autoTransport</id>
247247
<activation>
248248
<property>
@@ -263,5 +263,32 @@
263263
</plugins>
264264
</build>
265265
</profile>
266+
<profile>
267+
<id>jdk24-plus</id>
268+
<activation>
269+
<jdk>[24,)</jdk>
270+
</activation>
271+
<build>
272+
<plugins>
273+
<plugin>
274+
<artifactId>maven-compiler-plugin</artifactId>
275+
<executions>
276+
<execution>
277+
<id>java24-compile</id>
278+
<phase>compile</phase>
279+
<goals>
280+
<goal>compile</goal>
281+
</goals>
282+
<configuration>
283+
<release>24</release> <!-- Specific Java version for alternative classes -->
284+
<compileSourceRoots>${project.basedir}/src/main/java24</compileSourceRoots>
285+
<multiReleaseOutput>true</multiReleaseOutput>
286+
</configuration>
287+
</execution>
288+
</executions>
289+
</plugin>
290+
</plugins>
291+
</build>
292+
</profile>
266293
</profiles>
267294
</project>

activemq-broker/src/main/java/org/apache/activemq/broker/jmx/AnnotatedMBean.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,15 @@ public Object invoke(String s, Object[] objects, String[] strings) throws MBeanE
205205
objects = (objects == null) ? new Object[]{} : objects;
206206
JMXAuditLogEntry entry = null;
207207
if (audit != OFF) {
208-
// [AMQ-9563] TODO: JDK 21 use Subject.current() instead
209-
Subject subject = Subject.getSubject(AccessController.getContext());
208+
/**
209+
* [AMQ-9563] JDK JAAS API conversion assistance
210+
*
211+
* Use a shim along with multi-release jar to
212+
* support JDK 17 and JDK 24+ in one build.
213+
*
214+
* see: src/main/java24 folder
215+
*/
216+
Subject subject = SubjectShim.lookupSubject();
210217
String caller = "anonymous";
211218
if (subject != null) {
212219
caller = "";
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.broker.jmx;
18+
19+
import javax.security.auth.Subject;
20+
import java.security.AccessController;
21+
22+
/**
23+
* [AMQ-9563] JDK JAAS API conversion assistance
24+
*
25+
* This instance of the class is for JDK [17, 24)
26+
*
27+
*/
28+
public class SubjectShim {
29+
30+
private SubjectShim() {}
31+
32+
public static Subject lookupSubject() {
33+
return Subject.getSubject(AccessController.getContext());
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.activemq.broker.jmx;
18+
19+
import javax.security.auth.Subject;
20+
import java.security.AccessController;
21+
22+
/**
23+
* [AMQ-9563] JDK JAAS API conversion assistance
24+
*
25+
* This instance of the class is for JDK 24+
26+
*
27+
*/
28+
public class SubjectShim {
29+
30+
private SubjectShim() {}
31+
32+
public static Subject lookupSubject() {
33+
return Subject.current();
34+
}
35+
}

0 commit comments

Comments
 (0)