Skip to content

Commit

Permalink
Fix for 18592
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tjquinn committed May 2, 2012
1 parent b955533 commit f32783d
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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.*)
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
}
}

0 comments on commit f32783d

Please sign in to comment.