1/*
2 * Copyright (c) 2012, 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
24/*
25 * @test
26 * @bug 8031111
27 * @summary fix krb5 caddr
28 * @compile -XDignore.symbol.file Addresses.java
29 * @run main/othervm Addresses
30 */
31
32import sun.security.krb5.Config;
33
34import javax.security.auth.kerberos.KerberosTicket;
35import java.net.Inet4Address;
36import java.net.InetAddress;
37
38public class Addresses {
39
40    public static void main(String[] args) throws Exception {
41
42        KDC.saveConfig(OneKDC.KRB5_CONF, new OneKDC(null),
43                "noaddresses = false",
44                "extra_addresses = 10.0.0.10, 10.0.0.11 10.0.0.12");
45        Config.refresh();
46
47        KerberosTicket ticket =
48                Context.fromUserPass(OneKDC.USER, OneKDC.PASS, false)
49                        .s().getPrivateCredentials(KerberosTicket.class)
50                        .iterator().next();
51
52        InetAddress loopback = InetAddress.getLoopbackAddress();
53        InetAddress extra1 = InetAddress.getByName("10.0.0.10");
54        InetAddress extra2 = InetAddress.getByName("10.0.0.11");
55        InetAddress extra3 = InetAddress.getByName("10.0.0.12");
56
57        boolean loopbackFound = false;
58        boolean extra1Found = false;
59        boolean extra2Found = false;
60        boolean extra3Found = false;
61        boolean networkFound = false;
62
63        for (InetAddress ia: ticket.getClientAddresses()) {
64            System.out.println(ia);
65            if (ia.equals(loopback)) {
66                loopbackFound = true;
67                System.out.println("  loopback found");
68            } else if (ia.equals(extra1)) {
69                extra1Found = true;
70                System.out.println("  extra1 found");
71            } else if (ia.equals(extra2)) {
72                extra2Found = true;
73                System.out.println("  extra2 found");
74            } else if (ia.equals(extra3)) {
75                extra3Found = true;
76                System.out.println("  extra3 found");
77            } else if (ia instanceof Inet4Address) {
78                networkFound = true;
79                System.out.println("  another address (" + ia +
80                        "), assumed real network");
81            }
82        }
83
84        if (!loopbackFound || !networkFound
85                || !extra1Found || !extra2Found || !extra3Found ) {
86            throw new Exception();
87        }
88    }
89}
90