From: markt Date: Tue, 23 Sep 2008 16:35:42 +0000 (+0000) Subject: Now containers can have multiple realms, need to make sure we don't get duplicate... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=0a736f7aec306a3e0a9bcfae34e71d05d0b9eb53;p=tomcat7.0 Now containers can have multiple realms, need to make sure we don't get duplicate names for the realms in jmx. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@698227 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/realm/CombinedRealm.java b/java/org/apache/catalina/realm/CombinedRealm.java index 2ac1181a9..23d981143 100644 --- a/java/org/apache/catalina/realm/CombinedRealm.java +++ b/java/org/apache/catalina/realm/CombinedRealm.java @@ -23,6 +23,8 @@ import java.security.cert.X509Certificate; import java.util.LinkedList; import java.util.List; +import javax.management.ObjectName; + import org.apache.catalina.Container; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; @@ -67,6 +69,21 @@ public class CombinedRealm extends RealmBase { } + /** + * Return the set of Realms that this Realm is wrapping + */ + public ObjectName[] getRealms() { + ObjectName[] result = new ObjectName[realms.size()]; + for (Realm realm : realms) { + if (realm instanceof RealmBase) { + result[realms.indexOf(realm)] = + ((RealmBase) realm).getObjectName(); + } + } + return result; + } + + /** * Return the Principal associated with the specified username and * credentials, if there is one; otherwise return null. @@ -180,8 +197,14 @@ public class CombinedRealm extends RealmBase { * @param container The associated Container */ public void setContainer(Container container) { - // Set the container for sub-realms. Mainly so logging works. for(Realm realm : realms) { + // Set the realmPath for JMX naming + if (realm instanceof RealmBase) { + ((RealmBase) realm).setRealmPath( + getRealmPath() + "/realm" + realms.indexOf(realm)); + } + + // Set the container for sub-realms. Mainly so logging works. realm.setContainer(container); } super.setContainer(container); diff --git a/java/org/apache/catalina/realm/RealmBase.java b/java/org/apache/catalina/realm/RealmBase.java index 6556b7df6..4a0a6c770 100644 --- a/java/org/apache/catalina/realm/RealmBase.java +++ b/java/org/apache/catalina/realm/RealmBase.java @@ -1285,6 +1285,7 @@ public abstract class RealmBase protected String domain; protected String host; protected String path; + protected String realmPath = "/realm0"; protected ObjectName oname; protected ObjectName controller; protected MBeanServer mserver; @@ -1309,6 +1310,14 @@ public abstract class RealmBase return type; } + public String getRealmPath() { + return realmPath; + } + + public void setRealmPath(String theRealmPath) { + realmPath = theRealmPath; + } + public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception { oname=name; @@ -1370,7 +1379,8 @@ public abstract class RealmBase // register try { ContainerBase cb=(ContainerBase)container; - oname=new ObjectName(cb.getDomain()+":type=Realm" + cb.getContainerSuffix()); + oname=new ObjectName(cb.getDomain()+":type=Realm" + + getRealmSuffix() + cb.getContainerSuffix()); Registry.getRegistry(null, null).registerComponent(this, oname, null ); if(log.isDebugEnabled()) log.debug("Register Realm "+oname); @@ -1382,6 +1392,11 @@ public abstract class RealmBase } + protected String getRealmSuffix() { + return ",realmPath=" + getRealmPath(); + } + + protected static class AllRolesMode { private String name;