You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lh...@apache.org on 2010/02/12 23:11:00 UTC
svn commit: r909634 - in /incubator/shiro/trunk:
core/src/main/java/org/apache/shiro/ShiroException.java
core/src/main/java/org/apache/shiro/subject/SimplePrincipalCollection.java
web/src/test/java/org/apache/shiro/web/WebRememberMeManagerTest.java
Author: lhazlewood
Date: Fri Feb 12 22:10:59 2010
New Revision: 909634
URL: http://svn.apache.org/viewvc?rev=909634&view=rev
Log:
SHIRO-112 - ShiroException - removed unnecessary 'implements Serializable' clause because all Throwables are Serializable. SimplePrincipalCollection - iimplemented Serialization readObject/writeObject methods to mitigate serialization problems resulting from implementation changes. This should allow most implementation changes to occur without affecting application end-users (e.g. no rememberMe cookie breakage).
Modified:
incubator/shiro/trunk/core/src/main/java/org/apache/shiro/ShiroException.java
incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/SimplePrincipalCollection.java
incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/WebRememberMeManagerTest.java
Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/ShiroException.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/ShiroException.java?rev=909634&r1=909633&r2=909634&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/ShiroException.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/ShiroException.java Fri Feb 12 22:10:59 2010
@@ -18,8 +18,6 @@
*/
package org.apache.shiro;
-import java.io.Serializable;
-
/**
* Root exception for all Shiro runtime exceptions. This class is used as the root instead
* of {@link java.lang.SecurityException} to remove the potential for conflicts; many other
@@ -29,7 +27,7 @@
* @author Les Hazlewood
* @since 0.1
*/
-public class ShiroException extends RuntimeException implements Serializable {
+public class ShiroException extends RuntimeException {
/**
* Creates a new ShiroException.
Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/SimplePrincipalCollection.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/SimplePrincipalCollection.java?rev=909634&r1=909633&r2=909634&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/SimplePrincipalCollection.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/subject/SimplePrincipalCollection.java Fri Feb 12 22:10:59 2010
@@ -21,6 +21,9 @@
import org.apache.shiro.util.CollectionUtils;
import org.apache.shiro.util.StringUtils;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.util.*;
@@ -34,11 +37,18 @@
@SuppressWarnings({"unchecked"})
public class SimplePrincipalCollection implements MutablePrincipalCollection {
+ // Serialization reminder:
+ // You _MUST_ change this number if you introduce a change to this class
+ // that is NOT serialization backwards compatible. Serialization-compatible
+ // changes do not require a change to this number. If you need to generate
+ // a new number in this case, use the JDK's 'serialver' program to generate it.
+ private static final long serialVersionUID = -6305224034025797558L;
+
//TODO - complete JavaDoc
private Map<String, Set> realmPrincipals;
- private String cachedToString; //cached toString() result, as this can be printed many times in logging
+ private transient String cachedToString; //cached toString() result, as this can be printed many times in logging
public SimplePrincipalCollection() {
}
@@ -249,4 +259,44 @@
}
return this.cachedToString;
}
+
+
+ /**
+ * Serialization write support.
+ * <p/>
+ * NOTE: Don't forget to change the serialVersionUID constant at the top of this class
+ * if you make any backwards-incompatible serializatoin changes!!!
+ * (use the JDK 'serialver' program for this)
+ *
+ * @param out output stream provided by Java serialization
+ * @throws IOException if there is a stream error
+ */
+ private void writeObject(ObjectOutputStream out) throws IOException {
+ out.defaultWriteObject();
+ boolean principalsExist = !CollectionUtils.isEmpty(realmPrincipals);
+ out.writeBoolean(principalsExist);
+ if (principalsExist) {
+ out.writeObject(realmPrincipals);
+ }
+ }
+
+ /**
+ * Serialization read support - reads in the Map principals collection if it exists in the
+ * input stream.
+ * <p/>
+ * NOTE: Don't forget to change the serialVersionUID constant at the top of this class
+ * if you make any backwards-incompatible serializatoin changes!!!
+ * (use the JDK 'serialver' program for this)
+ *
+ * @param in input stream provided by
+ * @throws IOException if there is an input/output problem
+ * @throws ClassNotFoundException if the underlying Map implementation class is not available to the classloader.
+ */
+ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
+ in.defaultReadObject();
+ boolean principalsExist = in.readBoolean();
+ if (principalsExist) {
+ this.realmPrincipals = (Map<String, Set>) in.readObject();
+ }
+ }
}
Modified: incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/WebRememberMeManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/WebRememberMeManagerTest.java?rev=909634&r1=909633&r2=909634&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/WebRememberMeManagerTest.java (original)
+++ incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/WebRememberMeManagerTest.java Fri Feb 12 22:10:59 2010
@@ -85,13 +85,12 @@
//The following base64 string was determined from the log output of the above 'onSuccessfulLogin' test.
//This will have to change any time the PrincipalCollection implementation changes:
final String userPCBlowfishBase64 = "UwP13UzjVUceLBNWh+sYM01JWOSbBOwc1ZLySIws0Idnkc" +
- "WeD/yWeH0eIycwHaI8MRKPyenBr77dBdt3S7KTKzzt47bdseNbEI7TbTKPY5VfnJLqGVglQr+O" +
- "mTgH1vpCQ/PAw3XnrQ4FWSXe9/KkfcAfteY5iw7qea1zZJq5jC4dOU3HLlhL7+BtlFMOrSzP2i" +
- "ijwEZGFoNASMTpLxTpiiTHhVmB9Hf4s7N2rTthK18+uTyJwC1KoK3Fw82Wxl7BZb5aFoc5BoJb" +
- "lWyZVHV3hEIIIS9/2smrjrCdu0NRC31c/+IelggTG3jTMA1wQ0oq2jTZSjctlcknV90jxNJfbf" +
- "/Uzk679TmgyrHJgRrQ+kqJ+94rafqFWEcaG82yT3LkQEjE6S8U6Yokx4VZgfR3+Nnhgfb36EfU" +
- "BXytFPop+38q1ssgLNxj3TPPOMj/QfGHVX6lM6loW8zA3VIEtDyqXN0LAQzqnbC8zqb1CJhXaJ" +
- "owmdO9LV7XzouBN+l/ER8I";
+ "WeD/yWeH0eIycwHaI8MRKPyenBr77dBdt3S7KTK/6qKqKiW5oLqOgU/ZQLdvIOxlZxmT9RlUvK" +
+ "T6zopnQrSpdsCNaruG/Op/XEoJcdNLI9rJCCyMKN3em5wl8GrWTIzKS4hzHombGBEW4EPS9jv4" +
+ "0HV4mIS2sUFXm5MlOptr99e1A6eKYxlLrldk2/yqw29nWohE0sIjO7tRF9mOAZUeC/Fem6K4S8" +
+ "2LbXAJ6p0oNg3MP7dbFSkeeDF2CwFJvvi5xVrGyF0RnTzjwKZdTcvg4bx9ifQpKyPayQgsjCjd" +
+ "3pucJfBq1kuw/IyiPdSREnzWAEXOQi9o9II4jNvOJik+VI3QkwWdBBekzEKCACn8uvjlLKSiR8" +
+ "tCs9vbycs5N0FrODxMQ5FDvhV+rZLHtPkishP5cm/QEL01IUqqC4RA==";
Cookie[] cookies = new Cookie[]{
new Cookie(WebRememberMeManager.DEFAULT_REMEMBER_ME_COOKIE_NAME, userPCBlowfishBase64)