sun.net.dns.ResolverConfiguration Java Examples

The following examples show how to use sun.net.dns.ResolverConfiguration. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Config.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #2
Source File: DnsContextFactory.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #3
Source File: Config.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #4
Source File: Config.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #5
Source File: Config.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #6
Source File: DnsContextFactory.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #7
Source File: DnsContextFactory.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #8
Source File: Config.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #9
Source File: Config.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #10
Source File: DnsContextFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #11
Source File: DnsContextFactory.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #12
Source File: DnsContextFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #13
Source File: Config.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #14
Source File: DnsContextFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #15
Source File: DnsContextFactory.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #16
Source File: DnsContextFactory.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #17
Source File: DnsContextFactory.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #18
Source File: Config.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #19
Source File: Config.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #20
Source File: DnsContextFactory.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #21
Source File: Config.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #22
Source File: Config.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #23
Source File: DnsContextFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #24
Source File: DnsContextFactory.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static String[] serversForUrls(DnsUrl[] urls)
        throws NamingException {

    if (urls.length == 0) {
        throw new ConfigurationException("DNS pseudo-URL required");
    }

    List<String> servers = new ArrayList<>();

    for (int i = 0; i < urls.length; i++) {
        String server = urls[i].getHost();
        int port = urls[i].getPort();

        if (server == null && port < 0) {
            // No server or port given, so look to underlying platform.
            // ResolverConfiguration does some limited caching, so the
            // following is reasonably efficient even if called rapid-fire.
            List<String> platformServers = filterNameServers(
                ResolverConfiguration.open().nameservers(), false);
            if (!platformServers.isEmpty()) {
                servers.addAll(platformServers);
                continue;  // on to next URL (if any, which is unlikely)
            }
        }

        if (server == null) {
            server = "localhost";
        }
        servers.add((port < 0)
                    ? server
                    : server + ":" + port);
    }
    return servers.toArray(new String[servers.size()]);
}
 
Example #25
Source File: Config.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #26
Source File: Config.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Locate Kerberos realm using DNS
 *
 * @return the Kerberos realm
 */
private String getRealmFromDNS() throws KrbException {
    // use DNS to locate Kerberos realm
    String realm = null;
    String hostName = null;
    try {
        hostName = InetAddress.getLocalHost().getCanonicalHostName();
    } catch (UnknownHostException e) {
        KrbException ke = new KrbException(Krb5.KRB_ERR_GENERIC,
            "Unable to locate Kerberos realm: " + e.getMessage());
        ke.initCause(e);
        throw (ke);
    }
    // get the domain realm mapping from the configuration
    String mapRealm = PrincipalName.mapHostToRealm(hostName);
    if (mapRealm == null) {
        // No match. Try search and/or domain in /etc/resolv.conf
        List<String> srchlist = ResolverConfiguration.open().searchlist();
        for (String domain: srchlist) {
            realm = checkRealm(domain);
            if (realm != null) {
                break;
            }
        }
    } else {
        realm = checkRealm(mapRealm);
    }
    if (realm == null) {
        throw new KrbException(Krb5.KRB_ERR_GENERIC,
                            "Unable to locate Kerberos realm");
    }
    return realm;
}
 
Example #27
Source File: DnsContextFactory.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
public static boolean platformServersAvailable() {
    return !filterNameServers(
                ResolverConfiguration.open().nameservers(), true
            ).isEmpty();
}
 
