Path: blob/master/test/jdk/sun/security/krb5/auto/Addresses.java
41152 views
/*1* Copyright (c) 2012, 2018, 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 8031111 819448626* @summary fix krb5 caddr27* @library /test/lib28* @compile -XDignore.symbol.file Addresses.java29* @run main jdk.test.lib.FileInstaller TestHosts TestHosts30* @run main/othervm -Djdk.net.hosts.file=TestHosts Addresses31*/3233import sun.security.krb5.Config;3435import javax.security.auth.kerberos.KerberosTicket;36import java.net.Inet4Address;37import java.net.InetAddress;3839public class Addresses {4041public static void main(String[] args) throws Exception {4243KDC.saveConfig(OneKDC.KRB5_CONF, new OneKDC(null),44"noaddresses = false",45"extra_addresses = 10.0.0.10, 10.0.0.11 10.0.0.12");46Config.refresh();4748KerberosTicket ticket =49Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false)50.s().getPrivateCredentials(KerberosTicket.class)51.iterator().next();5253InetAddress loopback = InetAddress.getLoopbackAddress();54InetAddress extra1 = InetAddress.getByName("10.0.0.10");55InetAddress extra2 = InetAddress.getByName("10.0.0.11");56InetAddress extra3 = InetAddress.getByName("10.0.0.12");5758boolean loopbackFound = false;59boolean extra1Found = false;60boolean extra2Found = false;61boolean extra3Found = false;62boolean networkFound = false;6364for (InetAddress ia: ticket.getClientAddresses()) {65System.out.println(ia);66if (ia.equals(loopback)) {67loopbackFound = true;68System.out.println(" loopback found");69} else if (ia.equals(extra1)) {70extra1Found = true;71System.out.println(" extra1 found");72} else if (ia.equals(extra2)) {73extra2Found = true;74System.out.println(" extra2 found");75} else if (ia.equals(extra3)) {76extra3Found = true;77System.out.println(" extra3 found");78} else if (ia instanceof Inet4Address) {79networkFound = true;80System.out.println(" another address (" + ia +81"), assumed real network");82}83}8485if (!loopbackFound || !networkFound86|| !extra1Found || !extra2Found || !extra3Found ) {87throw new Exception();88}89}90}919293