Skip to content

Commit

Permalink
[WFCORE-6470] Make the TcclMBeanServer.(un)registerMBean() methods us…
Browse files Browse the repository at this point in the history
…e the app CL as the TCCL
  • Loading branch information
kabir committed Aug 17, 2023
1 parent d0017b4 commit 3dd4cd8
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions jmx/src/main/java/org/jboss/as/jmx/PluggableMBeanServerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,16 @@ public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {

public ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException {
return delegate.registerMBean(object, name);
if (object == null) {
// The MBeanServer.registerMBean() javadoc indicates this is the error to throw if null
throw new RuntimeOperationsException(new IllegalArgumentException());
}
ClassLoader old = pushClassLoaderFromObject(object);
try {
return delegate.registerMBean(object, name);
} finally {
resetClassLoader(old);
}
}

public void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback)
Expand Down Expand Up @@ -1592,7 +1601,12 @@ public AttributeList setAttributes(ObjectName name, AttributeList attributes) th
}

public void unregisterMBean(ObjectName name) throws InstanceNotFoundException, MBeanRegistrationException {
delegate.unregisterMBean(name);
ClassLoader old = pushClassLoader(name);
try {
delegate.unregisterMBean(name);
} finally {
resetClassLoader(old);
}
}

private ClassLoader pushClassLoader(final ObjectName name) throws InstanceNotFoundException {
Expand Down Expand Up @@ -1626,6 +1640,7 @@ private ClassLoader pushClassLoaderByName(final ObjectName loaderName) throws In
public ClassLoader run() throws Exception {
return delegate.getClassLoader(loaderName);
}

});
} catch (PrivilegedActionException e) {
try {
Expand All @@ -1643,6 +1658,16 @@ public ClassLoader run() throws Exception {
return WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(mbeanCl);
}

private ClassLoader pushClassLoaderFromObject(final Object o) {
ClassLoader cl = doPrivileged(new PrivilegedAction<ClassLoader>() {
@Override
public ClassLoader run() {
return o.getClass().getClassLoader();
}
});
return WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
}

private void resetClassLoader(ClassLoader cl) {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(cl);
}
Expand Down

0 comments on commit 3dd4cd8

Please sign in to comment.