Author: rjung Date: Wed Sep 9 09:10:11 2009 New Revision: 812847 URL: http://svn.apache.org/viewvc?rev=812847&view=rev Log: Backport r610930 from tc6.0.x:
Include user principal if possible when serializing de-serializing sessions. Fix bug 43840. Modified: tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/LocalStrings.properties tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/LocalStrings_es.properties tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/SerializablePrincipal.java Modified: tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml?rev=812847&r1=812846&r2=812847&view=diff ============================================================================== --- tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml (original) +++ tomcat/sandbox/tomcat-oacc/trunk/docs/changelog.xml Wed Sep 9 09:10:11 2009 @@ -33,6 +33,11 @@ <subsection name="Cluster"> <changelog> <fix> + <bug>43840</bug>: Include user principal if possible when serializing / + de-serializing sessions. + Port from Tomcat 6.0. (rjung) + </fix> + <fix> <bug>40551</bug>: Enable the JvmRouteBinderValve to work with PersistentManagers as well as clustering. Patch by Chris Chandler. Port from Tomcat 5.5. (rjung) Modified: tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/LocalStrings.properties URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/LocalStrings.properties?rev=812847&r1=812846&r2=812847&view=diff ============================================================================== --- tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/LocalStrings.properties (original) +++ tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/LocalStrings.properties Wed Sep 9 09:10:11 2009 @@ -91,3 +91,4 @@ standardSession.removeAttribute.ise=removeAttribute: Session already invalidated standardSession.sessionEvent=Session event listener threw exception standardSession.setAttribute.namenull=setAttribute: name parameter cannot be null +serializablePrincipal.readPrincipal.cnfe=readPrincipal: Failed to recreate user Principal Modified: tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/LocalStrings_es.properties URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/LocalStrings_es.properties?rev=812847&r1=812846&r2=812847&view=diff ============================================================================== --- tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/LocalStrings_es.properties (original) +++ tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/LocalStrings_es.properties Wed Sep 9 09:10:11 2009 @@ -90,3 +90,4 @@ standardSession.removeAttribute.ise = removeAttribute\: Sesi\u00F3n ya invalidada standardSession.sessionEvent = El oyente de evento de sesi\u00F3n lanz\u00F3 excepci\u00F3n standardSession.setAttribute.namenull = setAttribute\: par\u00E1metro de nombre no puede ser nulo +serializablePrincipal.readPrincipal.cnfe = readPrincipal\: No pude volver a crea el usuario Principal Modified: tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/SerializablePrincipal.java URL: http://svn.apache.org/viewvc/tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/SerializablePrincipal.java?rev=812847&r1=812846&r2=812847&view=diff ============================================================================== --- tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/SerializablePrincipal.java (original) +++ tomcat/sandbox/tomcat-oacc/trunk/src/share/org/apache/catalina/cluster/session/SerializablePrincipal.java Wed Sep 9 09:10:11 2009 @@ -23,11 +23,13 @@ import java.io.ObjectInput; import java.io.ObjectOutput; import java.io.Serializable; +import java.security.Principal; import java.util.Arrays; import java.util.List; import org.apache.catalina.Realm; import org.apache.catalina.realm.GenericPrincipal; +import org.apache.catalina.util.StringManager; /** @@ -40,6 +42,14 @@ */ public class SerializablePrincipal implements Serializable { + protected static org.apache.juli.logging.Log log = + org.apache.juli.logging.LogFactory.getLog(SerializablePrincipal.class); + + /** + * The string manager for this package. + */ + protected static StringManager sm = + StringManager.getManager(Constants.Package); // ----------------------------------------------------------- Constructors @@ -75,6 +85,23 @@ */ public SerializablePrincipal(Realm realm, String name, String password, List<String> roles) { + this(realm, name, password, roles, 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 user principal to be exposed to applications + */ + public SerializablePrincipal(Realm realm, String name, String password, + List<String> roles, Principal userPrincipal) { super(); this.realm = realm; @@ -86,7 +113,9 @@ if (this.roles.length > 0) Arrays.sort(this.roles); } - + if (userPrincipal instanceof Serializable) { + this.userPrincipal = userPrincipal; + } } @@ -140,6 +169,11 @@ } + /** + * The user principal, if present. + */ + protected Principal userPrincipal = null; + // --------------------------------------------------------- Public Methods @@ -164,13 +198,15 @@ return new SerializablePrincipal(principal.getRealm(), principal.getName(), principal.getPassword(), - principal.getRoles()!=null?Arrays.asList(principal.getRoles()):null); + principal.getRoles()!=null?Arrays.asList(principal.getRoles()):null, + principal.getUserPrincipal()!=principal?principal.getUserPrincipal():null); } public GenericPrincipal getPrincipal( Realm realm ) { return new GenericPrincipal(realm, name, password, - getRoles()!=null?Arrays.asList(getRoles()):null); + getRoles()!=null?Arrays.asList(getRoles()):null, + userPrincipal); } public static GenericPrincipal readPrincipal(ObjectInput in, Realm realm) @@ -182,7 +218,19 @@ int size = in.readInt(); String[] roles = new String[size]; for ( int i=0; i<size; i++ ) roles[i] = in.readUTF(); - return new GenericPrincipal(realm,name,pwd,Arrays.asList(roles)); + Principal userPrincipal = null; + boolean hasUserPrincipal = in.readBoolean(); + if (hasUserPrincipal) { + try { + userPrincipal = (Principal) in.readObject(); + } catch (ClassNotFoundException e) { + log.error(sm.getString( + "serializablePrincipal.readPrincipal.cnfe"), e); + throw e; + } + } + return new GenericPrincipal(realm,name,pwd,Arrays.asList(roles), + userPrincipal); } public static void writePrincipal(GenericPrincipal p, ObjectOutput out) @@ -194,6 +242,10 @@ if ( roles == null ) roles = new String[0]; out.writeInt(roles.length); for ( int i=0; i<roles.length; i++ ) out.writeUTF(roles[i]); + boolean hasUserPrincipal = (p != p.getUserPrincipal() && + p.getUserPrincipal() instanceof Serializable); + out.writeBoolean(hasUserPrincipal); + if (hasUserPrincipal) out.writeObject(p.getUserPrincipal()); } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org