Skip to content

Commit 35054f8

Browse files
committed
Merge branch 'master' into 9.0
2 parents 4902f8c + 5cd2ae3 commit 35054f8

3 files changed

Lines changed: 118 additions & 3 deletions

File tree

appserver/ejb/ejb-container/pom.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright (c) 2022 Contributors to the Eclipse Foundation. All rights reserved.
4+
Copyright (c) 2022, 2026 Contributors to the Eclipse Foundation. All rights reserved.
55
Copyright (c) 1997, 2022 Oracle and/or its affiliates. All rights reserved.
66
77
This program and the accompanying materials are made available under the
@@ -218,6 +218,10 @@
218218
<groupId>org.junit.jupiter</groupId>
219219
<artifactId>junit-jupiter-engine</artifactId>
220220
</dependency>
221+
<dependency>
222+
<groupId>org.junit.jupiter</groupId>
223+
<artifactId>junit-jupiter-params</artifactId>
224+
</dependency>
221225
<dependency>
222226
<groupId>org.hamcrest</groupId>
223227
<artifactId>hamcrest</artifactId>

appserver/ejb/ejb-container/src/main/java/org/glassfish/ejb/deployment/node/EjbNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2024 Contributors to the Eclipse Foundation.
2+
* Copyright (c) 2022, 2026 Contributors to the Eclipse Foundation.
33
* Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved.
44
*
55
* This program and the accompanying materials are made available under the
@@ -181,7 +181,7 @@ protected void writeCommonHeaderEjbDescriptor(Node ejbNode, EjbDescriptor descri
181181
* @param descriptor the EJB descriptor the security information to be retrieved
182182
*/
183183
protected void writeSecurityIdentityDescriptor(Node parent, EjbDescriptor descriptor) {
184-
if (descriptor.getUsesCallerIdentity() == null && descriptor.getRunAsIdentity() == null) {
184+
if (!Boolean.TRUE.equals(descriptor.getUsesCallerIdentity()) && descriptor.getRunAsIdentity() == null) {
185185
return;
186186
}
187187
SecurityIdentityNode.writeSecureIdentity(parent, SECURITY_IDENTITY, descriptor);
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* Copyright (c) 2026 Contributors to the Eclipse Foundation.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0, which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* This Source Code may also be made available under the following Secondary
9+
* Licenses when the conditions for such availability set forth in the
10+
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License,
11+
* version 2 with the GNU Classpath Exception, which is available at
12+
* https://www.gnu.org/software/classpath/license.html.
13+
*
14+
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
15+
*/
16+
17+
package org.glassfish.ejb.deployment.node;
18+
19+
import com.sun.enterprise.deployment.RunAsIdentityDescriptor;
20+
21+
import java.util.stream.Stream;
22+
23+
import javax.xml.parsers.DocumentBuilderFactory;
24+
25+
import org.glassfish.ejb.deployment.EjbTagNames;
26+
import org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor;
27+
import org.glassfish.ejb.deployment.descriptor.EjbDescriptor;
28+
import org.glassfish.hk2.api.ServiceLocator;
29+
import org.glassfish.hk2.api.ServiceLocatorFactory;
30+
import org.glassfish.internal.api.Globals;
31+
import org.junit.jupiter.api.AfterAll;
32+
import org.junit.jupiter.api.Assertions;
33+
import org.junit.jupiter.api.BeforeAll;
34+
import org.junit.jupiter.params.ParameterizedTest;
35+
import org.junit.jupiter.params.provider.Arguments;
36+
import org.junit.jupiter.params.provider.MethodSource;
37+
import org.w3c.dom.Element;
38+
39+
40+
public class EjbNodeTest {
41+
42+
private static final String TEST_LOCATOR_NAME = EjbNodeTest.class.getName();
43+
private static ServiceLocator previousHabitat;
44+
45+
@BeforeAll
46+
static void setupServiceLocator() {
47+
previousHabitat = Globals.getDefaultHabitat();
48+
Globals.setDefaultHabitat(ServiceLocatorFactory.getInstance().create(TEST_LOCATOR_NAME));
49+
}
50+
51+
@AfterAll
52+
static void teardownServiceLocator() {
53+
Globals.setDefaultHabitat(previousHabitat);
54+
ServiceLocatorFactory.getInstance().destroy(TEST_LOCATOR_NAME);
55+
}
56+
57+
/** Tests all meaningful branches of {@link EjbNode#writeSecurityIdentityDescriptor}. */
58+
@ParameterizedTest
59+
@MethodSource("securityIdentityWriteScenarios")
60+
void writeSecurityIdentityDescriptor(Boolean usesCallerIdentity, boolean withRunAs, int expectedSecurityIdentityCount) throws Exception {
61+
DummyEjbDescriptor descriptor = new DummyEjbDescriptor();
62+
if (withRunAs) {
63+
// setRunAsIdentity requires false first (EjbBeanDescriptor constraint).
64+
descriptor.setUsesCallerIdentity(false);
65+
descriptor.setRunAsIdentity(new RunAsIdentityDescriptor("test-role"));
66+
}
67+
if (usesCallerIdentity != null) {
68+
descriptor.setUsesCallerIdentity(usesCallerIdentity);
69+
}
70+
71+
Element parent = createParentElement();
72+
TestEjbNode ejbNode = new TestEjbNode(descriptor);
73+
ejbNode.writeSecurityIdentityDescriptor(parent, descriptor);
74+
75+
Assertions.assertEquals(expectedSecurityIdentityCount, parent.getElementsByTagName(EjbTagNames.SECURITY_IDENTITY).getLength());
76+
}
77+
78+
private static Stream<Arguments> securityIdentityWriteScenarios() {
79+
return Stream.of(
80+
Arguments.of(null, false, 0),
81+
Arguments.of(null, true, 1),
82+
Arguments.of(false, false, 0),
83+
Arguments.of(false, true, 1),
84+
Arguments.of(true, false, 1),
85+
Arguments.of(true, true, 1)
86+
);
87+
}
88+
89+
private static Element createParentElement() throws Exception {
90+
var document = DocumentBuilderFactory.newDefaultInstance().newDocumentBuilder().newDocument();
91+
Element parent = document.createElement("ejb");
92+
document.appendChild(parent);
93+
return parent;
94+
}
95+
96+
/** Minimal concrete subclass of {@link EjbNode} for testing protected methods. */
97+
private static class TestEjbNode extends EjbNode<EjbDescriptor> {
98+
99+
private final EjbDescriptor descriptor;
100+
101+
TestEjbNode(EjbDescriptor descriptor) {
102+
this.descriptor = descriptor;
103+
}
104+
105+
@Override
106+
public EjbDescriptor getEjbDescriptor() {
107+
return descriptor;
108+
}
109+
}
110+
111+
}

0 commit comments

Comments
 (0)