Example #28
Source File: DNSNameService.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private DirContext getTemporaryContext() throws NamingException {
    SoftReference<ThreadContext> ref = contextRef.get();
    ThreadContext thrCtxt = null;
    List<String> nsList = null;

    // if no property specified we need to obtain the list of servers
    //
    if (nameProviderUrl == null)
        nsList = ResolverConfiguration.open().nameservers();

    // if soft reference hasn't been gc'ed no property has been
    // specified then we need to check if the DNS configuration
    // has changed.
    //
    if ((ref != null) && ((thrCtxt = ref.get()) != null)) {
        if (nameProviderUrl == null) {
            if (!thrCtxt.nameservers().equals(nsList)) {
                // DNS configuration has changed
                thrCtxt = null;
            }
        }
    }

    // new thread context needs to be created
    if (thrCtxt == null) {
        final Hashtable<String,Object> env = new Hashtable<>();
        env.put("java.naming.factory.initial",
                "com.sun.jndi.dns.DnsContextFactory");

        // If no nameservers property specified we create provider URL
        // based on system configured name servers
        //
        String provUrl = nameProviderUrl;
        if (provUrl == null) {
            provUrl = createProviderURL(nsList);
            if (provUrl.length() == 0) {
                throw new RuntimeException("bad nameserver configuration");
            }
        }
        env.put("java.naming.provider.url", provUrl);

        // Need to create directory context in privileged block
        // as JNDI-DNS needs to resolve the name servers.
        //
        DirContext dirCtxt;
        try {
            dirCtxt = java.security.AccessController.doPrivileged(
                    new java.security.PrivilegedExceptionAction<DirContext>() {
                        public DirContext run() throws NamingException {
                            // Create the DNS context using NamingManager rather than using
                            // the initial context constructor. This avoids having the initial
                            // context constructor call itself.
                            Context ctx = NamingManager.getInitialContext(env);
                            if (!(ctx instanceof DirContext)) {
                                return null; // cannot create a DNS context
                            }
                            return (DirContext)ctx;
                        }
                });
        } catch (java.security.PrivilegedActionException pae) {
            throw (NamingException)pae.getException();
        }

        // create new soft reference to our thread context
        //
        thrCtxt = new ThreadContext(dirCtxt, nsList);
        contextRef.set(new SoftReference<ThreadContext>(thrCtxt));
    }

    return thrCtxt.dirContext();
}
 
Example #29
Source File: DNSNameService.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
private DirContext getTemporaryContext() throws NamingException {
    SoftReference<ThreadContext> ref = contextRef.get();
    ThreadContext thrCtxt = null;
    List<String> nsList = null;

    // if no property specified we need to obtain the list of servers
    //
    if (nameProviderUrl == null)
        nsList = ResolverConfiguration.open().nameservers();

    // if soft reference hasn't been gc'ed no property has been
    // specified then we need to check if the DNS configuration
    // has changed.
    //
    if ((ref != null) && ((thrCtxt = ref.get()) != null)) {
        if (nameProviderUrl == null) {
            if (!thrCtxt.nameservers().equals(nsList)) {
                // DNS configuration has changed
                thrCtxt = null;
            }
        }
    }

    // new thread context needs to be created
    if (thrCtxt == null) {
        final Hashtable<String,Object> env = new Hashtable<>();
        env.put("java.naming.factory.initial",
                "com.sun.jndi.dns.DnsContextFactory");

        // If no nameservers property specified we create provider URL
        // based on system configured name servers
        //
        String provUrl = nameProviderUrl;
        if (provUrl == null) {
            provUrl = createProviderURL(nsList);
            if (provUrl.length() == 0) {
                throw new RuntimeException("bad nameserver configuration");
            }
        }
        env.put("java.naming.provider.url", provUrl);

        // Need to create directory context in privileged block
        // as JNDI-DNS needs to resolve the name servers.
        //
        DirContext dirCtxt;
        try {
            dirCtxt = java.security.AccessController.doPrivileged(
                    new java.security.PrivilegedExceptionAction<DirContext>() {
                        public DirContext run() throws NamingException {
                            // Create the DNS context using NamingManager rather than using
                            // the initial context constructor. This avoids having the initial
                            // context constructor call itself.
                            Context ctx = NamingManager.getInitialContext(env);
                            if (!(ctx instanceof DirContext)) {
                                return null; // cannot create a DNS context
                            }
                            return (DirContext)ctx;
                        }
                });
        } catch (java.security.PrivilegedActionException pae) {
            throw (NamingException)pae.getException();
        }

        // create new soft reference to our thread context
        //
        thrCtxt = new ThreadContext(dirCtxt, nsList);
        contextRef.set(new SoftReference<ThreadContext>(thrCtxt));
    }

    return thrCtxt.dirContext();
}
 
Example #30
Source File: DnsContextFactory.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
public static boolean platformServersAvailable() {
    return !filterNameServers(
                ResolverConfiguration.open().nameservers(), true
            ).isEmpty();
}