Author: markt Date: Sun Dec 23 13:55:38 2007 New Revision: 606621 URL: http://svn.apache.org/viewvc?rev=606621&view=rev Log: Fix 44084 with a patch provided by Noah Levitt. I also made a few additional fixes to line lengths etc.
Modified: tomcat/trunk/java/org/apache/catalina/realm/JAASRealm.java Modified: tomcat/trunk/java/org/apache/catalina/realm/JAASRealm.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/realm/JAASRealm.java?rev=606621&r1=606620&r2=606621&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/realm/JAASRealm.java (original) +++ tomcat/trunk/java/org/apache/catalina/realm/JAASRealm.java Sun Dec 23 13:55:38 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); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]