This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 11.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/11.0.x by this push:
new 9c916c9790 Ensure ServerAuthModule.initialize() is called with simple
registration
9c916c9790 is described below
commit 9c916c9790ed92681cb2bc2495ef37ead66218b1
Author: Mark Thomas <[email protected]>
AuthorDate: Tue Sep 17 20:11:08 2024 +0100
Ensure ServerAuthModule.initialize() is called with simple registration
---
.../jaspic/AuthConfigFactoryImpl.java | 47 +++++++++++++++++-----
webapps/docs/changelog.xml | 9 +++++
2 files changed, 46 insertions(+), 10 deletions(-)
diff --git
a/java/org/apache/catalina/authenticator/jaspic/AuthConfigFactoryImpl.java
b/java/org/apache/catalina/authenticator/jaspic/AuthConfigFactoryImpl.java
index 9da0d05551..73d95329f6 100644
--- a/java/org/apache/catalina/authenticator/jaspic/AuthConfigFactoryImpl.java
+++ b/java/org/apache/catalina/authenticator/jaspic/AuthConfigFactoryImpl.java
@@ -328,9 +328,7 @@ public class AuthConfigFactoryImpl extends
AuthConfigFactory {
ServletContext servletContext = (ServletContext) context;
String appContext = servletContext.getVirtualServerName() + " " +
servletContext.getContextPath();
- ServerAuthContext serverAuthContext = new
SingleModuleServerAuthContext(serverAuthModule);
- ServerAuthConfig serverAuthConfig = new
SingleContextServerAuthConfig(serverAuthContext, appContext);
- AuthConfigProvider authConfigProvider = new
SingleConfigAuthConfigProvider(serverAuthConfig);
+ AuthConfigProvider authConfigProvider = new
SingleConfigAuthConfigProvider(serverAuthModule, appContext);
return registerConfigProvider(authConfigProvider,
SERVLET_LAYER_ID, appContext, "");
}
@@ -576,12 +574,16 @@ public class AuthConfigFactoryImpl extends
AuthConfigFactory {
private static class SingleContextServerAuthConfig implements
ServerAuthConfig {
- private final ServerAuthContext context;
+ private final ServerAuthModule serverAuthModule;
private final String appContext;
+ private final CallbackHandler handler;
+ private final Object serverAuthContextLock = new Object();
+ private volatile ServerAuthContext serverAuthContext;
- SingleContextServerAuthConfig(ServerAuthContext context, String
appContext) {
- this.context = context;
+ SingleContextServerAuthConfig(ServerAuthModule serverAuthModule,
String appContext, CallbackHandler handler) {
+ this.serverAuthModule = serverAuthModule;
this.appContext = appContext;
+ this.handler = handler;
}
@Override
@@ -612,17 +614,32 @@ public class AuthConfigFactoryImpl extends
AuthConfigFactory {
@Override
public ServerAuthContext getAuthContext(String authContextID, Subject
serviceSubject,
Map<String,Object> properties) throws AuthException {
- return context;
+ /*
+ * Lazy initialization since we need to pass in the properties
which aren't available until this point.
+ */
+ if (serverAuthContext == null) {
+ synchronized (serverAuthContextLock) {
+ if (serverAuthContext == null) {
+ serverAuthContext = new
SingleModuleServerAuthContext(serverAuthModule);
+ serverAuthModule.initialize(null, null, handler,
properties);
+ }
+ }
+ }
+ return serverAuthContext;
}
}
private static class SingleConfigAuthConfigProvider implements
AuthConfigProvider {
- private final ServerAuthConfig serverAuthConfig;
+ private final ServerAuthModule serverAuthModule;
+ private final String appContext;
+ private final Object serverAuthConfigLock = new Object();
+ private volatile ServerAuthConfig serverAuthConfig;
- SingleConfigAuthConfigProvider(ServerAuthConfig serverAuthConfig) {
- this.serverAuthConfig = serverAuthConfig;
+ SingleConfigAuthConfigProvider(ServerAuthModule serverAuthModule,
String appContext) {
+ this.serverAuthModule = serverAuthModule;
+ this.appContext = appContext;
}
@Override
@@ -635,6 +652,16 @@ public class AuthConfigFactoryImpl extends
AuthConfigFactory {
@Override
public ServerAuthConfig getServerAuthConfig(String layer, String
appContext, CallbackHandler handler)
throws AuthException {
+ /*
+ * Lazy initialization since we need to pass in the
CallbackHandler which isn't available until this point.
+ */
+ if (serverAuthConfig == null) {
+ synchronized (serverAuthConfigLock) {
+ if (serverAuthConfig == null) {
+ serverAuthConfig = new
SingleContextServerAuthConfig(serverAuthModule, this.appContext, handler);
+ }
+ }
+ }
return serverAuthConfig;
}
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 60291eeb5e..a295d756e9 100644
--- a/webapps/docs/changelog.xml
+++ b/webapps/docs/changelog.xml
@@ -105,6 +105,15 @@
issues do not "pop up" wrt. others).
-->
<section name="Tomcat 11.0.0 (markt)" rtext="in development">
+ <subsection name="Catalina">
+ <changelog>
+ <fix>
+ Ensure that <code>ServerAuthModule.initialize()</code> is called when
+ the module is configured via <code>registerServerAuthModule()</code>.
+ (markt)
+ </fix>
+ </changelog>
+ </subsection>
</section>
<section name="Tomcat 11.0.0-M26 (markt)" rtext="release in progress">
<subsection name="Coyote">
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]