1/* 2 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24import javax.security.auth.x500.X500Principal; 25 26/** 27 * @test 28 * @bug 6611991 29 * @summary Add support for parsing RFC 4514 DNs to X500Principal 30 * 31 * Ensure RFC 4514 Distinguished Name Strings can be parsed by X500Principal. 32 * RFC 4514 obsoleted RFC 2253 so we should make sure we can parse DNs of 33 * that form that contain subtle differences or clarifications in the grammar. 34 */ 35public class RFC4514 { 36 37 private int failed = 0; 38 39 public static void main(String[] args) throws Exception { 40 new RFC4514().test(); 41 } 42 43 private void test() throws Exception { 44 45 /** 46 * RFC 4514 allows space to be escaped as '\ '. 47 */ 48 parse("CN=\\ Space\\ ,C=US"); 49 parse("CN=Sp\\ ace,C=US"); 50 /** 51 * RFC 4514 does not require escaping of '=' characters. 52 */ 53 parse("CN=Eq=uals,C=US"); 54 /** 55 * RFC 4514 requires the null character to be escaped. 56 */ 57 parse("CN=\\00,C=US"); 58 /** 59 * RFC 4514 does not require escaping of non-leading '#' characters. 60 */ 61 parse("CN=Num#ber,C=US"); 62 /** 63 * XMLDSig (http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/) 64 * allows implementations to escape trailing whitespace as '\20'. 65 */ 66 parse("CN=Trailing \\20,C=US"); 67 /** 68 * XMLDSig allows implementations to escape ASCII control characters 69 * (Unicode range \x00 - \x1f) by replacing them with "\" followed by 70 * a two digit hex number showing its Unicode number. 71 */ 72 parse("CN=Con\\09trol,C=US"); 73 74 if (failed != 0) { 75 throw new Exception("Some RFC4514 tests FAILED"); 76 } 77 } 78 79 public void parse(String dnString) throws Exception { 80 81 System.out.println("Parsing " + dnString); 82 X500Principal dn = new X500Principal(dnString); 83 String dnString2 = dn.getName(); 84 X500Principal dn2 = new X500Principal(dnString2); 85 if (dn.equals(dn2)) { 86 System.out.println("PASSED"); 87 } else { 88 System.out.println("FAILED"); 89 failed++; 90 } 91 } 92} 93