Author: markt Date: Fri Dec 28 13:31:46 2007 New Revision: 607339 URL: http://svn.apache.org/viewvc?rev=607339&view=rev Log: Fix bug 44084. JASSRealm was broken for application provided Principals. Patch provided by Noah Levitt.
Modified: tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/JAASRealm.java tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Modified: tomcat/tc6.0.x/trunk/STATUS.txt URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=607339&r1=607338&r2=607339&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Fri Dec 28 13:31:46 2007 @@ -42,12 +42,6 @@ +1: markt,funkman, pero, yoavs -1: -* Fix http://issues.apache.org/bugzilla/show_bug.cgi?id=44084 - JASSRealm is broken for application provided Principals - http://svn.apache.org/viewvc?rev=606621&view=rev - +1: markt,funkman, yoavs - -1: - * Fix http://issues.apache.org/bugzilla/show_bug.cgi?id=42503 ServletContext.getResourceAsStream returns stale data http://svn.apache.org/viewvc?rev=606994&view=rev Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/JAASRealm.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/JAASRealm.java?rev=607339&r1=607338&r2=607339&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/JAASRealm.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/JAASRealm.java Fri Dec 28 13:31:46 2007 @@ -241,21 +241,19 @@ } /** - * Sets the list of comma-delimited classes that represent - * roles. The classes in the list must implement <code>java.security.Principal</code>. - * When this accessor is called (for example, by a <code>Digester</code> - * instance parsing the - * configuration file), it will parse the class names and store the resulting - * string(s) into the <code>ArrayList</code> field </code>roleClasses</code>. + * Sets the list of comma-delimited classes that represent roles. The + * classes in the list must implement <code>java.security.Principal</code>. + * The supplied list of classes will be parsed when [EMAIL PROTECTED] #start()} is + * called. */ public void setRoleClassNames(String roleClassNames) { this.roleClassNames = roleClassNames; - parseClassNames(roleClassNames, roleClasses); } /** * Parses a comma-delimited list of class names, and store the class names - * in the provided List. Each class must implement <codejava.security.Principal</code>. + * in the provided List. Each class must implement + * <code>java.security.Principal</code>. * * @param classNamesString a comma-delimited list of fully qualified class names. * @param classNamesList the list in which the class names will be stored. @@ -264,12 +262,17 @@ protected void parseClassNames(String classNamesString, List<String> classNamesList) { classNamesList.clear(); if (classNamesString == null) return; - + + ClassLoader loader = this.getClass().getClassLoader(); + if (isUseContextClassLoader()) + loader = Thread.currentThread().getContextClassLoader(); + String[] classNames = classNamesString.split("[ ]*,[ ]*"); for (int i=0; i<classNames.length; i++) { if (classNames[i].length()==0) continue; try { - Class principalClass = Class.forName(classNames[i]); + Class principalClass = Class.forName(classNames[i], false, + loader); if (Principal.class.isAssignableFrom(principalClass)) { classNamesList.add(classNames[i]); } else { @@ -293,16 +296,13 @@ } /** - * Sets the list of comma-delimited classes that represent individual - * users. The classes in the list must implement <code>java.security.Principal</code>. - * When this accessor is called (for example, by a <code>Digester</code> - * instance parsing the - * configuration file), it will parse the class names and store the resulting - * string(s) into the <code>ArrayList</code> field </code>userClasses</code>. - */ + * Sets the list of comma-delimited classes that represent individual + * users. The classes in the list must implement + * <code>java.security.Principal</code>. The supplied list of classes will + * be parsed when [EMAIL PROTECTED] #start()} is called. + */ public void setUserClassNames(String userClassNames) { this.userClassNames = userClassNames; - parseClassNames(userClassNames, userClasses); } @@ -335,9 +335,10 @@ // What if the LoginModule is in the container class loader ? ClassLoader ocl = null; - if (isUseContextClassLoader()) { - ocl=Thread.currentThread().getContextClassLoader(); - Thread.currentThread().setContextClassLoader(this.getClass().getClassLoader()); + if (!isUseContextClassLoader()) { + ocl = Thread.currentThread().getContextClassLoader(); + Thread.currentThread().setContextClassLoader( + this.getClass().getClassLoader()); } try { @@ -348,7 +349,7 @@ log.error(sm.getString("jaasRealm.unexpectedError"), e); return (null); } finally { - if( isUseContextClassLoader()) { + if(!isUseContextClassLoader()) { Thread.currentThread().setContextClassLoader(ocl); } } @@ -462,9 +463,9 @@ Principal userPrincipal = null; // Scan the Principals for this Subject - Iterator principals = subject.getPrincipals().iterator(); + Iterator<Principal> principals = subject.getPrincipals().iterator(); while (principals.hasNext()) { - Principal principal = (Principal) principals.next(); + Principal principal = principals.next(); String principalClass = principal.getClass().getName(); @@ -547,6 +548,10 @@ // Perform normal superclass initialization super.start(); + // These need to be called after loading configuration, in case + // useContextClassLoader appears after them in xml config + parseClassNames(userClassNames, userClasses); + parseClassNames(roleClassNames, roleClasses); } Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=607339&r1=607338&r2=607339&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Fri Dec 28 13:31:46 2007 @@ -107,6 +107,10 @@ <fix> <bug>44041</bug>: Fix duplicate class definition under load. (markt) </fix> + <fix> + <bug>44084</bug>: JASSRealm was broken for application provided + Principals. Patch provided by Noah Levitt. (markt) + </fix> </changelog> </subsection> <subsection name="Coyote"> --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]