Author: remy.maucherat(a)jboss.com
Date: 2008-08-18 00:04:18 -0400 (Mon, 18 Aug 2008)
New Revision: 743
Modified:
trunk/bin/catalina.sh
trunk/java/org/apache/catalina/core/StandardHost.java
trunk/java/org/apache/catalina/realm/JAASCallbackHandler.java
trunk/java/org/apache/catalina/realm/JAASMemoryLoginModule.java
trunk/java/org/apache/catalina/realm/JAASRealm.java
trunk/webapps/docs/changelog.xml
Log:
- Port 3 Tomcat patches, most notably JAAS realm additions.
Modified: trunk/bin/catalina.sh
===================================================================
--- trunk/bin/catalina.sh 2008-08-13 17:13:12 UTC (rev 742)
+++ trunk/bin/catalina.sh 2008-08-18 04:04:18 UTC (rev 743)
@@ -183,6 +183,9 @@
if [ -r "$CATALINA_BASE"/conf/logging.properties ]; then
JAVA_OPTS="$JAVA_OPTS
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager"
LOGGING_CONFIG="-Djava.util.logging.config.file=$CATALINA_BASE/conf/logging.properties"
+else
+ # Bugzilla 45585
+ LOGGING_CONFIG="-Dnop"
fi
# ----- Execute The Requested Command -----------------------------------------
@@ -225,7 +228,7 @@
if [ "$1" = "-security" ] ; then
echo "Using Security Manager"
shift
- exec "$_RUNJDB" $JAVA_OPTS "$LOGGING_CONFIG" $CATALINA_OPTS \
+ exec "$_RUNJDB" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath
"$CLASSPATH" \
-sourcepath "$CATALINA_HOME"/../../java \
-Djava.security.manager \
@@ -235,7 +238,7 @@
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap "$@" start
else
- exec "$_RUNJDB" $JAVA_OPTS "$LOGGING_CONFIG" $CATALINA_OPTS \
+ exec "$_RUNJDB" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath
"$CLASSPATH" \
-sourcepath "$CATALINA_HOME"/../../java \
-Dcatalina.base="$CATALINA_BASE" \
@@ -251,7 +254,7 @@
if [ "$1" = "-security" ] ; then
echo "Using Security Manager"
shift
- exec "$_RUNJAVA" $JAVA_OPTS "$LOGGING_CONFIG" $CATALINA_OPTS \
+ exec "$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath
"$CLASSPATH" \
-Djava.security.manager \
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
@@ -260,7 +263,7 @@
-Djava.io.tmpdir="$CATALINA_TMPDIR" \
org.apache.catalina.startup.Bootstrap "$@" start
else
- exec "$_RUNJAVA" $JAVA_OPTS "$LOGGING_CONFIG" $CATALINA_OPTS \
+ exec "$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath
"$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
@@ -275,7 +278,7 @@
if [ "$1" = "-security" ] ; then
echo "Using Security Manager"
shift
- "$_RUNJAVA" $JAVA_OPTS "$LOGGING_CONFIG" $CATALINA_OPTS \
+ "$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath
"$CLASSPATH" \
-Djava.security.manager \
-Djava.security.policy=="$CATALINA_BASE"/conf/catalina.policy \
@@ -289,7 +292,7 @@
echo $! > $CATALINA_PID
fi
else
- "$_RUNJAVA" $JAVA_OPTS "$LOGGING_CONFIG" $CATALINA_OPTS \
+ "$_RUNJAVA" "$LOGGING_CONFIG" $JAVA_OPTS $CATALINA_OPTS \
-Djava.endorsed.dirs="$JAVA_ENDORSED_DIRS" -classpath
"$CLASSPATH" \
-Dcatalina.base="$CATALINA_BASE" \
-Dcatalina.home="$CATALINA_HOME" \
@@ -354,4 +357,4 @@
echo " version What version of tomcat are you running?"
exit 1
-fi
\ No newline at end of file
+fi
Modified: trunk/java/org/apache/catalina/core/StandardHost.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardHost.java 2008-08-13 17:13:12 UTC (rev
742)
+++ trunk/java/org/apache/catalina/core/StandardHost.java 2008-08-18 04:04:18 UTC (rev
743)
@@ -706,7 +706,7 @@
} catch (Throwable t) {
log.error(sm.getString
("standardHost.invalidErrorReportValveClass",
- errorReportValveClass));
+ errorReportValveClass), t);
}
}
if(log.isDebugEnabled()) {
Modified: trunk/java/org/apache/catalina/realm/JAASCallbackHandler.java
===================================================================
--- trunk/java/org/apache/catalina/realm/JAASCallbackHandler.java 2008-08-13 17:13:12 UTC
(rev 742)
+++ trunk/java/org/apache/catalina/realm/JAASCallbackHandler.java 2008-08-18 04:04:18 UTC
(rev 743)
@@ -24,11 +24,10 @@
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.TextInputCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import org.apache.catalina.util.StringManager;
-import org.jboss.logging.Logger;
-import org.jboss.logging.Logger;
/**
* <p>Implementation of the JAAS <code>CallbackHandler</code>
interface,
@@ -49,7 +48,6 @@
*/
public class JAASCallbackHandler implements CallbackHandler {
- private static Logger log = Logger.getLogger(JAASCallbackHandler.class);
// ------------------------------------------------------------ Constructor
@@ -78,6 +76,35 @@
}
}
+
+ /**
+ * Construct a callback handler for DIGEST authentication.
+ *
+ * @param realm Our associated JAASRealm instance
+ * @param username Username to be authenticated with
+ * @param password Password to be authenticated with
+ * @param nonce Server generated nonce
+ * @param nc Nonce count
+ * @param cnonce Client generated nonce
+ * @param qop Quality of protection aplied to the message
+ * @param realmName Realm name
+ * @param md5a2 Second MD5 digest used to calculate the digest
+ * MD5(Method + ":" + uri)
+ * @param authMethod The authentication mehtod in use
+ */
+ public JAASCallbackHandler(JAASRealm realm, String username,
+ String password, String nonce, String nc,
+ String cnonce, String qop, String realmName,
+ String md5a2, String authMethod) {
+ this(realm, username, password);
+ this.nonce = nonce;
+ this.nc = nc;
+ this.cnonce = cnonce;
+ this.qop = qop;
+ this.realmName = realmName;
+ this.md5a2 = md5a2;
+ this.authMethod = authMethod;
+ }
// ----------------------------------------------------- Instance Variables
@@ -98,20 +125,55 @@
*/
protected JAASRealm realm = null;
-
/**
* The username to be authenticated with.
*/
protected String username = null;
+ /**
+ * Server generated nonce.
+ */
+ protected String nonce = null;
+
+ /**
+ * Nonce count.
+ */
+ protected String nc = null;
+
+ /**
+ * Client generated nonce.
+ */
+ protected String cnonce = null;
+ /**
+ * Quality of protection aplied to the message.
+ */
+ protected String qop;
+
+ /**
+ * Realm name.
+ */
+ protected String realmName;
+
+ /**
+ * Second MD5 digest.
+ */
+ protected String md5a2;
+
+ /**
+ * The authentication methdod to be used. If null, assume BASIC/FORM.
+ */
+ protected String authMethod;
+
// --------------------------------------------------------- Public Methods
/**
* Retrieve the information requested in the provided
<code>Callbacks</code>.
- * This implementation only recognizes <code>NameCallback</code> and
- * <code>PasswordCallback</code> instances.
+ * This implementation only recognizes {@link NameCallback},
+ * {@link PasswordCallback} and {@link TextInputCallback}.
+ * {@link TextInputCallback} is ued to pass the various additional
+ * parameters required for DIGEST authentication.
*
* @param callbacks The set of <code>Callback</code>s to be processed
*
@@ -137,6 +199,25 @@
}
((PasswordCallback) callbacks[i]).setPassword
(passwordcontents);
+ } else if (callbacks[i] instanceof TextInputCallback) {
+ TextInputCallback cb = ((TextInputCallback) callbacks[i]);
+ if (cb.getPrompt().equals("nonce")) {
+ cb.setText(nonce);
+ } else if (cb.getPrompt().equals("nc")) {
+ cb.setText(nc);
+ } else if (cb.getPrompt().equals("cnonce")) {
+ cb.setText(cnonce);
+ } else if (cb.getPrompt().equals("qop")) {
+ cb.setText(qop);
+ } else if (cb.getPrompt().equals("realmName")) {
+ cb.setText(realmName);
+ } else if (cb.getPrompt().equals("md5a2")) {
+ cb.setText(md5a2);
+ } else if (cb.getPrompt().equals("authMethod")) {
+ cb.setText(authMethod);
+ } else {
+ throw new UnsupportedCallbackException(callbacks[i]);
+ }
} else {
throw new UnsupportedCallbackException(callbacks[i]);
}
Modified: trunk/java/org/apache/catalina/realm/JAASMemoryLoginModule.java
===================================================================
--- trunk/java/org/apache/catalina/realm/JAASMemoryLoginModule.java 2008-08-13 17:13:12
UTC (rev 742)
+++ trunk/java/org/apache/catalina/realm/JAASMemoryLoginModule.java 2008-08-18 04:04:18
UTC (rev 743)
@@ -31,6 +31,7 @@
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.callback.TextInputCallback;
import javax.security.auth.callback.UnsupportedCallbackException;
import javax.security.auth.login.FailedLoginException;
import javax.security.auth.login.LoginException;
@@ -38,13 +39,13 @@
import org.apache.catalina.Context;
import org.apache.catalina.Realm;
+import org.apache.catalina.authenticator.Constants;
import org.apache.catalina.connector.Request;
import org.apache.catalina.deploy.SecurityConstraint;
import org.apache.catalina.util.RequestUtil;
import org.apache.catalina.util.StringManager;
import org.apache.tomcat.util.digester.Digester;
import org.jboss.logging.Logger;
-import org.jboss.logging.Logger;
/**
@@ -194,8 +195,19 @@
return (false);
// Add our Principal to the Subject if needed
- if (!subject.getPrincipals().contains(principal))
+ if (!subject.getPrincipals().contains(principal)) {
subject.getPrincipals().add(principal);
+ // Add the roles as additional sudjucts as per the contract with the
+ // JAASRealm
+ if (principal instanceof GenericPrincipal) {
+ String roles[] = ((GenericPrincipal) principal).getRoles();
+ for (int i = 0; i < roles.length; i++) {
+ subject.getPrincipals().add(
+ new GenericPrincipal(null, roles[i], null));
+ }
+
+ }
+ }
committed = true;
return (true);
@@ -212,7 +224,7 @@
*/
public SecurityConstraint [] findSecurityConstraints(Request request,
Context context) {
- ArrayList results = null;
+ ArrayList<SecurityConstraint> results = null;
// Are there any defined security constraints?
SecurityConstraint constraints[] = context.findConstraints();
if ((constraints == null) || (constraints.length == 0)) {
@@ -235,7 +247,7 @@
constraints[i].included(uri, method));
if (constraints[i].included(uri, method)) {
if(results == null) {
- results = new ArrayList();
+ results = new ArrayList<SecurityConstraint>();
}
results.add(constraints[i]);
}
@@ -298,18 +310,40 @@
// Set up our CallbackHandler requests
if (callbackHandler == null)
throw new LoginException("No CallbackHandler specified");
- Callback callbacks[] = new Callback[2];
+ Callback callbacks[] = new Callback[9];
callbacks[0] = new NameCallback("Username: ");
callbacks[1] = new PasswordCallback("Password: ", false);
+ callbacks[2] = new TextInputCallback("nonce");
+ callbacks[3] = new TextInputCallback("nc");
+ callbacks[4] = new TextInputCallback("cnonce");
+ callbacks[5] = new TextInputCallback("qop");
+ callbacks[6] = new TextInputCallback("realmName");
+ callbacks[7] = new TextInputCallback("md5a2");
+ callbacks[8] = new TextInputCallback("authMethod");
// Interact with the user to retrieve the username and password
String username = null;
String password = null;
+ String nonce = null;
+ String nc = null;
+ String cnonce = null;
+ String qop = null;
+ String realmName = null;
+ String md5a2 = null;
+ String authMethod = null;
+
try {
callbackHandler.handle(callbacks);
username = ((NameCallback) callbacks[0]).getName();
password =
new String(((PasswordCallback) callbacks[1]).getPassword());
+ nonce = ((TextInputCallback) callbacks[2]).getText();
+ nc = ((TextInputCallback) callbacks[3]).getText();
+ cnonce = ((TextInputCallback) callbacks[4]).getText();
+ qop = ((TextInputCallback) callbacks[5]).getText();
+ realmName = ((TextInputCallback) callbacks[6]).getText();
+ md5a2 = ((TextInputCallback) callbacks[7]).getText();
+ authMethod = ((TextInputCallback) callbacks[8]).getText();
} catch (IOException e) {
throw new LoginException(e.toString());
} catch (UnsupportedCallbackException e) {
@@ -317,7 +351,17 @@
}
// Validate the username and password we have received
- principal = super.authenticate(username, password);
+ if (authMethod == null) {
+ // BASIC or FORM
+ principal = super.authenticate(username, password);
+ } else if (authMethod.equals(Constants.DIGEST_METHOD)) {
+ principal = super.authenticate(username, password, nonce, nc,
+ cnonce, qop, realmName, md5a2);
+ } else if (authMethod.equals(Constants.CERT_METHOD)) {
+ principal = super.getPrincipal(username);
+ } else {
+ throw new LoginException("Unknown authentication method");
+ }
log.debug("login " + username + " " + principal);
Modified: trunk/java/org/apache/catalina/realm/JAASRealm.java
===================================================================
--- trunk/java/org/apache/catalina/realm/JAASRealm.java 2008-08-13 17:13:12 UTC (rev 742)
+++ trunk/java/org/apache/catalina/realm/JAASRealm.java 2008-08-18 04:04:18 UTC (rev 743)
@@ -25,6 +25,7 @@
import java.util.List;
import javax.security.auth.Subject;
+import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.AccountExpiredException;
import javax.security.auth.login.CredentialExpiredException;
import javax.security.auth.login.FailedLoginException;
@@ -33,12 +34,13 @@
import org.apache.catalina.Container;
import org.apache.catalina.LifecycleException;
+import org.apache.catalina.authenticator.Constants;
import org.apache.catalina.util.StringManager;
import org.jboss.logging.Logger;
/**
- * <p>Implmentation of <b>Realm</b> that authenticates users via the
<em>Java
+ * <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).</p>
@@ -213,7 +215,7 @@
* @return The value of useContextClassLoader
*/
public boolean isUseContextClassLoader() {
- return useContextClassLoader;
+ return useContextClassLoader;
}
public void setContainer(Container container) {
@@ -309,20 +311,56 @@
/**
- * Return the <code>Principal</code> associated with the specified
username and
- * credentials, if there is one; otherwise return <code>null</code>.
+ * Return the <code>Principal</code> associated with the specified
username
+ * and credentials, if there is one; otherwise return <code>null</code>.
*
- * If there are any errors with the JDBC connection, executing
- * the query or anything we return null (don't authenticate). This
- * event is also logged, and the connection will be closed so that
- * a subsequent request will automatically re-open it.
- *
* @param username Username of the <code>Principal</code> to look up
* @param credentials Password or other credentials to use in
* authenticating this username
*/
public Principal authenticate(String username, String credentials) {
+ return authenticate(username,
+ new JAASCallbackHandler(this, username, credentials));
+ }
+
+ /**
+ * Return the <code>Principal</code> associated with the specified
username
+ * and digest, if there is one; otherwise return <code>null</code>.
+ *
+ * @param username Username of the <code>Principal</code> to look
up
+ * @param clientDigest Digest to use in authenticating this username
+ * @param nonce Server generated nonce
+ * @param nc Nonce count
+ * @param cnonce Client generated nonce
+ * @param qop Quality of protection aplied to the message
+ * @param realmName Realm name
+ * @param md5a2 Second MD5 digest used to calculate the digest
+ * MD5(Method + ":" + uri)
+ * @param authMethod The authentication scheme in use
+ */
+ public Principal authenticate(String username, String clientDigest,
+ String nonce, String nc, String cnonce, String qop,
+ String realmName, String md5a2) {
+ return authenticate(username,
+ new JAASCallbackHandler(this, username, clientDigest, nonce,
+ nc, cnonce, qop, realmName, md5a2,
+ Constants.DIGEST_METHOD));
+ }
+
+
+ // -------------------------------------------------------- Package Methods
+
+
+ // ------------------------------------------------------ Protected Methods
+
+
+ /**
+ * Perform the actual JAAS authentication
+ */
+ protected Principal authenticate(String username,
+ CallbackHandler callbackHandler) {
+
// Establish a LoginContext to use for authentication
try {
LoginContext loginContext = null;
@@ -341,9 +379,7 @@
}
try {
- loginContext = new LoginContext
- (appName, new JAASCallbackHandler(this, username,
- credentials));
+ loginContext = new LoginContext(appName, callbackHandler);
} catch (Throwable e) {
log.error(sm.getString("jaasRealm.unexpectedError"), e);
return (null);
@@ -405,14 +441,7 @@
return null;
}
}
-
- // -------------------------------------------------------- Package Methods
-
-
- // ------------------------------------------------------ Protected Methods
-
-
/**
* Return a short name for this <code>Realm</code> implementation.
*/
@@ -424,7 +453,9 @@
/**
- * Return the password associated with the given principal's user name.
+ * Return the password associated with the given principal's user name. This
+ * always returns null as the JAASRealm has no way of obtaining this
+ * information.
*/
protected String getPassword(String username) {
@@ -438,7 +469,9 @@
*/
protected Principal getPrincipal(String username) {
- return (null);
+ return authenticate(username,
+ new JAASCallbackHandler(this, username, null, null, null, null,
+ null, null, null, Constants.CERT_METHOD));
}
Modified: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2008-08-13 17:13:12 UTC (rev 742)
+++ trunk/webapps/docs/changelog.xml 2008-08-18 04:04:18 UTC (rev 743)
@@ -28,6 +28,20 @@
<add>
New embedded API (startup.Tomcat class). (remm)
</add>
+ <add>
+ <bug>45576</bug>: Add DIGEST support to the JAAS Realm. (markt)
+ </add>
+ <fix>
+ <bug>45585</bug>: Allow Tomcat to start if using
+ <code>$CATALINA_BASE</code> but not JULI. Patch based on a suggestion
by
+ Ian Ward Comfort. (markt)
+ </fix>
+ <fix>
+ The JAAS Realm did not assign roles to authenticated users. (markt)
+ </fix>
+ <add>
+ <bug>41407</bug>: Add support for CLIENT-CERT to the JASS Realm.
(markt)
+ </add>
</changelog>
</subsection>
<subsection name="Coyote">