This is an automated email from the ASF dual-hosted git repository.

remm pushed a commit to branch 10.1.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/10.1.x by this push:
     new 65f9f9ea4d Check SSO configuration on start
65f9f9ea4d is described below

commit 65f9f9ea4df33d216c9c508591f0917c4ba1febc
Author: remm <[email protected]>
AuthorDate: Mon Oct 6 13:54:51 2025 +0200

    Check SSO configuration on start
    
    Log a warning if the SSO does not comply with the documentation.
---
 .../catalina/authenticator/LocalStrings.properties |  2 ++
 .../catalina/authenticator/SingleSignOn.java       | 38 +++++++++++++++++++---
 webapps/docs/changelog.xml                         |  8 +++++
 3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/java/org/apache/catalina/authenticator/LocalStrings.properties 
b/java/org/apache/catalina/authenticator/LocalStrings.properties
index b9c62d8502..126507b5db 100644
--- a/java/org/apache/catalina/authenticator/LocalStrings.properties
+++ b/java/org/apache/catalina/authenticator/LocalStrings.properties
@@ -79,6 +79,8 @@ singleSignOn.debug.removeSession=SSO removing application 
session [{0}] from SSO
 singleSignOn.debug.sessionLogout=SSO processing a log out for SSO session 
[{0}] and application session [{1}]
 singleSignOn.debug.sessionTimeout=SSO processing a time out for SSO session 
[{0}] and application session [{1}]
 singleSignOn.debug.update=SSO updating SSO session [{0}] to authentication 
type [{1}]
+singleSignOn.duplicateRealm=SSO found a realm defined on context [{0}], this 
will conflict with principals defined in the main realm
+singleSignOn.noRealm=This SSO [{0}] has no realm associated with it
 singleSignOn.sessionExpire.contextNotFound=SSO unable to expire session [{0}] 
because the Context could not be found
 singleSignOn.sessionExpire.engineNull=SSO unable to expire session [{0}] 
because the Engine was null
 singleSignOn.sessionExpire.hostNotFound=SSO unable to expire session [{0}] 
because the Host could not be found
diff --git a/java/org/apache/catalina/authenticator/SingleSignOn.java 
b/java/org/apache/catalina/authenticator/SingleSignOn.java
index c5fe8d853b..1d31889965 100644
--- a/java/org/apache/catalina/authenticator/SingleSignOn.java
+++ b/java/org/apache/catalina/authenticator/SingleSignOn.java
@@ -28,6 +28,7 @@ import jakarta.servlet.http.Cookie;
 import org.apache.catalina.Container;
 import org.apache.catalina.Context;
 import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.Manager;
 import org.apache.catalina.Realm;
@@ -569,12 +570,39 @@ public class SingleSignOn extends ValveBase {
 
     @Override
     protected void startInternal() throws LifecycleException {
-        Container c = getContainer();
-        while (c != null && !(c instanceof Engine)) {
-            c = c.getParent();
+        Container container = getContainer();
+        while (container != null && !(container instanceof Engine)) {
+            container = container.getParent();
         }
-        if (c != null) {
-            engine = (Engine) c;
+        if (container != null) {
+            engine = (Engine) container;
+        }
+        // Starting with the associated container, verify it has a realm 
associated,
+        // and that no child container returns a different realm
+        container = getContainer();
+        Realm containerRealm = container.getRealm();
+        if (containerRealm == null) {
+            containerLog.warn(sm.getString("singleSignOn.noRealm", 
container.getName()));
+        } else {
+            if (container instanceof Engine) {
+                for (Container host : engine.findChildren()) {
+                    if (host.getRealm() != containerRealm) {
+                        
containerLog.warn(sm.getString("singleSignOn.duplicateRealm", host.getName()));
+                    } else {
+                        for (Container context : host.findChildren()) {
+                            if (context.getRealm() != containerRealm) {
+                                
containerLog.warn(sm.getString("singleSignOn.duplicateRealm", 
context.getName()));
+                            }
+                        }
+                    }
+                }
+            } else if (container instanceof Host) {
+                for (Container context : container.findChildren()) {
+                    if (context.getRealm() != containerRealm) {
+                        
containerLog.warn(sm.getString("singleSignOn.duplicateRealm", 
context.getName()));
+                    }
+                }
+            }
         }
         super.startInternal();
     }
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 6d7e54baf9..ca572b4ffa 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -105,6 +105,14 @@
   issues do not "pop up" wrt. others).
 -->
 <section name="Tomcat 10.1.48 (schultz)" rtext="in development">
+  <subsection name="Catalina">
+    <changelog>
+      <fix>
+        Log warnings when the SSO configuration does not comply with the
+        documentation. (remm)
+      </fix>
+    </changelog>
+  </subsection>
 </section>
 <section name="Tomcat 10.1.47 (schultz)" rtext="release in progress">
   <subsection name="Catalina">


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to