jdk/src/share/classes/sun/security/krb5/KrbServiceLocator.java
changeset 10336 0bb1999251f8
parent 5506 202f599c92aa
equal deleted inserted replaced
10335:3c7eda3ab2f5 10336:0bb1999251f8
     1 /*
     1 /*
     2  * Copyright (c) 2006, 2009, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2006, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    24  */
    24  */
    25 
    25 
    26 package sun.security.krb5;
    26 package sun.security.krb5;
    27 
    27 
    28 import java.util.Arrays;
    28 import java.util.Arrays;
    29 import java.util.Enumeration;
       
    30 import java.util.Hashtable;
    29 import java.util.Hashtable;
    31 import java.util.NoSuchElementException;
       
    32 import java.util.Random;
    30 import java.util.Random;
    33 import java.util.StringTokenizer;
    31 import java.util.StringTokenizer;
    34 import java.util.List;
       
    35 
    32 
    36 import javax.naming.*;
    33 import javax.naming.*;
    37 import javax.naming.directory.*;
    34 import javax.naming.directory.*;
    38 import javax.naming.spi.NamingManager;
    35 import javax.naming.spi.NamingManager;
    39 
    36 
    78         try {
    75         try {
    79             // Create the DNS context using NamingManager rather than using
    76             // Create the DNS context using NamingManager rather than using
    80             // the initial context constructor. This avoids having the initial
    77             // the initial context constructor. This avoids having the initial
    81             // context constructor call itself (when processing the URL
    78             // context constructor call itself (when processing the URL
    82             // argument in the getAttributes call).
    79             // argument in the getAttributes call).
    83             Context ctx = NamingManager.getURLContext("dns", new Hashtable(0));
    80             Context ctx = NamingManager.getURLContext("dns", new Hashtable<>(0));
    84             if (!(ctx instanceof DirContext)) {
    81             if (!(ctx instanceof DirContext)) {
    85                 return null; // cannot create a DNS context
    82                 return null; // cannot create a DNS context
    86             }
    83             }
    87             Attributes attrs =
    84             Attributes attrs =
    88                 ((DirContext)ctx).getAttributes(dnsUrl, SRV_TXT_ATTR);
    85                 ((DirContext)ctx).getAttributes(dnsUrl, SRV_TXT_ATTR);
   139         try {
   136         try {
   140             // Create the DNS context using NamingManager rather than using
   137             // Create the DNS context using NamingManager rather than using
   141             // the initial context constructor. This avoids having the initial
   138             // the initial context constructor. This avoids having the initial
   142             // context constructor call itself (when processing the URL
   139             // context constructor call itself (when processing the URL
   143             // argument in the getAttributes call).
   140             // argument in the getAttributes call).
   144             Context ctx = NamingManager.getURLContext("dns", new Hashtable(0));
   141             Context ctx = NamingManager.getURLContext("dns", new Hashtable<>(0));
   145             if (!(ctx instanceof DirContext)) {
   142             if (!(ctx instanceof DirContext)) {
   146                 return null; // cannot create a DNS context
   143                 return null; // cannot create a DNS context
   147             }
   144             }
   148             Attributes attrs =
   145             Attributes attrs =
   149                 ((DirContext)ctx).getAttributes(dnsUrl, SRV_RR_ATTR);
   146                 ((DirContext)ctx).getAttributes(dnsUrl, SRV_RR_ATTR);
   261 /**
   258 /**
   262  * This class holds a DNS service (SRV) record.
   259  * This class holds a DNS service (SRV) record.
   263  * See http://www.ietf.org/rfc/rfc2782.txt
   260  * See http://www.ietf.org/rfc/rfc2782.txt
   264  */
   261  */
   265 
   262 
   266 static class SrvRecord implements Comparable {
   263 static class SrvRecord implements Comparable<SrvRecord> {
   267 
   264 
   268     int priority;
   265     int priority;
   269     int weight;
   266     int weight;
   270     int sum;
   267     int sum;
   271     String hostport;
   268     String hostport;
   293 
   290 
   294     /*
   291     /*
   295      * Sort records in ascending order of priority value. For records with
   292      * Sort records in ascending order of priority value. For records with
   296      * equal priority move those with weight 0 to the top of the list.
   293      * equal priority move those with weight 0 to the top of the list.
   297      */
   294      */
   298     public int compareTo(Object o) {
   295     public int compareTo(SrvRecord that) {
   299         SrvRecord that = (SrvRecord) o;
       
   300         if (priority > that.priority) {
   296         if (priority > that.priority) {
   301             return 1; // this > that
   297             return 1; // this > that
   302         } else if (priority < that.priority) {
   298         } else if (priority < that.priority) {
   303             return -1; // this < that
   299             return -1; // this < that
   304         } else if (weight == 0 && that.weight != 0) {
   300         } else if (weight == 0 && that.weight != 0) {