/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* This class discovers the location of LDAP services by querying DNS.
*/
class ServiceLocator {
private ServiceLocator() {
}
/**
* Maps a distinguished name (RFC 2253) to a fully qualified domain name.
* Processes a sequence of RDNs having a DC attribute.
* The special RDN "DC=." denotes the root of the domain tree.
* Multi-valued RDNs, non-DC attributes, binary-valued attributes and the
* RDN "DC=." all reset the domain name and processing continues.
*
* @param dn A string distinguished name (RFC 2253).
* @return A domain name or null if none can be derived.
* @throw InvalidNameException If the distinugished name is invalid.
*/
return null;
}
// process RDNs left-to-right
//List<Rdn> rdnList = ldapName.getRdns();
//Rdn rdn = rdnList.get(i);
// single-valued RDN with a DC attribute
// RDN value is "DC=.")
}
}
} else {
}
} else {
}
}
}
/**
* Locates the LDAP service for a given domain.
* Queries DNS for a list of LDAP Service Location Records (SRV) for a
* given domain name.
*
* @param domainName A string domain name.
* @param environment The possibly null environment of the context.
* @return An ordered list of hostports for the LDAP service or null if
* the service has not been located.
*/
return null;
}
try {
// Create the DNS context using NamingManager rather than using
// the initial context constructor. This avoids having the initial
// context constructor call itself (when processing the URL
// argument in the getAttributes call).
if (!(ctx instanceof DirContext)) {
return null; // cannot create a DNS context
}
int numRecords = 0;
// create the service records
int i = 0;
int j = 0;
while (i < numValues) {
try {
j++;
} catch (Exception e) {
// ignore bad value
}
i++;
}
numRecords = j;
// trim
if (numRecords < numValues) {
}
// Sort the service records in ascending order of their
// priority value. For records with equal priority, move
// those with weight 0 to the top of the list.
if (numRecords > 1) {
}
// extract the host and port number from each service record
}
} catch (NamingException e) {
// ignore
}
return hostports;
}
/**
* Extract hosts and port numbers from a list of SRV records.
* An array of hostports is returned or null if none were found.
*/
int head = 0;
int tail = 0;
int sublistLength = 0;
int k = 0;
}
// find the head and tail of the list of records having the same
// priority value.
head = i;
i++;
}
tail = i;
// select hostports from the sublist
for (int j = 0; j < sublistLength; j++) {
}
}
return hostports;
}
/*
* Randomly select a service record in the range [head, tail] and return
* its hostport value. Follows the algorithm in RFC 2782.
*/
int tail) {
}
// compute the running sum for records between head and tail
int sum = 0;
if (srvRecords[i] != null) {
}
}
// If all records have zero weight, select first available one;
// otherwise, randomly select a record according to its weight
break;
}
}
return hostport;
}
/**
* This class holds a DNS service (SRV) record.
*/
int priority;
int weight;
int sum;
/**
* Creates a service record object from a string record.
* DNS supplies the string record in the following format:
* <pre>
* <Priority> " " <Weight> " " <Port> " " <Host>
* </pre>
*/
} else {
throw new IllegalArgumentException();
}
}
/*
* Sort records in ascending order of priority value. For records with
* equal priority move those with weight 0 to the top of the list.
*/
return 1; // this > that
return -1; // this < that
return -1; // this < that
return 1; // this > that
} else {
return 0; // this == that
}
}
}
}