tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r772132 - in /tomcat/trunk/java/org/apache/catalina/realm: DataSourceRealm.java RealmBase.java UserDatabaseRealm.java
Date Wed, 06 May 2009 10:22:02 GMT
Author: markt
Date: Wed May  6 10:22:02 2009
New Revision: 772132

URL: http://svn.apache.org/viewvc?rev=772132&view=rev
Log:
Start process of removing o.a.c.ServerFactory. Need to do this so:
a) The current o.a.c.startup.Tomcat tests pass
b) We can start to use o.a.c.startup.Tomcat for some new unit tests
This removes ServerFactory from the Realms

Modified:
    tomcat/trunk/java/org/apache/catalina/realm/DataSourceRealm.java
    tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java
    tomcat/trunk/java/org/apache/catalina/realm/UserDatabaseRealm.java

Modified: tomcat/trunk/java/org/apache/catalina/realm/DataSourceRealm.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/realm/DataSourceRealm.java?rev=772132&r1=772131&r2=772132&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/realm/DataSourceRealm.java (original)
+++ tomcat/trunk/java/org/apache/catalina/realm/DataSourceRealm.java Wed May  6 10:22:02 2009
@@ -31,7 +31,6 @@
 
 import org.apache.naming.ContextBindings;
 import org.apache.catalina.LifecycleException;
-import org.apache.catalina.ServerFactory;
 import org.apache.catalina.core.StandardServer;
 import org.apache.catalina.util.StringManager;
 
@@ -396,9 +395,8 @@
                 context = ContextBindings.getClassLoader();
                 context = (Context) context.lookup("comp/env");
             } else {
-                StandardServer server = 
-                    (StandardServer) ServerFactory.getServer();
-                context = server.getGlobalNamingContext();
+                context =
+                    ((StandardServer)getServer()).getGlobalNamingContext();
             }
             DataSource dataSource = (DataSource)context.lookup(dataSourceName);
 	    return dataSource.getConnection();

Modified: tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java?rev=772132&r1=772131&r2=772132&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java Wed May  6 10:22:02 2009
@@ -37,11 +37,15 @@
 
 import org.apache.catalina.Container;
 import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
 import org.apache.catalina.Globals;
+import org.apache.catalina.Host;
 import org.apache.catalina.Lifecycle;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.Realm;
+import org.apache.catalina.Server;
+import org.apache.catalina.Service;
 import org.apache.catalina.connector.Request;
 import org.apache.catalina.connector.Response;
 import org.apache.catalina.core.ContainerBase;
@@ -1219,6 +1223,30 @@
     protected abstract Principal getPrincipal(String username);
 
 
+    /**
+     * Return the Server object that is the ultimate parent for the container
+     * with which this Realm is associated. If the server cannot be found (eg
+     * because the container hierarchy is not complete), <code>null</code> is
+     * returned.
+     */
+    protected Server getServer() {
+        Container c = container;
+        if (c instanceof Context) {
+            c = c.getParent();
+        }
+        if (c instanceof Host) {
+            c = c.getParent();
+        }
+        if (c instanceof Engine) {
+            Service s = ((Engine)c).getService();
+            if (s != null) {
+                return s.getServer();
+            }
+        }
+        return null;
+    }
+
+    
     // --------------------------------------------------------- Static Methods
 
 

Modified: tomcat/trunk/java/org/apache/catalina/realm/UserDatabaseRealm.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/realm/UserDatabaseRealm.java?rev=772132&r1=772131&r2=772132&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/realm/UserDatabaseRealm.java (original)
+++ tomcat/trunk/java/org/apache/catalina/realm/UserDatabaseRealm.java Wed May  6 10:22:02
2009
@@ -29,7 +29,6 @@
 import org.apache.catalina.Group;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.Role;
-import org.apache.catalina.ServerFactory;
 import org.apache.catalina.User;
 import org.apache.catalina.UserDatabase;
 import org.apache.catalina.core.StandardServer;
@@ -248,8 +247,8 @@
         super.start();
 
         try {
-            StandardServer server = (StandardServer) ServerFactory.getServer();
-            Context context = server.getGlobalNamingContext();
+            Context context =
+                ((StandardServer)getServer()).getGlobalNamingContext();
             database = (UserDatabase) context.lookup(resourceName);
         } catch (Throwable e) {
             containerLog.error(sm.getString("userDatabaseRealm.lookup",



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message