This is an automated email from the ASF dual-hosted git repository.
remm pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/9.0.x by this push:
new ebbd1875f5 Add configuration source for configFile attribute
ebbd1875f5 is described below
commit ebbd1875f513066f4dec307f4e6a498e2284d109
Author: remm <[email protected]>
AuthorDate: Mon Jun 24 11:32:39 2024 +0200
Add configuration source for configFile attribute
Much easier to use for testing.
---
java/org/apache/catalina/realm/JAASRealm.java | 24 ++++++++++++++++------
.../apache/catalina/realm/LocalStrings.properties | 1 +
webapps/docs/changelog.xml | 8 ++++++++
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/java/org/apache/catalina/realm/JAASRealm.java
b/java/org/apache/catalina/realm/JAASRealm.java
index b815ab14a7..91b5d77649 100644
--- a/java/org/apache/catalina/realm/JAASRealm.java
+++ b/java/org/apache/catalina/realm/JAASRealm.java
@@ -16,6 +16,7 @@
*/
package org.apache.catalina.realm;
+import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.net.URI;
@@ -40,12 +41,13 @@ import org.apache.catalina.LifecycleException;
import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.tomcat.util.ExceptionUtils;
+import org.apache.tomcat.util.file.ConfigFileLoader;
+import org.apache.tomcat.util.file.ConfigurationSource;
/**
* <p>
* Implementation of <b>Realm</b> that authenticates users via the <em>Java
Authentication and Authorization
- * Service</em> (JAAS). JAAS support requires either JDK 1.4 (which includes
it as part of the standard platform) or JDK
- * 1.3 (with the plug-in <code>jaas.jar</code> file).
+ * Service</em> (JAAS).
* </p>
* <p>
* The value configured for the <code>appName</code> property is passed to the
@@ -593,15 +595,25 @@ public class JAASRealm extends RealmBase {
jaasConfigurationLoaded = true;
return null;
}
- URL resource =
Thread.currentThread().getContextClassLoader().getResource(configFile);
- URI uri = resource.toURI();
@SuppressWarnings("unchecked")
Class<Configuration> sunConfigFile =
(Class<Configuration>)
Class.forName("com.sun.security.auth.login.ConfigFile");
Constructor<Configuration> constructor =
sunConfigFile.getConstructor(URI.class);
- Configuration config = constructor.newInstance(uri);
+ URL resource =
Thread.currentThread().getContextClassLoader().getResource(configFile);
+ Configuration config = null;
+ if (resource == null) {
+ try (ConfigurationSource.Resource configFileResource =
ConfigFileLoader.getSource().getResource(configFile)) {
+ config =
constructor.newInstance(configFileResource.getURI());
+ this.jaasConfigurationLoaded = true;
+ } catch (IOException ioe) {
+ throw new
RuntimeException(sm.getString("jaasRealm.configFileNotFound", configFile));
+ }
+ } else {
+ URI uri = resource.toURI();
+ config = constructor.newInstance(uri);
+ this.jaasConfigurationLoaded = true;
+ }
this.jaasConfiguration = config;
- this.jaasConfigurationLoaded = true;
return this.jaasConfiguration;
}
} catch (InvocationTargetException ex) {
diff --git a/java/org/apache/catalina/realm/LocalStrings.properties
b/java/org/apache/catalina/realm/LocalStrings.properties
index 6ee36b31f5..bf6632173f 100644
--- a/java/org/apache/catalina/realm/LocalStrings.properties
+++ b/java/org/apache/catalina/realm/LocalStrings.properties
@@ -52,6 +52,7 @@ jaasRealm.authenticateSuccess=Username [{0}] successfully
authenticated as Princ
jaasRealm.beginLogin=JAASRealm login requested for username [{0}] using
LoginContext for application [{1}]
jaasRealm.checkPrincipal=Checking Principal [{0}] [{1}]
jaasRealm.classNotFound=Class [{0}] was not found
+jaasRealm.configFileNotFound=JAAS configuration resource [{0}] was not found
jaasRealm.credentialExpired=Username [{0}] NOT authenticated due to expired
credential
jaasRealm.failedLogin=Username [{0}] NOT authenticated due to failed login
jaasRealm.loginContextCreated=JAAS LoginContext created for username [{0}]
diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
index 328349c6ca..86cc5c27fd 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 9.0.91 (remm)" rtext="in development">
+ <subsection name="Catalina">
+ <changelog>
+ <fix>
+ Allow <code>JAASRealm</code> to use the configuration source to load a
+ configured <code>configFile</code>, for easier use with testing. (remm)
+ </fix>
+ </changelog>
+ </subsection>
<subsection name="Coyote">
<changelog>
<fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]