From f32783d487df05b84d587f41c404915fa6c9967a Mon Sep 17 00:00:00 2001 From: tjquinn Date: Wed, 2 May 2012 19:28:35 +0000 Subject: [PATCH] Fix for 18592 MBeans created for config beans use the name as declared in the config bean for part of the MBean name. For secure-admin-principal elements, the name is the DN which contains characters that are illegal in MBean names. The constructed ObjectName includes name=(name-from-config-bean) These changes quote the name-from-config-bean if it contains an illegal character. git-svn-id: https://svn.java.net/svn/glassfish~svn/trunk/main@53780 6f3ba3e3-413c-0410-a8aa-90bee3ab43b5 --- .../amx/impl/config/AMXConfigLoader.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/nucleus/common/amx-core/src/main/java/org/glassfish/admin/amx/impl/config/AMXConfigLoader.java b/nucleus/common/amx-core/src/main/java/org/glassfish/admin/amx/impl/config/AMXConfigLoader.java index 4c1608f06fc..2c0d1fcfd05 100644 --- a/nucleus/common/amx-core/src/main/java/org/glassfish/admin/amx/impl/config/AMXConfigLoader.java +++ b/nucleus/common/amx-core/src/main/java/org/glassfish/admin/amx/impl/config/AMXConfigLoader.java @@ -71,6 +71,7 @@ import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Level; import java.util.logging.Logger; +import java.util.regex.Pattern; /** Responsible for loading ConfigBeanProxy MBeans (com.sun.enterprise.config.serverbeans.*) @@ -90,6 +91,13 @@ private static void debug(final String s) { private final ConfigBeanRegistry mRegistry = ConfigBeanRegistry.getInstance(); private final MBeanServer mServer; + /** + * Detects illegal characters in MBean name values. (Used instead of + * individual character searches for efficiency) + */ + private static final Pattern ILLEGAL_JMX_NAME_PATTERN = Pattern.compile(".*[=:" + + Pattern.quote("\"") + Pattern.quote("*") + Pattern.quote("?") + "].*"); + public AMXConfigLoader( final MBeanServer mbeanServer, final PendingConfigBeans pending, @@ -599,10 +607,30 @@ private ObjectName buildObjectName(final ConfigBean cb) { //debug( "Type/name for " + cb.getProxyType().getName() + " = " + type + " = " + name ); - final ObjectName objectName = ObjectNameBuilder.buildChildObjectName(mServer, parentObjectName, type, name); + final ObjectName objectName = ObjectNameBuilder.buildChildObjectName(mServer, parentObjectName, type, quoteIfNeeded(name)); //debug( "ObjectName for " + cb.getProxyType().getName() + " = " + objectName + " of parent " + parentObjectName ); return objectName; } + + /** + * Quotes the name string if it contains any characters that are illegal + * in MBean names. + * + * @param name the string to examine + * @return quoted string if it contains illegal characters; the string otherwise + */ + private static String quoteIfNeeded(final String name) { + /* + * JMX names cannot include = or , or : or * or ? unless they are part of + * the value and they are quoted. + */ + + if (name != null && ILLEGAL_JMX_NAME_PATTERN.matcher(name).matches()) { + return "\"" + name + "\""; + } else { + return name; + } + } }