shiro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lhazlew...@apache.org
Subject svn commit: r906238 - in /incubator/shiro/trunk/core/src/main/java/org/apache/shiro: io/DefaultSerializer.java io/Serializer.java mgt/AbstractRememberMeManager.java
Date Wed, 03 Feb 2010 20:58:23 GMT
Author: lhazlewood
Date: Wed Feb  3 20:58:22 2010
New Revision: 906238

URL: http://svn.apache.org/viewvc?rev=906238&view=rev
Log:
Enabled generic types for the Serializer interface and updated the AbstractRememberMeManager
implementation to reference a Serializer<PrincipalCollection>

Modified:
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/io/DefaultSerializer.java
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/io/Serializer.java
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/io/DefaultSerializer.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/io/DefaultSerializer.java?rev=906238&r1=906237&r2=906238&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/io/DefaultSerializer.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/io/DefaultSerializer.java Wed
Feb  3 20:58:22 2010
@@ -18,13 +18,7 @@
  */
 package org.apache.shiro.io;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
+import java.io.*;
 
 /**
  * Serializer implementation that uses the default JVM serialization mechanism (Object Input/Output
Streams).
@@ -32,9 +26,9 @@
  * @author Les Hazlewood
  * @since 0.9
  */
-public class DefaultSerializer implements Serializer {
+public class DefaultSerializer<T> implements Serializer<T> {
 
-    public byte[] serialize(Object o) throws SerializationException {
+    public byte[] serialize(T o) throws SerializationException {
         if (o == null) {
             String msg = "argument cannot be null.";
             throw new IllegalArgumentException(msg);
@@ -55,7 +49,7 @@
         }
     }
 
-    public Object deserialize(byte[] serialized) throws SerializationException {
+    public T deserialize(byte[] serialized) throws SerializationException {
         if (serialized == null) {
             String msg = "argument cannot be null.";
             throw new IllegalArgumentException(msg);
@@ -64,7 +58,8 @@
         BufferedInputStream bis = new BufferedInputStream(bais);
         try {
             ObjectInputStream ois = new ObjectInputStream(bis);
-            Object deserialized = ois.readObject();
+            @SuppressWarnings({"unchecked"})
+            T deserialized = (T)ois.readObject();
             ois.close();
             return deserialized;
         } catch (Exception e) {

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/io/Serializer.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/io/Serializer.java?rev=906238&r1=906237&r2=906238&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/io/Serializer.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/io/Serializer.java Wed Feb 
3 20:58:22 2010
@@ -25,10 +25,11 @@
  * A <code>Serializer</code> should only do conversion, never change the data,
such as encoding/decoding or
  * encryption.  These orthoganal concerns are handled elsewhere by Shiro, for example, via
  * {@link org.apache.shiro.codec.CodecSupport CodecSupport} and {@link org.apache.shiro.crypto.Cipher
Cipher}s.
+ * @param <T> The type of the object being serialized and deserialized.
  * @author Les Hazlewood
  * @since 0.9
  */
-public interface Serializer {
+public interface Serializer<T> {
 
     /**
      * Converts the specified Object into a byte[] array.  This byte[] array must be able
to be reconstructed
@@ -37,7 +38,7 @@
      * @return a byte[] array representing the Object's state that can be restored later.
      * @throws SerializationException if an error occurrs converting the Object into a byte[]
array.
      */
-    byte[] serialize(Object o) throws SerializationException;
+    byte[] serialize(T o) throws SerializationException;
 
     /**
      * Converts the specified raw byte[] array back into an original Object form.  This byte[]
array is expected to
@@ -47,5 +48,5 @@
      * @return the Object that was previously serialized into the raw byte[] array.
      * @throws SerializationException if an error occurrs converting the raw byte[] array
back into an Object.
      */
-    Object deserialize(byte[] serialized) throws SerializationException;
+    T deserialize(byte[] serialized) throws SerializationException;
 }

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java?rev=906238&r1=906237&r2=906238&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java
(original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/mgt/AbstractRememberMeManager.java
Wed Feb  3 20:58:22 2010
@@ -18,9 +18,6 @@
  */
 package org.apache.shiro.mgt;
 
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.shiro.authc.AuthenticationException;
 import org.apache.shiro.authc.AuthenticationInfo;
 import org.apache.shiro.authc.AuthenticationToken;
@@ -33,6 +30,8 @@
 import org.apache.shiro.io.SerializationException;
 import org.apache.shiro.io.Serializer;
 import org.apache.shiro.subject.PrincipalCollection;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 
 /**
@@ -55,7 +54,7 @@
      */
     private static final Logger log = LoggerFactory.getLogger(AbstractRememberMeManager.class);
 
-    private Serializer serializer = new DefaultSerializer();
+    private Serializer<PrincipalCollection> serializer = new DefaultSerializer<PrincipalCollection>();
     private Cipher cipher = new BlowfishCipher();
     private byte[] encryptionCipherKey = null;
     private byte[] decryptionCipherKey = null;
@@ -63,11 +62,11 @@
     public AbstractRememberMeManager() {
     }
 
-    public Serializer getSerializer() {
+    public Serializer<PrincipalCollection> getSerializer() {
         return serializer;
     }
 
-    public void setSerializer(Serializer serializer) {
+    public void setSerializer(Serializer<PrincipalCollection> serializer) {
         this.serializer = serializer;
     }
 
@@ -261,7 +260,7 @@
     }
 
     protected PrincipalCollection deserialize(byte[] serializedIdentity) {
-        return (PrincipalCollection) getSerializer().deserialize(serializedIdentity);
+        return getSerializer().deserialize(serializedIdentity);
     }
 
     public void onFailedLogin(AuthenticationToken token, AuthenticationException ae) {



Mime
View raw message