Now containers can have multiple realms, need to make sure we don't get duplicate...
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 23 Sep 2008 16:35:42 +0000 (16:35 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 23 Sep 2008 16:35:42 +0000 (16:35 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@698227 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/realm/CombinedRealm.java
java/org/apache/catalina/realm/RealmBase.java

index 2ac1181..23d9811 100644 (file)
@@ -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 <code>null</code>.
@@ -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);
index 6556b7d..4a0a6c7 100644 (file)
@@ -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;