jdk/test/sun/security/krb5/config/NamingManager.java
author weijun
Mon, 19 Nov 2012 11:13:08 +0800
changeset 14515 f67149f8daf6
child 31420 7ee930c87f08
permissions -rw-r--r--
8002344: Krb5LoginModule config class does not return proper KDC list from DNS Reviewed-by: weijun Contributed-by: Severin Gehwolf <sgehwolf@redhat.com>, Wang Weijun <weijun.wang@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
14515
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
     1
/*
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
     4
 *
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
     8
 *
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    13
 * accompanied this code).
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    14
 *
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    18
 *
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    21
 * questions.
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    22
 */
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    23
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    24
package javax.naming.spi;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    25
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    26
import com.sun.jndi.dns.DnsContext;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    27
import java.util.Hashtable;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    28
import javax.naming.Context;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    29
import javax.naming.NamingException;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    30
import javax.naming.directory.Attribute;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    31
import javax.naming.directory.Attributes;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    32
import javax.naming.directory.BasicAttribute;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    33
import javax.naming.directory.BasicAttributes;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    34
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    35
/**
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    36
 * A fake javax.naming.spi.NamingManager. It allows reading a DNS
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    37
 * record without contacting a real server.
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    38
 *
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    39
 * See DNS.java and dns.sh.
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    40
 */
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    41
public class NamingManager {
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    42
    NamingManager() {}
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    43
    public static Context getURLContext(
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    44
            String scheme, Hashtable<?,?> environment)
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    45
            throws NamingException {
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    46
        return new DnsContext("", null, new Hashtable<String,String>()) {
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    47
            public Attributes getAttributes(String name, String[] attrIds)
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    48
                    throws NamingException {
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    49
                return new BasicAttributes() {
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    50
                    public Attribute get(String attrID) {
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    51
                        BasicAttribute ba  = new BasicAttribute(attrID);
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    52
                        ba.add("1 1 99 b.com.");
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    53
                        ba.add("0 0 88 a.com.");    // 2nd has higher priority
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    54
                        return ba;
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    55
                    }
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    56
                };
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    57
            }
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    58
        };
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    59
    }
f67149f8daf6 8002344: Krb5LoginModule config class does not return proper KDC list from DNS
weijun
parents:
diff changeset
    60
}