Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/sun/security/krb5/IPv6.java
38839 views
/*1* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 6877357 688516626* @run main/othervm IPv627* @summary IPv6 address does not work28*/2930import com.sun.security.auth.module.Krb5LoginModule;31import java.io.*;32import java.util.HashMap;33import java.util.Map;34import java.util.regex.Matcher;35import java.util.regex.Pattern;36import javax.security.auth.Subject;3738public class IPv6 {3940public static void main(String[] args) throws Exception {4142String[][] kdcs = {43{"simple.host", null}, // These are legal settings44{"simple.host", ""},45{"simple.host", "8080"},46{"0.0.0.1", null},47{"0.0.0.1", ""},48{"0.0.0.1", "8080"},49{"1::1", null},50{"[1::1]", null},51{"[1::1]", ""},52{"[1::1]", "8080"},53{"[1::1", null}, // Two illegal settings54{"[1::1]abc", null},55};56// Prepares a krb5.conf with every kind of KDC settings57PrintStream out = new PrintStream(new FileOutputStream("ipv6.conf"));58out.println("[libdefaults]");59out.println("default_realm = V6");60out.println("kdc_timeout = 1");61out.println("[realms]");62out.println("V6 = {");63for (String[] hp: kdcs) {64if (hp[1] != null) out.println(" kdc = "+hp[0]+":"+hp[1]);65else out.println(" kdc = " + hp[0]);66}67out.println("}");68out.close();6970System.setProperty("sun.security.krb5.debug", "true");71System.setProperty("java.security.krb5.conf", "ipv6.conf");7273ByteArrayOutputStream bo = new ByteArrayOutputStream();74PrintStream po = new PrintStream(bo);75PrintStream oldout = System.out;76System.setOut(po);7778try {79Subject subject = new Subject();80Krb5LoginModule krb5 = new Krb5LoginModule();81Map<String, String> map = new HashMap<>();82Map<String, Object> shared = new HashMap<>();8384map.put("debug", "true");85map.put("doNotPrompt", "true");86map.put("useTicketCache", "false");87map.put("useFirstPass", "true");88shared.put("javax.security.auth.login.name", "any");89shared.put("javax.security.auth.login.password", "any".toCharArray());90krb5.initialize(subject, null, shared, map);91krb5.login();92} catch (Exception e) {93// Ignore94}9596po.flush();9798System.setOut(oldout);99BufferedReader br = new BufferedReader(new StringReader(100new String(bo.toByteArray())));101int cc = 0;102Pattern r = Pattern.compile(".*KrbKdcReq send: kdc=(.*) UDP:(\\d+),.*");103String line;104while ((line = br.readLine()) != null) {105Matcher m = r.matcher(line.subSequence(0, line.length()));106if (m.matches()) {107System.out.println("------------------");108System.out.println(line);109String h = m.group(1), p = m.group(2);110String eh = kdcs[cc][0], ep = kdcs[cc][1];111if (eh.charAt(0) == '[') {112eh = eh.substring(1, eh.length()-1);113}114System.out.println("Expected: " + eh + " : " + ep);115System.out.println("Actual: " + h + " : " + p);116if (!eh.equals(h) ||117(ep == null || ep.length() == 0) && !p.equals("88") ||118(ep != null && ep.length() > 0) && !p.equals(ep)) {119throw new Exception("Mismatch");120}121cc++;122}123}124if (cc != kdcs.length - 2) { // 2 illegal settings at the end125throw new Exception("Not traversed");126}127}128}129130131132133