Author: markt Date: Wed Nov 4 00:08:46 2009 New Revision: 832626 URL: http://svn.apache.org/viewvc?rev=832626&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=39231 JAAS LoginContext expects a call to logout()
Modified: tomcat/tc6.0.x/trunk/STATUS.txt tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/GenericPrincipal.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/JAASRealm.java tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/LocalStrings.properties tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardSession.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=832626&r1=832625&r2=832626&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/STATUS.txt (original) +++ tomcat/tc6.0.x/trunk/STATUS.txt Wed Nov 4 00:08:46 2009 @@ -67,14 +67,6 @@ -1: remm: no for TC 6.0 -1: funkman : api change in Session.java for .x.x release -* Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=39231 - JAAS LoginContext expects a call to logout() - It is updated version of Mark's (since withdrawn) patch, - where the new method in JAASRealm calls the old one. - http://people.apache.org/~kkolinko/patches/2009-11-02_bug39231.patch - +1: kkolinko, markt,funkman - -1: - * Improve NIO connector shutdown time by doing shutdowns in parallel and with a timeout http://svn.apache.org/viewvc?view=rev&revision=791914 Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/GenericPrincipal.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/GenericPrincipal.java?rev=832626&r1=832625&r2=832626&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/GenericPrincipal.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/realm/GenericPrincipal.java Wed Nov 4 00:08:46 2009 @@ -22,6 +22,10 @@ import java.security.Principal; import java.util.Arrays; import java.util.List; + +import javax.security.auth.login.LoginContext; +import javax.security.auth.login.LoginException; + import org.apache.catalina.Realm; @@ -83,7 +87,26 @@ */ public GenericPrincipal(Realm realm, String name, String password, List<String> roles, Principal userPrincipal) { - + this(realm, name, password, roles, userPrincipal, null); + } + + /** + * Construct a new Principal, associated with the specified Realm, for the + * specified username and password, with the specified role names + * (as Strings). + * + * @param realm The Realm that owns this principal + * @param name The username of the user represented by this Principal + * @param password Credentials used to authenticate this user + * @param roles List of roles (must be Strings) possessed by this user + * @param userPrincipal - the principal to be returned from the request + * getUserPrincipal call if not null; if null, this will be returned + * @param loginContext - If provided, this will be used to log out the user + * at the appropriate time + */ + public GenericPrincipal(Realm realm, String name, String password, + List<String> roles, Principal userPrincipal, + LoginContext loginContext) { super(); this.realm = realm; this.name = name; @@ -95,6 +118,7 @@ if (this.roles.length > 0) Arrays.sort(this.roles); } + this.loginContext = loginContext; } @@ -159,6 +183,16 @@ } } + + /** + * The JAAS LoginContext, if any, used to authenticate this Principal. + * Kept so we can call logout(). + */ + protected LoginContext loginContext = null; + + void setLoginContext( LoginContext loginContext ) { + this.loginContext=loginContext; + } // --------------------------------------------------------- Public Methods @@ -196,5 +230,22 @@ } + + /** + * Calls logout, if necessary, on any associated JAASLoginContext. May in + * the future be extended to cover other logout requirements. + * + * @throws Exception If something goes wrong with the logout. Uses Exception + * to allow for future expansion of this method to cover + * other logout mechanisms that might throw a different + * exception to LoginContext + * + */ + public void logout() throws Exception { + if (loginContext != null) { + loginContext.logout(); + } + } + } 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=832626&r1=832625&r2=832626&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 Wed Nov 4 00:08:46 2009 @@ -426,7 +426,7 @@ log.debug(sm.getString("jaasRealm.loginContextCreated", username)); // Return the appropriate Principal for this authenticated Subject - Principal principal = createPrincipal(username, subject); + Principal principal = createPrincipal(username, subject, loginContext); if (principal == null) { log.debug(sm.getString("jaasRealm.authenticateFailure", username)); return (null); @@ -477,16 +477,8 @@ /** - * Identify and return a <code>java.security.Principal</code> instance - * representing the authenticated user for the specified <code>Subject</code>. - * The Principal is constructed by scanning the list of Principals returned - * by the JAASLoginModule. The first <code>Principal</code> object that matches - * one of the class names supplied as a "user class" is the user Principal. - * This object is returned to tha caller. - * Any remaining principal objects returned by the LoginModules are mapped to - * roles, but only if their respective classes match one of the "role class" classes. - * If a user Principal cannot be constructed, return <code>null</code>. - * @param subject The <code>Subject</code> representing the logged-in user + * @deprecated + * Use {...@link JAASRealm#createPrincipal(String, Subject, LoginContext)} */ protected Principal createPrincipal(String username, Subject subject) { // Prepare to scan the Principals for this Subject @@ -538,6 +530,29 @@ return new GenericPrincipal(this, username, null, roles, userPrincipal); } + /** + * Identify and return a <code>java.security.Principal</code> instance + * representing the authenticated user for the specified <code>Subject</code>. + * The Principal is constructed by scanning the list of Principals returned + * by the JAASLoginModule. The first <code>Principal</code> object that matches + * one of the class names supplied as a "user class" is the user Principal. + * This object is returned to the caller. + * Any remaining principal objects returned by the LoginModules are mapped to + * roles, but only if their respective classes match one of the "role class" classes. + * If a user Principal cannot be constructed, return <code>null</code>. + * @param subject The <code>Subject</code> representing the logged-in user + * @param loginContext Associated with the Principal so + * {...@link LoginContext#logout()} can be called later + */ + protected Principal createPrincipal(String username, Subject subject, + LoginContext loginContext) { + Principal principal = createPrincipal(username, subject); + if (principal instanceof GenericPrincipal) { + ((GenericPrincipal) principal).setLoginContext(loginContext); + } + return principal; + } + /** * Ensure the given name is legal for JAAS configuration. * Added for Bugzilla 30869, made protected for easy customization Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/LocalStrings.properties?rev=832626&r1=832625&r2=832626&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/LocalStrings.properties (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/LocalStrings.properties Wed Nov 4 00:08:46 2009 @@ -60,6 +60,7 @@ standardSession.getId.ise=getId: Session already invalidated standardSession.getMaxInactiveInterval.ise=getMaxInactiveInterval: Session already invalidated standardSession.getValueNames.ise=getValueNames: Session already invalidated +standardSession.logoutfail=Exception logging out user when expiring session standardSession.notSerializable=Cannot serialize session attribute {0} for session {1} standardSession.removeAttribute.ise=removeAttribute: Session already invalidated standardSession.sessionEvent=Session event listener threw exception Modified: tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardSession.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardSession.java?rev=832626&r1=832625&r2=832626&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardSession.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/session/StandardSession.java Wed Nov 4 00:08:46 2009 @@ -57,6 +57,7 @@ import org.apache.catalina.util.StringManager; import org.apache.catalina.core.StandardContext; +import org.apache.catalina.realm.GenericPrincipal; import org.apache.catalina.security.SecurityUtil; /** @@ -734,6 +735,18 @@ fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null); } + // Call the logout method + if (principal instanceof GenericPrincipal) { + GenericPrincipal gp = (GenericPrincipal) principal; + try { + gp.logout(); + } catch (Exception e) { + manager.getContainer().getLogger().error( + sm.getString("standardSession.logoutfail"), + e); + } + } + // We have completed expire of this session expiring = false; 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=832626&r1=832625&r2=832626&view=diff ============================================================================== --- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Wed Nov 4 00:08:46 2009 @@ -65,6 +65,10 @@ manager. (markt) </fix> <fix> + <bug>39231</bug>: Call LoginContext.logout() when using JAAS realm and + session expires. (markt/kkolinko) + </fix> + <fix> <bug>40380</bug>: Fix potential synchronization issue in StandardSession.expire(). (markt) </fix> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org