Skip to content

Commit 1685d74

Browse files
authored
Merge pull request wildfly#17119 from kabir/WFLY-18370-sar-tccl-problem
[WFLY-18370] Remove the workaround sar dependency, and add test
2 parents 66f2144 + f311c4c commit 1685d74

File tree

14 files changed

+336
-20
lines changed

14 files changed

+336
-20
lines changed

ee-feature-pack/galleon-shared/src/main/resources/modules/system/layers/base/org/jboss/as/sar/main/module.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,5 @@
5353
<module name="org.jboss.metadata.common"/>
5454
<module name="org.jboss.as.naming"/>
5555
<module name="java.xml"/>
56-
<!--
57-
The Angus Activation services are required to register a Web Service via a management Bean
58-
-->
59-
<module name="org.eclipse.angus.activation" services="import" optional="true"/>
6056
</dependencies>
6157
</module>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2023, Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags. See the copyright.txt file in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package org.jboss.as.test.integration.sar.context.classloader.app;
23+
24+
import java.io.BufferedOutputStream;
25+
import java.io.FileOutputStream;
26+
import java.nio.charset.StandardCharsets;
27+
import java.nio.file.Files;
28+
import java.nio.file.Path;
29+
import java.nio.file.StandardOpenOption;
30+
import java.security.AccessController;
31+
import java.security.PrivilegedExceptionAction;
32+
import java.util.Properties;
33+
34+
public class MBeanAppClassLoaderTCCLCheckService implements MBeanAppClassLoaderTCCLCheckServiceMBean {
35+
36+
public static final String APP_CL = "application-loader";
37+
public static final String CONSTRUCTOR_TCCL = "constructor-tccl";
38+
public static final String ATTR_WRITE_TCCL = "attr-write-tccl";
39+
public static final String ATTR_READ_TCCL = "attr-read-tccl";
40+
public static final String INVOKE_TCCL = "invoke-tccl";
41+
public static final String CREATE_TCCL = "create-tccl";
42+
public static final String START_TCCL = "start-tccl";
43+
public static final String STOP_TCCL = "stop-tccl";
44+
public static final String DESTROY_TCCL = "destroy-tccl";
45+
46+
private final Properties properties = new Properties();
47+
private volatile Path file;
48+
49+
public MBeanAppClassLoaderTCCLCheckService() {
50+
properties.put(APP_CL, String.valueOf(System.identityHashCode(this.getClass().getClassLoader())));
51+
storeTccl(CONSTRUCTOR_TCCL);
52+
}
53+
54+
@Override
55+
public void create() throws Exception {
56+
storeTccl(CREATE_TCCL);
57+
}
58+
59+
@Override
60+
public void start() throws Exception {
61+
storeTccl(START_TCCL);
62+
}
63+
64+
@Override
65+
public void stop() {
66+
storeTccl(STOP_TCCL);
67+
}
68+
69+
@Override
70+
public void destroy() {
71+
storeTccl(DESTROY_TCCL);
72+
}
73+
74+
@Override
75+
public void setFile(String path) throws Exception {
76+
System.out.println("setFile " + path);
77+
storeTccl(ATTR_WRITE_TCCL);
78+
if (file == null) {
79+
file = Path.of(path);
80+
properties.store(new BufferedOutputStream(new FileOutputStream(file.toFile())), "Test");
81+
} else {
82+
throw new IllegalStateException("Only called once");
83+
}
84+
}
85+
86+
@Override
87+
public String getFile() {
88+
storeTccl(ATTR_READ_TCCL);
89+
return null;
90+
}
91+
92+
@Override
93+
public void method() {
94+
storeTccl(INVOKE_TCCL);
95+
}
96+
97+
private void storeTccl(String id) {
98+
System.out.println("storeTccl " + id);
99+
ClassLoader cl = Thread.currentThread().getContextClassLoader();
100+
String clId = String.valueOf(System.identityHashCode(cl));
101+
if (file == null) {
102+
properties.put(id, clId);
103+
} else {
104+
try {
105+
String s = id + "=" + clId + "\n";
106+
AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
107+
Files.write(file, s.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
108+
return null;
109+
});
110+
} catch (Exception e) {
111+
throw new RuntimeException(e);
112+
}
113+
}
114+
}
115+
116+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2023, Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags. See the copyright.txt file in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/package org.jboss.as.test.integration.sar.context.classloader.app;
22+
23+
public interface MBeanAppClassLoaderTCCLCheckServiceMBean {
24+
// Service lifecycle methods
25+
void create() throws Exception;
26+
void start() throws Exception;
27+
void stop();
28+
void destroy();
29+
// Attribute
30+
void setFile(String path) throws Exception;
31+
String getFile();
32+
// A method
33+
void method();
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
/*
2+
* JBoss, Home of Professional Open Source.
3+
* Copyright 2023, Red Hat, Inc., and individual contributors
4+
* as indicated by the @author tags. See the copyright.txt file in the
5+
* distribution for a full listing of individual contributors.
6+
*
7+
* This is free software; you can redistribute it and/or modify it
8+
* under the terms of the GNU Lesser General Public License as
9+
* published by the Free Software Foundation; either version 2.1 of
10+
* the License, or (at your option) any later version.
11+
*
12+
* This software is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
* Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public
18+
* License along with this software; if not, write to the Free
19+
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
*/
22+
package org.jboss.as.test.integration.sar.context.classloader.app;
23+
24+
import org.jboss.arquillian.container.test.api.Deployment;
25+
import org.jboss.arquillian.container.test.api.RunAsClient;
26+
import org.jboss.arquillian.junit.Arquillian;
27+
import org.jboss.as.arquillian.api.ContainerResource;
28+
import org.jboss.as.arquillian.container.ManagementClient;
29+
import org.jboss.as.controller.PathAddress;
30+
import org.jboss.as.controller.operations.common.Util;
31+
import org.jboss.as.test.integration.common.DefaultConfiguration;
32+
import org.jboss.dmr.ModelNode;
33+
import org.jboss.shrinkwrap.api.Archive;
34+
import org.jboss.shrinkwrap.api.ShrinkWrap;
35+
import org.jboss.shrinkwrap.api.spec.JavaArchive;
36+
import org.junit.After;
37+
import org.junit.Assert;
38+
import org.junit.Test;
39+
import org.junit.runner.RunWith;
40+
import org.xnio.IoUtils;
41+
42+
import javax.management.Attribute;
43+
import javax.management.MBeanServerConnection;
44+
import javax.management.ObjectName;
45+
import javax.management.remote.JMXConnector;
46+
import javax.management.remote.JMXConnectorFactory;
47+
import java.io.BufferedReader;
48+
import java.io.FilePermission;
49+
import java.io.FileReader;
50+
import java.io.IOException;
51+
import java.nio.file.Files;
52+
import java.nio.file.Path;
53+
import java.util.Properties;
54+
55+
import static org.jboss.as.test.shared.PermissionUtils.createPermissionsXmlAsset;
56+
57+
@RunWith(Arquillian.class)
58+
@RunAsClient
59+
public class MBeanAppClassLoaderTCCLTestCase {
60+
61+
@ContainerResource
62+
private ManagementClient managementClient;
63+
64+
private JMXConnector connector;
65+
66+
private static final String SAR_NAME = "test-app-tccl.sar";
67+
68+
static Path outputPath = Path.of("target/app-cl" + System.currentTimeMillis() + "/tccl.properties");
69+
70+
@Deployment
71+
public static Archive createDeployment() {
72+
final JavaArchive sar = ShrinkWrap.create(JavaArchive.class, SAR_NAME);
73+
// add the jboss-service.xml to the META-INF of the .sar
74+
sar.addAsManifestResource(MBeanAppClassLoaderTCCLCheckService.class.getPackage(), "tccl-app-test-service.xml", "jboss-service.xml");
75+
// add some (dummy) classes to the .sar. These classes will then be attempted to be loaded from the MBean class (which resides in a module)
76+
sar.addClasses(MBeanAppClassLoaderTCCLCheckService.class, MBeanAppClassLoaderTCCLCheckServiceMBean.class);
77+
sar.addAsManifestResource(createPermissionsXmlAsset(
78+
new FilePermission(outputPath.toAbsolutePath().toString(), "read"),
79+
new FilePermission(outputPath.toAbsolutePath().toString(), "write")
80+
), "permissions.xml");
81+
82+
return sar;
83+
}
84+
85+
@After
86+
public void closeConnector() {
87+
IoUtils.safeClose(connector);
88+
}
89+
90+
/**
91+
* Tests the MBean was deployed successfully and can be invoked. The fact that the MBean deployed successfully is a sign that the TCCL access from within the MBean code, worked fine
92+
*
93+
* @throws Exception
94+
*/
95+
@Test
96+
public void testTCCLInMBeanInvocation() throws Exception {
97+
final MBeanServerConnection mBeanServerConnection = this.getMBeanServerConnection();
98+
final ObjectName mbeanObjectName = new ObjectName("wildfly:name=tccl-app-test-mbean");
99+
100+
//Path tmp = Path.of("target/app-cl" + System.currentTimeMillis() + "/tccl.properties");
101+
try {
102+
Files.createDirectories(outputPath.getParent());
103+
Files.createFile(outputPath);
104+
mBeanServerConnection.setAttribute(mbeanObjectName, new Attribute("File", outputPath.toAbsolutePath().toString()));
105+
mBeanServerConnection.getAttribute(mbeanObjectName, "File");
106+
mBeanServerConnection.invoke(mbeanObjectName, "method", new Object[0], new String[0]);
107+
108+
// Undeploy so that the stop and destroy methods get called
109+
ModelNode removeOp = Util.createRemoveOperation(PathAddress.pathAddress("deployment", SAR_NAME));
110+
managementClient.getControllerClient().execute(removeOp);
111+
112+
Properties props = new Properties();
113+
props.load(new BufferedReader(new FileReader(outputPath.toFile())));
114+
String appCl = props.getProperty(MBeanAppClassLoaderTCCLCheckService.APP_CL);
115+
Assert.assertNotNull(MBeanAppClassLoaderTCCLCheckService.APP_CL, appCl);
116+
117+
checkProperty(props, MBeanAppClassLoaderTCCLCheckService.CONSTRUCTOR_TCCL, appCl);
118+
checkProperty(props, MBeanAppClassLoaderTCCLCheckService.CREATE_TCCL, appCl);
119+
checkProperty(props, MBeanAppClassLoaderTCCLCheckService.START_TCCL, appCl);
120+
checkProperty(props, MBeanAppClassLoaderTCCLCheckService.ATTR_WRITE_TCCL, appCl);
121+
checkProperty(props, MBeanAppClassLoaderTCCLCheckService.ATTR_READ_TCCL, appCl);
122+
checkProperty(props, MBeanAppClassLoaderTCCLCheckService.INVOKE_TCCL, appCl);
123+
checkProperty(props, MBeanAppClassLoaderTCCLCheckService.STOP_TCCL, appCl);
124+
checkProperty(props, MBeanAppClassLoaderTCCLCheckService.DESTROY_TCCL, appCl);
125+
126+
} finally {
127+
Files.delete(outputPath);
128+
Files.delete(outputPath.getParent());
129+
}
130+
}
131+
132+
private void checkProperty(Properties props, String key, String expected) {
133+
Object value = props.get(key);
134+
Assert.assertNotNull(key, value);
135+
Assert.assertEquals(key, expected, value);
136+
}
137+
138+
private MBeanServerConnection getMBeanServerConnection() throws IOException {
139+
connector = JMXConnectorFactory.connect(managementClient.getRemoteJMXURL(), DefaultConfiguration.credentials());
140+
return connector.getMBeanServerConnection();
141+
}
142+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!--
2+
~ JBoss, Home of Professional Open Source.
3+
~ Copyright 2023, Red Hat, Inc., and individual contributors
4+
~ as indicated by the @author tags. See the copyright.txt file in the
5+
~ distribution for a full listing of individual contributors.
6+
~
7+
~ This is free software; you can redistribute it and/or modify it
8+
~ under the terms of the GNU Lesser General Public License as
9+
~ published by the Free Software Foundation; either version 2.1 of
10+
~ the License, or (at your option) any later version.
11+
~
12+
~ This software is distributed in the hope that it will be useful,
13+
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
~ Lesser General Public License for more details.
16+
~
17+
~ You should have received a copy of the GNU Lesser General Public
18+
~ License along with this software; if not, write to the Free
19+
~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20+
~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21+
-->
22+
<server xmlns="urn:jboss:service:7.0"
23+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
24+
xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
25+
26+
<mbean name="wildfly:name=tccl-app-test-mbean" code="org.jboss.as.test.integration.sar.context.classloader.app.MBeanAppClassLoaderTCCLCheckService">
27+
</mbean>
28+
</server>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
2121
*/
2222

23-
package org.jboss.as.test.integration.sar.context.classloader;
23+
package org.jboss.as.test.integration.sar.context.classloader.module;
2424

2525
/**
2626
* @author: Jaikiran Pai
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
2121
*/
2222

23-
package org.jboss.as.test.integration.sar.context.classloader;
23+
package org.jboss.as.test.integration.sar.context.classloader.module;
2424

2525
/**
2626
* @author: Jaikiran Pai
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
2121
*/
2222

23-
package org.jboss.as.test.integration.sar.context.classloader;
23+
package org.jboss.as.test.integration.sar.context.classloader.module;
2424

2525
/**
2626
* @author: Jaikiran Pai
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
2121
*/
2222

23-
package org.jboss.as.test.integration.sar.context.classloader;
23+
package org.jboss.as.test.integration.sar.context.classloader.module;
2424

2525
/**
2626
* @author: Jaikiran Pai

0 commit comments

Comments
 (0)