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/05/09 02:21:55 UTC

svn commit: r942483 - in /incubator/shiro/trunk/core/src/main/java/org/apache/shiro: authc/credential/SimpleCredentialsMatcher.java codec/CodecSupport.java

Author: lhazlewood
Date: Sun May  9 00:21:55 2010
New Revision: 942483

URL: http://svn.apache.org/viewvc?rev=942483&view=rev
Log:
Ensured CodecSupport and the SimpleCredentialsMatcher's check for a byte source is easier and also supports the ByteSource type.

Modified:
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authc/credential/SimpleCredentialsMatcher.java
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/codec/CodecSupport.java

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authc/credential/SimpleCredentialsMatcher.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authc/credential/SimpleCredentialsMatcher.java?rev=942483&r1=942482&r2=942483&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authc/credential/SimpleCredentialsMatcher.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/authc/credential/SimpleCredentialsMatcher.java Sun May  9 00:21:55 2010
@@ -24,8 +24,6 @@ import org.apache.shiro.codec.CodecSuppo
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.File;
-import java.io.InputStream;
 import java.util.Arrays;
 
 
@@ -101,12 +99,7 @@ public class SimpleCredentialsMatcher ex
                     tokenCredentials.getClass().getName() + " and accountCredentials of type [" +
                     accountCredentials.getClass().getName() + "]");
         }
-        if ((tokenCredentials instanceof byte[] || tokenCredentials instanceof char[] ||
-                tokenCredentials instanceof String || tokenCredentials instanceof File ||
-                tokenCredentials instanceof InputStream) &&
-                (accountCredentials instanceof byte[] || accountCredentials instanceof char[] ||
-                        accountCredentials instanceof String || accountCredentials instanceof File ||
-                        accountCredentials instanceof InputStream)) {
+        if (isByteSource(tokenCredentials) && isByteSource(accountCredentials)) {
             if (log.isDebugEnabled()) {
                 log.debug("Both credentials arguments can be easily converted to byte arrays.  Performing " +
                         "array equals comparison");

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/codec/CodecSupport.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/codec/CodecSupport.java?rev=942483&r1=942482&r2=942483&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/codec/CodecSupport.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/codec/CodecSupport.java Sun May  9 00:21:55 2010
@@ -18,6 +18,8 @@
  */
 package org.apache.shiro.codec;
 
+import org.apache.shiro.util.ByteSource;
+
 import java.io.*;
 
 /**
@@ -162,24 +164,26 @@ public abstract class CodecSupport {
      * <ul>
      * <li>{@code byte[]}</li>
      * <li>{@code char[]}</li>
+     * <li>{@link ByteSource}</li>
      * <li>{@link String}</li>
      * <li>{@link File}</li>
      * </li>{@link InputStream}</li>
      * </ul>
      *
+     * @param o the object to test to see if it can be easily converted to a byte array
      * @return {@code true} if the specified object can be easily converted to bytes by instances of this class,
      *         {@code false} otherwise.
      * @since 1.0
      */
     protected boolean isByteSource(Object o) {
         return o instanceof byte[] || o instanceof char[] || o instanceof String ||
-                o instanceof File || o instanceof InputStream;
+                o instanceof ByteSource || o instanceof File || o instanceof InputStream;
     }
 
     /**
      * Converts the specified Object into a byte array.
      * <p/>
-     * If the argument is a {@code byte[]}, {@code char[]}, {@link String}, {@link File}, or
+     * If the argument is a {@code byte[]}, {@code char[]}, {@link ByteSource}, {@link String}, {@link File}, or
      * {@link InputStream}, it will be converted automatically and returned.}
      * <p/>
      * If the argument is anything other than these types, it is passed to the
@@ -195,6 +199,8 @@ public abstract class CodecSupport {
         }
         if (o instanceof byte[]) {
             return (byte[]) o;
+        } else if (o instanceof ByteSource) {
+            return ((ByteSource) o).getBytes();
         } else if (o instanceof char[]) {
             return toBytes((char[]) o);
         } else if (o instanceof String) {
@@ -294,8 +300,8 @@ public abstract class CodecSupport {
      */
     protected byte[] objectToBytes(Object o) {
         String msg = "The " + getClass().getName() + " implementation only supports conversion to " +
-                "byte[] if the source is of type byte[], char[], String, File or InputStream.  The instance " +
-                "provided as a method " +
+                "byte[] if the source is of type byte[], char[], String, " + ByteSource.class.getName() +
+                " File or InputStream.  The instance provided as a method " +
                 "argument is of type [" + o.getClass().getName() + "].  If you would like to convert " +
                 "this argument type to a byte[], you can 1) convert the argument to one of the supported types " +
                 "yourself and then use that as the method argument or 2) subclass " + getClass().getName() +