From e29ccebc213274943956c4ec45bbbf72e8b953fd Mon Sep 17 00:00:00 2001
From: pskopek The options parameter, which appears in a few places, is used to pass
- * several pieces of information to the encoder. In the "higher level" methods such as
- * encodeBytes( bytes, options ) the options parameter can be used to indicate such
+ * The options parameter, which appears in a few places, is used to pass
+ * several pieces of information to the encoder. In the "higher level" methods such as
+ * encodeBytes( bytes, options ) the options parameter can be used to indicate such
* things as first gzipping the bytes before encoding them, not inserting linefeeds,
* and encoding using the URL-safe and Ordered dialects.
* byte[] myByteArray = Base64.decode( encoded );
*
- *
The constants defined in Base64 can be OR-ed together to combine options, so you + *
The constants defined in Base64 can be OR-ed together to combine options, so you * might make a call like this:
* *String encoded = Base64.encodeBytes( mybytes, Base64.GZIP | Base64.DO_BREAK_LINES );
@@ -68,7 +68,7 @@ package org.keycloak.common.util;
* Encodes up to three bytes of the array source * and writes the resulting four Base64 bytes to destination. * The source and destination arrays can be manipulated - * anywhere along their length by specifying + * anywhere along their length by specifying * srcOffset and destOffset. * This method does not check to make sure your arrays * are large enough to accomodate srcOffset + 3 for @@ -498,7 +498,7 @@ public class Base64 byte[] ALPHABET = getAlphabet( options ); - // 1 2 3 + // 1 2 3 // 01234567890123456789012345678901 Bit position // --------000000001111111122222222 Array position from threeBytes // --------| || || || | Six bit groups to index ALPHABET @@ -597,7 +597,7 @@ public class Base64 /** * Serializes an object and returns the Base64-encoded - * version of that serialized object. + * version of that serialized object. * *
As of v 2.3, if the object * cannot be serialized or there is another error, @@ -991,11 +991,11 @@ public class Base64 } // end else: don't compress } // end encodeBytesToBytes - - - - + + + + /* ******** D E C O D I N G M E T H O D S ******** */ @@ -1004,13 +1004,13 @@ public class Base64 * and writes the resulting bytes (up to three of them) * to destination. * The source and destination arrays can be manipulated - * anywhere along their length by specifying + * anywhere along their length by specifying * srcOffset and destOffset. * This method does not check to make sure your arrays * are large enough to accomodate srcOffset + 4 for * the source array or destOffset + 3 for * the destination array. - * This method returns the actual number of bytes that + * This method returns the actual number of bytes that * were converted from the Base64 encoding. *
This is the lowest level of the decoding methods with * all possible parameters.
@@ -1200,7 +1200,7 @@ public class Base64 // There's a bad input character in the Base64 stream. throw new java.io.IOException( String.format( "Bad Base64 input character decimal %d in array position %d", ((int)source[i])&0xFF, i ) ); - } // end else: + } // end else: } // each input character byte[] out = new byte[ outBuffPosn ]; @@ -1302,94 +1302,6 @@ public class Base64 return bytes; } // end decode - - - /** - * Attempts to decode Base64 data and deserialize a Java - * Object within. Returns null if there was an error. - * - * @param encodedObject The Base64 data to decode - * @return The decoded and deserialized object - * @throws NullPointerException if encodedObject is null - * @throws java.io.IOException if there is a general error - * @throws ClassNotFoundException if the decoded object is of a - * class that cannot be found by the JVM - * @since 1.5 - */ - public static Object decodeToObject( String encodedObject ) - throws java.io.IOException, java.lang.ClassNotFoundException { - return decodeToObject(encodedObject,NO_OPTIONS,null); - } - - - /** - * Attempts to decode Base64 data and deserialize a Java - * Object within. Returns null if there was an error. - * If loader is not null, it will be the class loader - * used when deserializing. - * - * @param encodedObject The Base64 data to decode - * @param options Various parameters related to decoding - * @param loader Optional class loader to use in deserializing classes. - * @return The decoded and deserialized object - * @throws NullPointerException if encodedObject is null - * @throws java.io.IOException if there is a general error - * @throws ClassNotFoundException if the decoded object is of a - * class that cannot be found by the JVM - * @since 2.3.4 - */ - public static Object decodeToObject( - String encodedObject, int options, final ClassLoader loader ) - throws java.io.IOException, java.lang.ClassNotFoundException { - - // Decode and gunzip if necessary - byte[] objBytes = decode( encodedObject, options ); - - java.io.ByteArrayInputStream bais = null; - java.io.ObjectInputStream ois = null; - Object obj = null; - - try { - bais = new java.io.ByteArrayInputStream( objBytes ); - - // If no custom class loader is provided, use Java's builtin OIS. - if( loader == null ){ - ois = new java.io.ObjectInputStream( bais ); - } // end if: no loader provided - - // Else make a customized object input stream that uses - // the provided class loader. - else { - ois = new java.io.ObjectInputStream(bais){ - @Override - public Class> resolveClass(java.io.ObjectStreamClass streamClass) - throws java.io.IOException, ClassNotFoundException { - Class c = Class.forName(streamClass.getName(), false, loader); - if( c == null ){ - return super.resolveClass(streamClass); - } else { - return c; // Class loader knows of this class. - } // end else: not null - } // end resolveClass - }; // end ois - } // end else: no custom class loader - - obj = ois.readObject(); - } // end try - catch( java.io.IOException e ) { - throw e; // Catch and throw in order to execute finally{} - } // end catch - catch( java.lang.ClassNotFoundException e ) { - throw e; // Catch and throw in order to execute finally{} - } // end catch - finally { - try{ bais.close(); } catch( Exception e ){} - try{ ois.close(); } catch( Exception e ){} - } // end finally - - return obj; - } // end decodeObject - /* ******** I N N E R C L A S S I N P U T S T R E A M ******** */ /** @@ -1522,7 +1434,7 @@ public class Base64 else { // Must have broken out from above. throw new java.io.IOException( "Improperly padded Base64 input." ); - } // end + } // end } // end else: decode } // end else: get data @@ -1595,12 +1507,12 @@ public class Base64 } // end read } // end inner class InputStream - - - - - - + + + + + + /* ******** I N N E R C L A S S O U T P U T S T R E A M ******** */ @@ -1730,7 +1642,7 @@ public class Base64 /** - * Calls {@link #write(int)} repeatedly until len + * Calls {@link #write(int)} repeatedly until len * bytes are written. * * @param theBytes array from which to read bytes @@ -1775,7 +1687,7 @@ public class Base64 /** - * Flushes and closes (I think, in the superclass) the stream. + * Flushes and closes (I think, in the superclass) the stream. * * @since 1.3 */ diff --git a/saml-core-api/src/main/java/org/keycloak/saml/common/util/Base64.java b/saml-core-api/src/main/java/org/keycloak/saml/common/util/Base64.java index eade901dfde..8b71397c5d5 100755 --- a/saml-core-api/src/main/java/org/keycloak/saml/common/util/Base64.java +++ b/saml-core-api/src/main/java/org/keycloak/saml/common/util/Base64.java @@ -693,48 +693,6 @@ public class Base64 { return bytes; } // end decode - /** - * Attempts to decode Base64 data and deserialize a Java Object within. Returns null if there was an error. - * - * @param encodedObject The Base64 data to decode - * @return The decoded and deserialized object - * @since 1.5 - */ - public static Object decodeToObject(String encodedObject) { - // Decode and gunzip if necessary - byte[] objBytes = decode(encodedObject); - - java.io.ByteArrayInputStream bais = null; - java.io.ObjectInputStream ois = null; - Object obj = null; - - try { - bais = new java.io.ByteArrayInputStream(objBytes); - ois = new java.io.ObjectInputStream(bais); - - obj = ois.readObject(); - } // end try - catch (java.io.IOException e) { - e.printStackTrace(); - obj = null; - } // end catch - catch (java.lang.ClassNotFoundException e) { - e.printStackTrace(); - obj = null; - } // end catch - finally { - try { - bais.close(); - } catch (Exception e) { - } - try { - ois.close(); - } catch (Exception e) { - } - } // end finally - - return obj; - } // end decodeObject /* ******** I N N E R C L A S S I N P U T S T R E A M ******** */