/* * Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * @test * @bug 8035807 * @summary Confirm that old and new Base64 encodings are compatible.
*/
/* * RFC 2713 specifies an encoding for Java objects stored in an LDAP directory. * Section 3.6 specifies how a binary-valued JNDI RefAddr object is encoded * in the value of a javaReferenceAttribute LDAP attribute: first the RefAddr * object is serialized and then it is encoded using Base64. * * Since JDK 9, the JNDI/LDAP provider uses the public Base64 encoder which * adheres strictly to the MIME encoding rules. The encoder inserts '\r\n' * as the line separator at intervals of 76 characters. Previously the * JNDI/LDAP provider used a private Base64 encoder which inserted '\n' * as the line separator. It is a compatible change. * * This test demonstrates that there is no compatability problem when * decoding using the new Base64 coder: * * encoded bytes captured from s.m.BASE64Encoder, decode with j.u.Base64.Decoder => OK * encoded bytes captured from j.u.Base64.Encoder, decode with j.u.Base64.Decoder => OK * * * NOTE: The two Base64 encodings used in this test were captured from * LDAP protocol exchanges during attempts by the JNDI/LDAP provider * to store a JNDI Reference test object.
*/
/* * Deserialize the decoded Base64 bytes to recover the BinaryRefAddr object.
*/ privatestaticvoid deserialize(byte[] bytes) throws Exception {
ObjectInputStream objectStream = new ObjectInputStream(new ByteArrayInputStream(bytes));
Object object = objectStream.readObject(); if (!BINARY_REF_ADDR.equals(object)) { thrownew Exception("Recovered object does not match the original");
}
System.out.println("Recovered RefAddr object:\n" + object);
}
/* * Dumps the encoding of a JNDI Reference object during an attempt to store * in an LDAP directory.
*/ privatestaticvoid storeObjectInLDAP() {
Hashtable<Object, Object> env = new Hashtable<>();
env.put(Context.REFERRAL, "follow"); // omit an LDAP control
env.put("java.naming.ldap.version", "3"); // omit LDAP bind operation
env.put("com.sun.jndi.ldap.trace.ber", System.err); // dump protocol try {
DirContext ctx = new InitialDirContext(env);
Reference reference = new Reference("test", BINARY_REF_ADDR);
ctx.bind("ldap://ldap.example.com/cn=test", reference);
} catch (NamingException ignore) {
}
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.