提交 3633c027 编写于 作者: J jjg

7072353: JNDI libraries do not build with javac -Xlint:all -Werror

Reviewed-by: xuelei
Contributed-by: alexandre.boulgakov@oracle.com
上级 f40d1f5d
# #
# Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -28,6 +28,8 @@ ...@@ -28,6 +28,8 @@
# #
BUILDDIR = ../../.. BUILDDIR = ../../..
SUBDIRS_MAKEFLAGS += JAVAC_MAX_WARNINGS=true
SUBDIRS_MAKEFLAGS += JAVAC_WARNINGS_FATAL=true
include $(BUILDDIR)/common/Defs.gmk include $(BUILDDIR)/common/Defs.gmk
SUBDIRS = toolkit cosnaming ldap rmi dns SUBDIRS = toolkit cosnaming ldap rmi dns
......
# #
# Copyright (c) 1998, 2008, Oracle and/or its affiliates. All rights reserved. # Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
# #
# This code is free software; you can redistribute it and/or modify it # This code is free software; you can redistribute it and/or modify it
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
# #
BUILDDIR = ../.. BUILDDIR = ../..
JAVAC_MAX_WARNINGS = true
include $(BUILDDIR)/common/Defs.gmk include $(BUILDDIR)/common/Defs.gmk
# #
......
/* /*
* Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -32,8 +32,6 @@ import java.util.NoSuchElementException; ...@@ -32,8 +32,6 @@ import java.util.NoSuchElementException;
import java.util.Hashtable; import java.util.Hashtable;
import org.omg.CosNaming.*; import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
/** /**
* Implements the JNDI NamingEnumeration interface for COS * Implements the JNDI NamingEnumeration interface for COS
...@@ -44,7 +42,8 @@ import org.omg.CORBA.*; ...@@ -44,7 +42,8 @@ import org.omg.CORBA.*;
* @author Rosanna Lee * @author Rosanna Lee
*/ */
final class CNBindingEnumeration implements NamingEnumeration { final class CNBindingEnumeration
implements NamingEnumeration<javax.naming.Binding> {
private static final int DEFAULT_BATCHSIZE = 100; private static final int DEFAULT_BATCHSIZE = 100;
private BindingListHolder _bindingList; // list of bindings private BindingListHolder _bindingList; // list of bindings
...@@ -52,105 +51,105 @@ final class CNBindingEnumeration implements NamingEnumeration { ...@@ -52,105 +51,105 @@ final class CNBindingEnumeration implements NamingEnumeration {
private int counter; // pointer in _bindingList private int counter; // pointer in _bindingList
private int batchsize = DEFAULT_BATCHSIZE; // how many to ask for each time private int batchsize = DEFAULT_BATCHSIZE; // how many to ask for each time
private CNCtx _ctx; // ctx to list private CNCtx _ctx; // ctx to list
private Hashtable _env; // environment for getObjectInstance private Hashtable<?,?> _env; // environment for getObjectInstance
private boolean more = false; // iterator done? private boolean more = false; // iterator done?
private boolean isLookedUpCtx = false; // iterating on a context beneath this context ? private boolean isLookedUpCtx = false; // iterating on a context beneath this context ?
/** /**
* Creates a CNBindingEnumeration object. * Creates a CNBindingEnumeration object.
* @param ctx Context to enumerate * @param ctx Context to enumerate
*/ */
CNBindingEnumeration(CNCtx ctx, boolean isLookedUpCtx, Hashtable env) { CNBindingEnumeration(CNCtx ctx, boolean isLookedUpCtx, Hashtable<?,?> env) {
// Get batch size to use // Get batch size to use
String batch = (env != null ? String batch = (env != null ?
(String)env.get(javax.naming.Context.BATCHSIZE) : null); (String)env.get(javax.naming.Context.BATCHSIZE) : null);
if (batch != null) { if (batch != null) {
try { try {
batchsize = Integer.parseInt(batch); batchsize = Integer.parseInt(batch);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {
throw new IllegalArgumentException("Batch size not numeric: " + batch); throw new IllegalArgumentException("Batch size not numeric: " + batch);
}
} }
_ctx = ctx;
_ctx.incEnumCount();
this.isLookedUpCtx = isLookedUpCtx;
_env = env;
_bindingList = new BindingListHolder();
BindingIteratorHolder _bindingIterH = new BindingIteratorHolder();
// Perform listing and request that bindings be returned in _bindingIter
// Upon return,_bindingList returns a zero length list
_ctx._nc.list(0, _bindingList, _bindingIterH);
_bindingIter = _bindingIterH.value;
// Get first batch using _bindingIter
if (_bindingIter != null) {
more = _bindingIter.next_n(batchsize, _bindingList);
} else {
more = false;
}
counter = 0;
} }
_ctx = ctx;
_ctx.incEnumCount(); /**
this.isLookedUpCtx = isLookedUpCtx; * Returns the next binding in the list.
_env = env; * @exception NamingException any naming exception.
_bindingList = new BindingListHolder(); */
BindingIteratorHolder _bindingIterH = new BindingIteratorHolder();
public javax.naming.Binding next() throws NamingException {
// Perform listing and request that bindings be returned in _bindingIter if (more && counter >= _bindingList.value.length) {
// Upon return,_bindingList returns a zero length list getMore();
_ctx._nc.list(0, _bindingList, _bindingIterH); }
if (more && counter < _bindingList.value.length) {
_bindingIter = _bindingIterH.value; org.omg.CosNaming.Binding bndg = _bindingList.value[counter];
counter++;
// Get first batch using _bindingIter return mapBinding(bndg);
if (_bindingIter != null) { } else {
more = _bindingIter.next_n(batchsize, _bindingList); throw new NoSuchElementException();
} else { }
more = false;
} }
counter = 0;
}
/**
* Returns the next binding in the list.
* @exception NamingException any naming exception.
*/
public java.lang.Object next() throws NamingException { /**
if (more && counter >= _bindingList.value.length) {
getMore();
}
if (more && counter < _bindingList.value.length) {
org.omg.CosNaming.Binding bndg = _bindingList.value[counter];
counter++;
return mapBinding(bndg);
} else {
throw new NoSuchElementException();
}
}
/**
* Returns true or false depending on whether there are more bindings. * Returns true or false depending on whether there are more bindings.
* @return boolean value * @return boolean value
*/ */
public boolean hasMore() throws NamingException { public boolean hasMore() throws NamingException {
// If there's more, check whether current bindingList has been exhausted, // If there's more, check whether current bindingList has been exhausted,
// and if so, try to get more. // and if so, try to get more.
// If no more, just say so. // If no more, just say so.
return more ? (counter < _bindingList.value.length || getMore()) : false; return more ? (counter < _bindingList.value.length || getMore()) : false;
} }
/** /**
* Returns true or false depending on whether there are more bindings. * Returns true or false depending on whether there are more bindings.
* Need to define this to satisfy the Enumeration api requirement. * Need to define this to satisfy the Enumeration api requirement.
* @return boolean value * @return boolean value
*/ */
public boolean hasMoreElements() { public boolean hasMoreElements() {
try { try {
return hasMore(); return hasMore();
} catch (NamingException e) { } catch (NamingException e) {
return false; return false;
} }
} }
/** /**
* Returns the next binding in the list. * Returns the next binding in the list.
* @exception NoSuchElementException Thrown when the end of the * @exception NoSuchElementException Thrown when the end of the
* list is reached. * list is reached.
*/ */
public java.lang.Object nextElement() { public javax.naming.Binding nextElement() {
try { try {
return next(); return next();
} catch (NamingException ne) { } catch (NamingException ne) {
throw new NoSuchElementException(); throw new NoSuchElementException();
} }
} }
public void close() throws NamingException { public void close() throws NamingException {
more = false; more = false;
...@@ -197,7 +196,7 @@ final class CNBindingEnumeration implements NamingEnumeration { ...@@ -197,7 +196,7 @@ final class CNBindingEnumeration implements NamingEnumeration {
return more; return more;
} }
/** /**
* Constructs a JNDI Binding object from the COS Naming binding * Constructs a JNDI Binding object from the COS Naming binding
* object. * object.
* @exception NameNotFound No objects under the name. * @exception NameNotFound No objects under the name.
...@@ -232,5 +231,5 @@ final class CNBindingEnumeration implements NamingEnumeration { ...@@ -232,5 +231,5 @@ final class CNBindingEnumeration implements NamingEnumeration {
String fullName = CNNameParser.cosNameToInsString(comps); String fullName = CNNameParser.cosNameToInsString(comps);
jbndg.setNameInNamespace(fullName); jbndg.setNameInNamespace(fullName);
return jbndg; return jbndg;
} }
} }
/* /*
* Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,7 +30,6 @@ import javax.naming.spi.NamingManager; ...@@ -30,7 +30,6 @@ import javax.naming.spi.NamingManager;
import javax.naming.spi.ResolveResult; import javax.naming.spi.ResolveResult;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.io.InputStream; import java.io.InputStream;
...@@ -63,7 +62,7 @@ public class CNCtx implements javax.naming.Context { ...@@ -63,7 +62,7 @@ public class CNCtx implements javax.naming.Context {
public NamingContext _nc; // public for accessing underlying NamingContext public NamingContext _nc; // public for accessing underlying NamingContext
private NameComponent[] _name = null; private NameComponent[] _name = null;
Hashtable _env; // used by ExceptionMapper Hashtable<String, java.lang.Object> _env; // used by ExceptionMapper
static final CNNameParser parser = new CNNameParser(); static final CNNameParser parser = new CNNameParser();
private static final String FED_PROP = "com.sun.jndi.cosnaming.federation"; private static final String FED_PROP = "com.sun.jndi.cosnaming.federation";
...@@ -82,11 +81,12 @@ public class CNCtx implements javax.naming.Context { ...@@ -82,11 +81,12 @@ public class CNCtx implements javax.naming.Context {
* @param env Environment properties for initializing name service. * @param env Environment properties for initializing name service.
* @exception NamingException Cannot initialize ORB or naming context. * @exception NamingException Cannot initialize ORB or naming context.
*/ */
CNCtx(Hashtable env) throws NamingException { @SuppressWarnings("unchecked")
CNCtx(Hashtable<?,?> env) throws NamingException {
if (env != null) { if (env != null) {
env = (Hashtable) env.clone(); env = (Hashtable<?,?>)env.clone();
} }
_env = env; _env = (Hashtable<String, java.lang.Object>)env;
federation = "true".equals(env != null ? env.get(FED_PROP) : null); federation = "true".equals(env != null ? env.get(FED_PROP) : null);
initOrbAndRootContext(env); initOrbAndRootContext(env);
} }
...@@ -97,13 +97,14 @@ public class CNCtx implements javax.naming.Context { ...@@ -97,13 +97,14 @@ public class CNCtx implements javax.naming.Context {
/** /**
* This method is used by the iiop and iiopname URL Context factories. * This method is used by the iiop and iiopname URL Context factories.
*/ */
public static ResolveResult createUsingURL(String url, Hashtable env) @SuppressWarnings("unchecked")
public static ResolveResult createUsingURL(String url, Hashtable<?,?> env)
throws NamingException { throws NamingException {
CNCtx ctx = new CNCtx(); CNCtx ctx = new CNCtx();
if (env != null) { if (env != null) {
env = (Hashtable) env.clone(); env = (Hashtable<?,?>) env.clone();
} }
ctx._env = env; ctx._env = (Hashtable<String, java.lang.Object>)env;
String rest = ctx.initUsingUrl( String rest = ctx.initUsingUrl(
env != null ? env != null ?
(org.omg.CORBA.ORB) env.get("java.naming.corba.orb") (org.omg.CORBA.ORB) env.get("java.naming.corba.orb")
...@@ -128,8 +129,8 @@ public class CNCtx implements javax.naming.Context { ...@@ -128,8 +129,8 @@ public class CNCtx implements javax.naming.Context {
* @param name The name of this context relative to the root * @param name The name of this context relative to the root
*/ */
CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx, Hashtable env, CNCtx(ORB orb, OrbReuseTracker tracker, NamingContext nctx,
NameComponent[]name) Hashtable<String, java.lang.Object> env, NameComponent[]name)
throws NamingException { throws NamingException {
if (orb == null || nctx == null) if (orb == null || nctx == null)
throw new ConfigurationException( throw new ConfigurationException(
...@@ -207,7 +208,7 @@ public class CNCtx implements javax.naming.Context { ...@@ -207,7 +208,7 @@ public class CNCtx implements javax.naming.Context {
* @exception NamingException When an error occurs while initializing the * @exception NamingException When an error occurs while initializing the
* ORB or the naming context. * ORB or the naming context.
*/ */
private void initOrbAndRootContext(Hashtable env) throws NamingException { private void initOrbAndRootContext(Hashtable<?,?> env) throws NamingException {
org.omg.CORBA.ORB inOrb = null; org.omg.CORBA.ORB inOrb = null;
String ncIor = null; String ncIor = null;
...@@ -240,7 +241,7 @@ public class CNCtx implements javax.naming.Context { ...@@ -240,7 +241,7 @@ public class CNCtx implements javax.naming.Context {
// If name supplied in URL, resolve it to a NamingContext // If name supplied in URL, resolve it to a NamingContext
if (insName.length() > 0) { if (insName.length() > 0) {
_name = parser.nameToCosName(parser.parse(insName)); _name = CNNameParser.nameToCosName(parser.parse(insName));
try { try {
org.omg.CORBA.Object obj = _nc.resolve(_name); org.omg.CORBA.Object obj = _nc.resolve(_name);
_nc = NamingContextHelper.narrow(obj); _nc = NamingContextHelper.narrow(obj);
...@@ -271,7 +272,7 @@ public class CNCtx implements javax.naming.Context { ...@@ -271,7 +272,7 @@ public class CNCtx implements javax.naming.Context {
} }
private String initUsingUrl(ORB orb, String url, Hashtable env) private String initUsingUrl(ORB orb, String url, Hashtable<?,?> env)
throws NamingException { throws NamingException {
if (url.startsWith("iiop://") || url.startsWith("iiopname://")) { if (url.startsWith("iiop://") || url.startsWith("iiopname://")) {
return initUsingIiopUrl(orb, url, env); return initUsingIiopUrl(orb, url, env);
...@@ -283,17 +284,14 @@ public class CNCtx implements javax.naming.Context { ...@@ -283,17 +284,14 @@ public class CNCtx implements javax.naming.Context {
/** /**
* Handles "iiop" and "iiopname" URLs (INS 98-10-11) * Handles "iiop" and "iiopname" URLs (INS 98-10-11)
*/ */
private String initUsingIiopUrl(ORB defOrb, String url, Hashtable env) private String initUsingIiopUrl(ORB defOrb, String url, Hashtable<?,?> env)
throws NamingException { throws NamingException {
try { try {
IiopUrl parsedUrl = new IiopUrl(url); IiopUrl parsedUrl = new IiopUrl(url);
Vector addrs = parsedUrl.getAddresses();
IiopUrl.Address addr;
NamingException savedException = null; NamingException savedException = null;
for (int i = 0; i < addrs.size(); i++) { for (IiopUrl.Address addr : parsedUrl.getAddresses()) {
addr = (IiopUrl.Address)addrs.elementAt(i);
try { try {
if (defOrb != null) { if (defOrb != null) {
...@@ -341,7 +339,7 @@ public class CNCtx implements javax.naming.Context { ...@@ -341,7 +339,7 @@ public class CNCtx implements javax.naming.Context {
/** /**
* Initializes using "corbaname" URL (INS 99-12-03) * Initializes using "corbaname" URL (INS 99-12-03)
*/ */
private String initUsingCorbanameUrl(ORB orb, String url, Hashtable env) private String initUsingCorbanameUrl(ORB orb, String url, Hashtable<?,?> env)
throws NamingException { throws NamingException {
try { try {
CorbanameUrl parsedUrl = new CorbanameUrl(url); CorbanameUrl parsedUrl = new CorbanameUrl(url);
...@@ -731,7 +729,7 @@ public class CNCtx implements javax.naming.Context { ...@@ -731,7 +729,7 @@ public class CNCtx implements javax.naming.Context {
// as per JNDI spec // as per JNDI spec
if (leafNotFound(e, path[path.length-1])) { if (leafNotFound(e, path[path.length-1])) {
; // do nothing // do nothing
} else { } else {
throw ExceptionMapper.mapException(e, this, path); throw ExceptionMapper.mapException(e, this, path);
} }
...@@ -829,7 +827,7 @@ public class CNCtx implements javax.naming.Context { ...@@ -829,7 +827,7 @@ public class CNCtx implements javax.naming.Context {
* with a non-null argument * with a non-null argument
* @return a list of name-class objects as a NameClassEnumeration. * @return a list of name-class objects as a NameClassEnumeration.
*/ */
public NamingEnumeration list(String name) throws NamingException { public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
return list(new CompositeName(name)); return list(new CompositeName(name));
} }
...@@ -840,9 +838,10 @@ public class CNCtx implements javax.naming.Context { ...@@ -840,9 +838,10 @@ public class CNCtx implements javax.naming.Context {
* @exception NamingException All exceptions thrown by lookup * @exception NamingException All exceptions thrown by lookup
* @return a list of name-class objects as a NameClassEnumeration. * @return a list of name-class objects as a NameClassEnumeration.
*/ */
public NamingEnumeration list(Name name) @SuppressWarnings("unchecked")
public NamingEnumeration<NameClassPair> list(Name name)
throws NamingException { throws NamingException {
return listBindings(name); return (NamingEnumeration)listBindings(name);
} }
/** /**
...@@ -852,7 +851,7 @@ public class CNCtx implements javax.naming.Context { ...@@ -852,7 +851,7 @@ public class CNCtx implements javax.naming.Context {
* @exception NamingException all exceptions returned by lookup * @exception NamingException all exceptions returned by lookup
* @return a list of bindings as a BindingEnumeration. * @return a list of bindings as a BindingEnumeration.
*/ */
public NamingEnumeration listBindings(String name) public NamingEnumeration<javax.naming.Binding> listBindings(String name)
throws NamingException { throws NamingException {
return listBindings(new CompositeName(name)); return listBindings(new CompositeName(name));
} }
...@@ -864,7 +863,7 @@ public class CNCtx implements javax.naming.Context { ...@@ -864,7 +863,7 @@ public class CNCtx implements javax.naming.Context {
* @exception NamingException all exceptions returned by lookup. * @exception NamingException all exceptions returned by lookup.
* @return a list of bindings as a BindingEnumeration. * @return a list of bindings as a BindingEnumeration.
*/ */
public NamingEnumeration listBindings(Name name) public NamingEnumeration<javax.naming.Binding> listBindings(Name name)
throws NamingException { throws NamingException {
if (_nc == null) if (_nc == null)
throw new ConfigurationException( throw new ConfigurationException(
...@@ -1064,11 +1063,12 @@ public class CNCtx implements javax.naming.Context { ...@@ -1064,11 +1063,12 @@ public class CNCtx implements javax.naming.Context {
* Returns the current environment. * Returns the current environment.
* @return Environment. * @return Environment.
*/ */
public Hashtable getEnvironment() throws NamingException { @SuppressWarnings("unchecked")
public Hashtable<String, java.lang.Object> getEnvironment() throws NamingException {
if (_env == null) { if (_env == null) {
return new Hashtable(5, 0.75f); return new Hashtable<>(5, 0.75f);
} else { } else {
return (Hashtable)_env.clone(); return (Hashtable<String, java.lang.Object>)_env.clone();
} }
} }
...@@ -1090,25 +1090,27 @@ public class CNCtx implements javax.naming.Context { ...@@ -1090,25 +1090,27 @@ public class CNCtx implements javax.naming.Context {
* @param propVal The ORB. * @param propVal The ORB.
* @return the previous value of this property if any. * @return the previous value of this property if any.
*/ */
@SuppressWarnings("unchecked")
public java.lang.Object addToEnvironment(String propName, public java.lang.Object addToEnvironment(String propName,
java.lang.Object propValue) java.lang.Object propValue)
throws NamingException { throws NamingException {
if (_env == null) { if (_env == null) {
_env = new Hashtable(7, 0.75f); _env = new Hashtable<>(7, 0.75f);
} else { } else {
// copy-on-write // copy-on-write
_env = (Hashtable)_env.clone(); _env = (Hashtable<String, java.lang.Object>)_env.clone();
} }
return _env.put(propName, propValue); return _env.put(propName, propValue);
} }
// Record change but do not reinitialize ORB // Record change but do not reinitialize ORB
@SuppressWarnings("unchecked")
public java.lang.Object removeFromEnvironment(String propName) public java.lang.Object removeFromEnvironment(String propName)
throws NamingException { throws NamingException {
if (_env != null && _env.get(propName) != null) { if (_env != null && _env.get(propName) != null) {
// copy-on-write // copy-on-write
_env = (Hashtable)_env.clone(); _env = (Hashtable<String, java.lang.Object>)_env.clone();
return _env.remove(propName); return _env.remove(propName);
} }
return null; return null;
......
/* /*
* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -67,7 +67,7 @@ final public class CNNameParser implements NameParser { ...@@ -67,7 +67,7 @@ final public class CNNameParser implements NameParser {
* @return a non-null CompoundName * @return a non-null CompoundName
*/ */
public Name parse(String name) throws NamingException { public Name parse(String name) throws NamingException {
Vector comps = insStringToStringifiedComps(name); Vector<String> comps = insStringToStringifiedComps(name);
return new CNCompoundName(comps.elements()); return new CNCompoundName(comps.elements());
} }
...@@ -128,11 +128,11 @@ final public class CNNameParser implements NameParser { ...@@ -128,11 +128,11 @@ final public class CNNameParser implements NameParser {
* each element of the vector contains a stringified form of * each element of the vector contains a stringified form of
* a NameComponent. * a NameComponent.
*/ */
private static Vector insStringToStringifiedComps(String str) private static Vector<String> insStringToStringifiedComps(String str)
throws InvalidNameException { throws InvalidNameException {
int len = str.length(); int len = str.length();
Vector components = new Vector(10); Vector<String> components = new Vector<>(10);
char[] id = new char[len]; char[] id = new char[len];
char[] kind = new char[len]; char[] kind = new char[len];
int idCount, kindCount; int idCount, kindCount;
...@@ -306,7 +306,7 @@ final public class CNNameParser implements NameParser { ...@@ -306,7 +306,7 @@ final public class CNNameParser implements NameParser {
* and stringifying code of the default CompoundName. * and stringifying code of the default CompoundName.
*/ */
static final class CNCompoundName extends CompoundName { static final class CNCompoundName extends CompoundName {
CNCompoundName(Enumeration enum_) { CNCompoundName(Enumeration<String> enum_) {
super(enum_, CNNameParser.mySyntax); super(enum_, CNNameParser.mySyntax);
} }
...@@ -315,12 +315,12 @@ final public class CNNameParser implements NameParser { ...@@ -315,12 +315,12 @@ final public class CNNameParser implements NameParser {
} }
public Name getPrefix(int posn) { public Name getPrefix(int posn) {
Enumeration comps = super.getPrefix(posn).getAll(); Enumeration<String> comps = super.getPrefix(posn).getAll();
return new CNCompoundName(comps); return new CNCompoundName(comps);
} }
public Name getSuffix(int posn) { public Name getSuffix(int posn) {
Enumeration comps = super.getSuffix(posn).getAll(); Enumeration<String> comps = super.getSuffix(posn).getAll();
return new CNCompoundName(comps); return new CNCompoundName(comps);
} }
......
/* /*
* Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -102,10 +102,10 @@ public final class ExceptionMapper { ...@@ -102,10 +102,10 @@ public final class ExceptionMapper {
private static final NamingException tryFed(NotFound e, CNCtx ctx, private static final NamingException tryFed(NotFound e, CNCtx ctx,
NameComponent[] inputName) throws NamingException { NameComponent[] inputName) throws NamingException {
NameComponent[] rest = ((NotFound) e).rest_of_name; NameComponent[] rest = e.rest_of_name;
if (debug) { if (debug) {
System.out.println(((NotFound)e).why.value()); System.out.println(e.why.value());
System.out.println(rest.length); System.out.println(rest.length);
} }
......
/* /*
* Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -68,7 +68,7 @@ public final class IiopUrl { ...@@ -68,7 +68,7 @@ public final class IiopUrl {
static final private int DEFAULT_IIOPNAME_PORT = 9999; static final private int DEFAULT_IIOPNAME_PORT = 9999;
static final private int DEFAULT_IIOP_PORT = 900; static final private int DEFAULT_IIOP_PORT = 900;
static final private String DEFAULT_HOST = "localhost"; static final private String DEFAULT_HOST = "localhost";
private Vector addresses; private Vector<Address> addresses;
private String stringName; private String stringName;
public static class Address { public static class Address {
...@@ -149,7 +149,7 @@ public final class IiopUrl { ...@@ -149,7 +149,7 @@ public final class IiopUrl {
} }
} }
public Vector getAddresses() { public Vector<Address> getAddresses() {
return addresses; return addresses;
} }
...@@ -185,7 +185,7 @@ public final class IiopUrl { ...@@ -185,7 +185,7 @@ public final class IiopUrl {
} else { } else {
stringName = UrlUtil.decode(url.substring(addrEnd+1)); stringName = UrlUtil.decode(url.substring(addrEnd+1));
} }
addresses = new Vector(3); addresses = new Vector<>(3);
if (oldFormat) { if (oldFormat) {
// Only one host:port part, not multiple // Only one host:port part, not multiple
addresses.addElement( addresses.addElement(
......
/* /*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -524,7 +524,7 @@ public class DnsClient { ...@@ -524,7 +524,7 @@ public class DnsClient {
"\tResponse Q:" + resps); "\tResponse Q:" + resps);
} }
byte[] pkt; byte[] pkt;
if ((pkt = (byte[]) resps.get(xid)) != null) { if ((pkt = resps.get(xid)) != null) {
checkResponseCode(new Header(pkt, pkt.length)); checkResponseCode(new Header(pkt, pkt.length));
synchronized (queuesLock) { synchronized (queuesLock) {
resps.remove(xid); resps.remove(xid);
......
/* /*
* Copyright (c) 2000, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -47,7 +47,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -47,7 +47,7 @@ public class DnsContext extends ComponentDirContext {
DnsName domain; // fully-qualified domain name of this context, DnsName domain; // fully-qualified domain name of this context,
// with a root (empty) label at position 0 // with a root (empty) label at position 0
Hashtable environment; Hashtable<Object,Object> environment;
private boolean envShared; // true if environment is possibly shared private boolean envShared; // true if environment is possibly shared
// and so must be copied on write // and so must be copied on write
private boolean parentIsDns; // was this DnsContext created by private boolean parentIsDns; // was this DnsContext created by
...@@ -95,14 +95,15 @@ public class DnsContext extends ComponentDirContext { ...@@ -95,14 +95,15 @@ public class DnsContext extends ComponentDirContext {
* There must be at least one server. * There must be at least one server.
* The environment must not be null; it is cloned before being stored. * The environment must not be null; it is cloned before being stored.
*/ */
public DnsContext(String domain, String[] servers, Hashtable environment) @SuppressWarnings("unchecked")
public DnsContext(String domain, String[] servers, Hashtable<?,?> environment)
throws NamingException { throws NamingException {
this.domain = new DnsName(domain.endsWith(".") this.domain = new DnsName(domain.endsWith(".")
? domain ? domain
: domain + "."); : domain + ".");
this.servers = servers; this.servers = servers;
this.environment = (Hashtable) environment.clone(); this.environment = (Hashtable<Object,Object>) environment.clone();
envShared = false; envShared = false;
parentIsDns = false; parentIsDns = false;
resolver = null; resolver = null;
...@@ -154,14 +155,15 @@ public class DnsContext extends ComponentDirContext { ...@@ -154,14 +155,15 @@ public class DnsContext extends ComponentDirContext {
/* /*
* Override default with a noncloning version. * Override default with a noncloning version.
*/ */
protected Hashtable p_getEnvironment() { protected Hashtable<?,?> p_getEnvironment() {
return environment; return environment;
} }
public Hashtable getEnvironment() throws NamingException { public Hashtable<?,?> getEnvironment() throws NamingException {
return (Hashtable) environment.clone(); return (Hashtable<?,?>) environment.clone();
} }
@SuppressWarnings("unchecked")
public Object addToEnvironment(String propName, Object propVal) public Object addToEnvironment(String propName, Object propVal)
throws NamingException { throws NamingException {
...@@ -189,7 +191,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -189,7 +191,7 @@ public class DnsContext extends ComponentDirContext {
return environment.put(propName, propVal); return environment.put(propName, propVal);
} else if (environment.get(propName) != propVal) { } else if (environment.get(propName) != propVal) {
// copy on write // copy on write
environment = (Hashtable) environment.clone(); environment = (Hashtable<Object,Object>) environment.clone();
envShared = false; envShared = false;
return environment.put(propName, propVal); return environment.put(propName, propVal);
} else { } else {
...@@ -197,6 +199,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -197,6 +199,7 @@ public class DnsContext extends ComponentDirContext {
} }
} }
@SuppressWarnings("unchecked")
public Object removeFromEnvironment(String propName) public Object removeFromEnvironment(String propName)
throws NamingException { throws NamingException {
...@@ -222,7 +225,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -222,7 +225,7 @@ public class DnsContext extends ComponentDirContext {
return environment.remove(propName); return environment.remove(propName);
} else if (environment.get(propName) != null) { } else if (environment.get(propName) != null) {
// copy-on-write // copy-on-write
environment = (Hashtable) environment.clone(); environment = (Hashtable<Object,Object>) environment.clone();
envShared = false; envShared = false;
return environment.remove(propName); return environment.remove(propName);
} else { } else {
...@@ -307,7 +310,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -307,7 +310,7 @@ public class DnsContext extends ComponentDirContext {
return c_lookup(name, cont); return c_lookup(name, cont);
} }
public NamingEnumeration c_list(Name name, Continuation cont) public NamingEnumeration<NameClassPair> c_list(Name name, Continuation cont)
throws NamingException { throws NamingException {
cont.setSuccess(); cont.setSuccess();
try { try {
...@@ -322,7 +325,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -322,7 +325,7 @@ public class DnsContext extends ComponentDirContext {
} }
} }
public NamingEnumeration c_listBindings(Name name, Continuation cont) public NamingEnumeration<Binding> c_listBindings(Name name, Continuation cont)
throws NamingException { throws NamingException {
cont.setSuccess(); cont.setSuccess();
try { try {
...@@ -457,7 +460,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -457,7 +460,7 @@ public class DnsContext extends ComponentDirContext {
new OperationNotSupportedException()); new OperationNotSupportedException());
} }
public NamingEnumeration c_search(Name name, public NamingEnumeration<SearchResult> c_search(Name name,
Attributes matchingAttributes, Attributes matchingAttributes,
String[] attributesToReturn, String[] attributesToReturn,
Continuation cont) Continuation cont)
...@@ -465,7 +468,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -465,7 +468,7 @@ public class DnsContext extends ComponentDirContext {
throw new OperationNotSupportedException(); throw new OperationNotSupportedException();
} }
public NamingEnumeration c_search(Name name, public NamingEnumeration<SearchResult> c_search(Name name,
String filter, String filter,
SearchControls cons, SearchControls cons,
Continuation cont) Continuation cont)
...@@ -473,7 +476,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -473,7 +476,7 @@ public class DnsContext extends ComponentDirContext {
throw new OperationNotSupportedException(); throw new OperationNotSupportedException();
} }
public NamingEnumeration c_search(Name name, public NamingEnumeration<SearchResult> c_search(Name name,
String filterExpr, String filterExpr,
Object[] filterArgs, Object[] filterArgs,
SearchControls cons, SearchControls cons,
...@@ -608,7 +611,7 @@ public class DnsContext extends ComponentDirContext { ...@@ -608,7 +611,7 @@ public class DnsContext extends ComponentDirContext {
BasicAttributes attrs = new BasicAttributes(true); BasicAttributes attrs = new BasicAttributes(true);
for (int i = 0; i < rrs.answer.size(); i++) { for (int i = 0; i < rrs.answer.size(); i++) {
ResourceRecord rr = (ResourceRecord) rrs.answer.elementAt(i); ResourceRecord rr = rrs.answer.elementAt(i);
int rrtype = rr.getType(); int rrtype = rr.getType();
int rrclass = rr.getRrclass(); int rrclass = rr.getRrclass();
...@@ -952,19 +955,14 @@ class CT { ...@@ -952,19 +955,14 @@ class CT {
//---------- //----------
/* /*
* An enumeration of name/classname pairs. * Common base class for NameClassPairEnumeration and BindingEnumeration.
*
* Nodes that have children or that are zone cuts are returned with
* classname DirContext. Other nodes are returned with classname
* Object even though they are DirContexts as well, since this might
* make the namespace easier to browse.
*/ */
class NameClassPairEnumeration implements NamingEnumeration { abstract class BaseNameClassPairEnumeration<T> implements NamingEnumeration<T> {
protected Enumeration nodes; // nodes to be enumerated, or null if none protected Enumeration<NameNode> nodes; // nodes to be enumerated, or null if none
protected DnsContext ctx; // context being enumerated protected DnsContext ctx; // context being enumerated
NameClassPairEnumeration(DnsContext ctx, Hashtable nodes) { BaseNameClassPairEnumeration(DnsContext ctx, Hashtable<String,NameNode> nodes) {
this.ctx = ctx; this.ctx = ctx;
this.nodes = (nodes != null) this.nodes = (nodes != null)
? nodes.elements() ? nodes.elements()
...@@ -974,12 +972,12 @@ class NameClassPairEnumeration implements NamingEnumeration { ...@@ -974,12 +972,12 @@ class NameClassPairEnumeration implements NamingEnumeration {
/* /*
* ctx will be set to null when no longer needed by the enumeration. * ctx will be set to null when no longer needed by the enumeration.
*/ */
public void close() { public final void close() {
nodes = null; nodes = null;
ctx = null; ctx = null;
} }
public boolean hasMore() { public final boolean hasMore() {
boolean more = ((nodes != null) && nodes.hasMoreElements()); boolean more = ((nodes != null) && nodes.hasMoreElements());
if (!more) { if (!more) {
close(); close();
...@@ -987,11 +985,46 @@ class NameClassPairEnumeration implements NamingEnumeration { ...@@ -987,11 +985,46 @@ class NameClassPairEnumeration implements NamingEnumeration {
return more; return more;
} }
public Object next() throws NamingException { public final boolean hasMoreElements() {
return hasMore();
}
abstract public T next() throws NamingException;
public final T nextElement() {
try {
return next();
} catch (NamingException e) {
java.util.NoSuchElementException nsee =
new java.util.NoSuchElementException();
nsee.initCause(e);
throw nsee;
}
}
}
/*
* An enumeration of name/classname pairs.
*
* Nodes that have children or that are zone cuts are returned with
* classname DirContext. Other nodes are returned with classname
* Object even though they are DirContexts as well, since this might
* make the namespace easier to browse.
*/
final class NameClassPairEnumeration
extends BaseNameClassPairEnumeration<NameClassPair>
implements NamingEnumeration<NameClassPair> {
NameClassPairEnumeration(DnsContext ctx, Hashtable<String,NameNode> nodes) {
super(ctx, nodes);
}
@Override
public NameClassPair next() throws NamingException {
if (!hasMore()) { if (!hasMore()) {
throw new java.util.NoSuchElementException(); throw new java.util.NoSuchElementException();
} }
NameNode nnode = (NameNode) nodes.nextElement(); NameNode nnode = nodes.nextElement();
String className = (nnode.isZoneCut() || String className = (nnode.isZoneCut() ||
(nnode.getChildren() != null)) (nnode.getChildren() != null))
? "javax.naming.directory.DirContext" ? "javax.naming.directory.DirContext"
...@@ -1005,28 +1038,15 @@ class NameClassPairEnumeration implements NamingEnumeration { ...@@ -1005,28 +1038,15 @@ class NameClassPairEnumeration implements NamingEnumeration {
ncp.setNameInNamespace(ctx.fullyQualify(cname).toString()); ncp.setNameInNamespace(ctx.fullyQualify(cname).toString());
return ncp; return ncp;
} }
public boolean hasMoreElements() {
return hasMore();
}
public Object nextElement() {
try {
return next();
} catch (NamingException e) {
throw (new java.util.NoSuchElementException(
"javax.naming.NamingException was thrown: " +
e.getMessage()));
}
}
} }
/* /*
* An enumeration of Bindings. * An enumeration of Bindings.
*/ */
class BindingEnumeration extends NameClassPairEnumeration { final class BindingEnumeration extends BaseNameClassPairEnumeration<Binding>
implements NamingEnumeration<Binding> {
BindingEnumeration(DnsContext ctx, Hashtable nodes) { BindingEnumeration(DnsContext ctx, Hashtable<String,NameNode> nodes) {
super(ctx, nodes); super(ctx, nodes);
} }
...@@ -1035,11 +1055,12 @@ class BindingEnumeration extends NameClassPairEnumeration { ...@@ -1035,11 +1055,12 @@ class BindingEnumeration extends NameClassPairEnumeration {
// close(); // close();
// } // }
public Object next() throws NamingException { @Override
public Binding next() throws NamingException {
if (!hasMore()) { if (!hasMore()) {
throw (new java.util.NoSuchElementException()); throw (new java.util.NoSuchElementException());
} }
NameNode nnode = (NameNode) nodes.nextElement(); NameNode nnode = nodes.nextElement();
String label = nnode.getLabel(); String label = nnode.getLabel();
Name compName = (new DnsName()).add(label); Name compName = (new DnsName()).add(label);
......
/* /*
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -59,7 +59,7 @@ public class DnsContextFactory implements InitialContextFactory { ...@@ -59,7 +59,7 @@ public class DnsContextFactory implements InitialContextFactory {
public Context getInitialContext(Hashtable<?,?> env) throws NamingException { public Context getInitialContext(Hashtable<?,?> env) throws NamingException {
if (env == null) { if (env == null) {
env = new Hashtable(5); env = new Hashtable<>(5);
} }
return urlToContext(getInitCtxUrl(env), env); return urlToContext(getInitCtxUrl(env), env);
} }
...@@ -75,7 +75,7 @@ public class DnsContextFactory implements InitialContextFactory { ...@@ -75,7 +75,7 @@ public class DnsContextFactory implements InitialContextFactory {
* components are overridden by "domain". * components are overridden by "domain".
*/ */
public static DnsContext getContext(String domain, public static DnsContext getContext(String domain,
DnsUrl[] urls, Hashtable env) DnsUrl[] urls, Hashtable<?,?> env)
throws NamingException { throws NamingException {
String[] servers = serversForUrls(urls); String[] servers = serversForUrls(urls);
...@@ -95,7 +95,7 @@ public class DnsContextFactory implements InitialContextFactory { ...@@ -95,7 +95,7 @@ public class DnsContextFactory implements InitialContextFactory {
).isEmpty(); ).isEmpty();
} }
private static Context urlToContext(String url, Hashtable env) private static Context urlToContext(String url, Hashtable<?,?> env)
throws NamingException { throws NamingException {
DnsUrl[] urls; DnsUrl[] urls;
...@@ -212,7 +212,7 @@ public class DnsContextFactory implements InitialContextFactory { ...@@ -212,7 +212,7 @@ public class DnsContextFactory implements InitialContextFactory {
* Reads environment to find URL(s) of initial context. * Reads environment to find URL(s) of initial context.
* Default URL is "dns:". * Default URL is "dns:".
*/ */
private static String getInitCtxUrl(Hashtable env) { private static String getInitCtxUrl(Hashtable<?,?> env) {
String url = (String) env.get(Context.PROVIDER_URL); String url = (String) env.get(Context.PROVIDER_URL);
return ((url != null) ? url : DEFAULT_URL); return ((url != null) ? url : DEFAULT_URL);
} }
...@@ -223,34 +223,31 @@ public class DnsContextFactory implements InitialContextFactory { ...@@ -223,34 +223,31 @@ public class DnsContextFactory implements InitialContextFactory {
* @param oneIsEnough return output once there exists one ok * @param oneIsEnough return output once there exists one ok
* @return the filtered list, all non-permitted input removed * @return the filtered list, all non-permitted input removed
*/ */
private static List filterNameServers(List input, boolean oneIsEnough) { private static List<String> filterNameServers(List<String> input, boolean oneIsEnough) {
SecurityManager security = System.getSecurityManager(); SecurityManager security = System.getSecurityManager();
if (security == null || input == null || input.isEmpty()) { if (security == null || input == null || input.isEmpty()) {
return input; return input;
} else { } else {
List output = new ArrayList(); List<String> output = new ArrayList<>();
for (Object o: input) { for (String platformServer: input) {
if (o instanceof String) { int colon = platformServer.indexOf(':',
String platformServer = (String)o; platformServer.indexOf(']') + 1);
int colon = platformServer.indexOf(':',
platformServer.indexOf(']') + 1);
int p = (colon < 0) int p = (colon < 0)
? DEFAULT_PORT ? DEFAULT_PORT
: Integer.parseInt( : Integer.parseInt(
platformServer.substring(colon + 1)); platformServer.substring(colon + 1));
String s = (colon < 0) String s = (colon < 0)
? platformServer ? platformServer
: platformServer.substring(0, colon); : platformServer.substring(0, colon);
try { try {
security.checkConnect(s, p); security.checkConnect(s, p);
output.add(platformServer); output.add(platformServer);
if (oneIsEnough) { if (oneIsEnough) {
return output; return output;
}
} catch (SecurityException se) {
continue;
} }
} catch (SecurityException se) {
continue;
} }
} }
return output; return output;
......
/* /*
* Copyright (c) 2000, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -29,7 +29,6 @@ package com.sun.jndi.dns; ...@@ -29,7 +29,6 @@ package com.sun.jndi.dns;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator; import java.util.Comparator;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Iterator;
import javax.naming.*; import javax.naming.*;
...@@ -111,7 +110,7 @@ public final class DnsName implements Name { ...@@ -111,7 +110,7 @@ public final class DnsName implements Name {
// The labels of this domain name, as a list of strings. Index 0 // The labels of this domain name, as a list of strings. Index 0
// corresponds to the leftmost (least significant) label: note that // corresponds to the leftmost (least significant) label: note that
// this is the reverse of the ordering used by the Name interface. // this is the reverse of the ordering used by the Name interface.
private ArrayList labels = new ArrayList(); private ArrayList<String> labels = new ArrayList<>();
// The number of octets needed to carry this domain name in a DNS // The number of octets needed to carry this domain name in a DNS
// packet. Equal to the sum of the lengths of each label, plus the // packet. Equal to the sum of the lengths of each label, plus the
...@@ -152,9 +151,7 @@ public final class DnsName implements Name { ...@@ -152,9 +151,7 @@ public final class DnsName implements Name {
domain = n.domain; domain = n.domain;
octets = n.octets; octets = n.octets;
} else { } else {
Iterator iter = labels.iterator(); for (String label: labels) {
while (iter.hasNext()) {
String label = (String) iter.next();
if (label.length() > 0) { if (label.length() > 0) {
octets += (short) (label.length() + 1); octets += (short) (label.length() + 1);
} }
...@@ -165,10 +162,8 @@ public final class DnsName implements Name { ...@@ -165,10 +162,8 @@ public final class DnsName implements Name {
public String toString() { public String toString() {
if (domain == null) { if (domain == null) {
StringBuffer buf = new StringBuffer(); StringBuilder buf = new StringBuilder();
Iterator iter = labels.iterator(); for (String label: labels) {
while (iter.hasNext()) {
String label = (String) iter.next();
if (buf.length() > 0 || label.length() == 0) { if (buf.length() > 0 || label.length() == 0) {
buf.append('.'); buf.append('.');
} }
...@@ -183,9 +178,8 @@ public final class DnsName implements Name { ...@@ -183,9 +178,8 @@ public final class DnsName implements Name {
* Does this domain name follow <em>host name</em> syntax? * Does this domain name follow <em>host name</em> syntax?
*/ */
public boolean isHostName() { public boolean isHostName() {
Iterator iter = labels.iterator(); for (String label: labels) {
while (iter.hasNext()) { if (!isHostNameLabel(label)) {
if (!isHostNameLabel((String) iter.next())) {
return false; return false;
} }
} }
...@@ -241,16 +235,16 @@ public final class DnsName implements Name { ...@@ -241,16 +235,16 @@ public final class DnsName implements Name {
throw new ArrayIndexOutOfBoundsException(); throw new ArrayIndexOutOfBoundsException();
} }
int i = size() - pos - 1; // index of "pos" component in "labels" int i = size() - pos - 1; // index of "pos" component in "labels"
return (String) labels.get(i); return labels.get(i);
} }
public Enumeration getAll() { public Enumeration<String> getAll() {
return new Enumeration() { return new Enumeration<String>() {
int pos = 0; int pos = 0;
public boolean hasMoreElements() { public boolean hasMoreElements() {
return (pos < size()); return (pos < size());
} }
public Object nextElement() { public String nextElement() {
if (pos < size()) { if (pos < size()) {
return get(pos++); return get(pos++);
} }
...@@ -276,7 +270,7 @@ public final class DnsName implements Name { ...@@ -276,7 +270,7 @@ public final class DnsName implements Name {
throw new ArrayIndexOutOfBoundsException(); throw new ArrayIndexOutOfBoundsException();
} }
int i = size() - pos - 1; // index of element to remove in "labels" int i = size() - pos - 1; // index of element to remove in "labels"
String label = (String) labels.remove(i); String label = labels.remove(i);
int len = label.length(); int len = label.length();
if (len > 0) { if (len > 0) {
octets -= (short) (len + 1); octets -= (short) (len + 1);
...@@ -530,7 +524,7 @@ public final class DnsName implements Name { ...@@ -530,7 +524,7 @@ public final class DnsName implements Name {
/* /*
* Append a label to buf, escaping as needed. * Append a label to buf, escaping as needed.
*/ */
private static void escape(StringBuffer buf, String label) { private static void escape(StringBuilder buf, String label) {
for (int i = 0; i < label.length(); i++) { for (int i = 0; i < label.length(); i++) {
char c = label.charAt(i); char c = label.charAt(i);
if (c == '.' || c == '\\') { if (c == '.' || c == '\\') {
......
/* /*
* Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -52,7 +52,7 @@ class NameNode { ...@@ -52,7 +52,7 @@ class NameNode {
private String label; // name of this node relative to its private String label; // name of this node relative to its
// parent, or null for root of a tree // parent, or null for root of a tree
private Hashtable children = null; // child nodes private Hashtable<String,NameNode> children = null; // child nodes
private boolean isZoneCut = false; // true if this node is a zone cut private boolean isZoneCut = false; // true if this node is a zone cut
private int depth = 0; // depth in tree (0 for root) private int depth = 0; // depth in tree (0 for root)
...@@ -97,7 +97,7 @@ class NameNode { ...@@ -97,7 +97,7 @@ class NameNode {
* Returns the children of this node, or null if there are none. * Returns the children of this node, or null if there are none.
* The caller must not modify the Hashtable returned. * The caller must not modify the Hashtable returned.
*/ */
Hashtable getChildren() { Hashtable<String,NameNode> getChildren() {
return children; return children;
} }
...@@ -108,7 +108,7 @@ class NameNode { ...@@ -108,7 +108,7 @@ class NameNode {
*/ */
NameNode get(String key) { NameNode get(String key) {
return (children != null) return (children != null)
? (NameNode) children.get(key) ? children.get(key)
: null; : null;
} }
...@@ -140,9 +140,9 @@ class NameNode { ...@@ -140,9 +140,9 @@ class NameNode {
NameNode child = null; NameNode child = null;
if (node.children == null) { if (node.children == null) {
node.children = new Hashtable(); node.children = new Hashtable<>();
} else { } else {
child = (NameNode) node.children.get(key); child = node.children.get(key);
} }
if (child == null) { if (child == null) {
child = newNameNode(label); child = newNameNode(label);
......
/* /*
* Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -125,8 +125,7 @@ class Resolver { ...@@ -125,8 +125,7 @@ class Resolver {
} }
// Look for an SOA record giving the zone's top node. // Look for an SOA record giving the zone's top node.
for (int i = 0; i < rrs.authority.size(); i++) { for (int i = 0; i < rrs.authority.size(); i++) {
ResourceRecord rr = (ResourceRecord) ResourceRecord rr = rrs.authority.elementAt(i);
rrs.authority.elementAt(i);
if (rr.getType() == ResourceRecord.TYPE_SOA) { if (rr.getType() == ResourceRecord.TYPE_SOA) {
DnsName zone = rr.getName(); DnsName zone = rr.getName();
if (fqdn.endsWith(zone)) { if (fqdn.endsWith(zone)) {
...@@ -152,7 +151,7 @@ class Resolver { ...@@ -152,7 +151,7 @@ class Resolver {
ResourceRecords rrs = query(zone, rrclass, ResourceRecord.TYPE_SOA, ResourceRecords rrs = query(zone, rrclass, ResourceRecord.TYPE_SOA,
recursion, false); recursion, false);
for (int i = 0; i < rrs.answer.size(); i++) { for (int i = 0; i < rrs.answer.size(); i++) {
ResourceRecord rr = (ResourceRecord) rrs.answer.elementAt(i); ResourceRecord rr = rrs.answer.elementAt(i);
if (rr.getType() == ResourceRecord.TYPE_SOA) { if (rr.getType() == ResourceRecord.TYPE_SOA) {
return rr; return rr;
} }
...@@ -175,8 +174,7 @@ class Resolver { ...@@ -175,8 +174,7 @@ class Resolver {
recursion, false); recursion, false);
String[] ns = new String[rrs.answer.size()]; String[] ns = new String[rrs.answer.size()];
for (int i = 0; i < ns.length; i++) { for (int i = 0; i < ns.length; i++) {
ResourceRecord rr = (ResourceRecord) ResourceRecord rr = rrs.answer.elementAt(i);
rrs.answer.elementAt(i);
if (rr.getType() != ResourceRecord.TYPE_NS) { if (rr.getType() != ResourceRecord.TYPE_NS) {
throw new CommunicationException("Corrupted DNS message"); throw new CommunicationException("Corrupted DNS message");
} }
......
/* /*
* Copyright (c) 2000, 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -45,10 +45,10 @@ class ResourceRecords { ...@@ -45,10 +45,10 @@ class ResourceRecords {
// Four sections: question, answer, authority, additional. // Four sections: question, answer, authority, additional.
// The question section is treated as being made up of (shortened) // The question section is treated as being made up of (shortened)
// resource records, although this isn't technically how it's defined. // resource records, although this isn't technically how it's defined.
Vector question = new Vector(); Vector<ResourceRecord> question = new Vector<>();
Vector answer = new Vector(); Vector<ResourceRecord> answer = new Vector<>();
Vector authority = new Vector(); Vector<ResourceRecord> authority = new Vector<>();
Vector additional = new Vector(); Vector<ResourceRecord> additional = new Vector<>();
/* /*
* True if these resource records are from a zone transfer. In * True if these resource records are from a zone transfer. In
...@@ -80,7 +80,7 @@ class ResourceRecords { ...@@ -80,7 +80,7 @@ class ResourceRecords {
if (answer.size() == 0) { if (answer.size() == 0) {
return -1; return -1;
} }
return ((ResourceRecord) answer.firstElement()).getType(); return answer.firstElement().getType();
} }
/* /*
...@@ -91,7 +91,7 @@ class ResourceRecords { ...@@ -91,7 +91,7 @@ class ResourceRecords {
if (answer.size() == 0) { if (answer.size() == 0) {
return -1; return -1;
} }
return ((ResourceRecord) answer.lastElement()).getType(); return answer.lastElement().getType();
} }
/* /*
......
/* /*
* Copyright (c) 2000, 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -55,7 +55,7 @@ import java.util.Vector; ...@@ -55,7 +55,7 @@ import java.util.Vector;
class ZoneNode extends NameNode { class ZoneNode extends NameNode {
private SoftReference contentsRef = null; // the zone's namespace private SoftReference<NameNode> contentsRef = null; // the zone's namespace
private long serialNumber = -1; // the zone data's serial number private long serialNumber = -1; // the zone data's serial number
private Date expiration = null; // time when the zone's data expires private Date expiration = null; // time when the zone's data expires
...@@ -88,7 +88,7 @@ class ZoneNode extends NameNode { ...@@ -88,7 +88,7 @@ class ZoneNode extends NameNode {
*/ */
synchronized NameNode getContents() { synchronized NameNode getContents() {
return (contentsRef != null) return (contentsRef != null)
? (NameNode) contentsRef.get() ? contentsRef.get()
: null; : null;
} }
...@@ -130,7 +130,7 @@ class ZoneNode extends NameNode { ...@@ -130,7 +130,7 @@ class ZoneNode extends NameNode {
NameNode newContents = new NameNode(null); NameNode newContents = new NameNode(null);
for (int i = 0; i < rrs.answer.size(); i++) { for (int i = 0; i < rrs.answer.size(); i++) {
ResourceRecord rr = (ResourceRecord) rrs.answer.elementAt(i); ResourceRecord rr = rrs.answer.elementAt(i);
DnsName n = rr.getName(); DnsName n = rr.getName();
// Ignore resource records whose names aren't within the zone's // Ignore resource records whose names aren't within the zone's
...@@ -144,9 +144,9 @@ class ZoneNode extends NameNode { ...@@ -144,9 +144,9 @@ class ZoneNode extends NameNode {
} }
} }
// The zone's SOA record is the first record in the answer section. // The zone's SOA record is the first record in the answer section.
ResourceRecord soa = (ResourceRecord) rrs.answer.firstElement(); ResourceRecord soa = rrs.answer.firstElement();
synchronized (this) { synchronized (this) {
contentsRef = new SoftReference(newContents); contentsRef = new SoftReference<NameNode>(newContents);
serialNumber = getSerialNumber(soa); serialNumber = getSerialNumber(soa);
setExpiration(getMinimumTtl(soa)); setExpiration(getMinimumTtl(soa));
return newContents; return newContents;
......
/*
* Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* 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.
*/
package com.sun.jndi.ldap;
import com.sun.jndi.toolkit.ctx.Continuation;
import java.util.NoSuchElementException;
import java.util.Vector;
import javax.naming.*;
import javax.naming.directory.Attributes;
import javax.naming.ldap.Control;
/**
* Basic enumeration for NameClassPair, Binding, and SearchResults.
*/
abstract class AbstractLdapNamingEnumeration<T extends NameClassPair>
implements NamingEnumeration<T>, ReferralEnumeration<T> {
protected Name listArg;
private boolean cleaned = false;
private LdapResult res;
private LdapClient enumClnt;
private Continuation cont; // used to fill in exceptions
private Vector<LdapEntry> entries = null;
private int limit = 0;
private int posn = 0;
protected LdapCtx homeCtx;
private LdapReferralException refEx = null;
private NamingException errEx = null;
/*
* Record the next set of entries and/or referrals.
*/
AbstractLdapNamingEnumeration(LdapCtx homeCtx, LdapResult answer, Name listArg,
Continuation cont) throws NamingException {
// These checks are to accommodate referrals and limit exceptions
// which will generate an enumeration and defer the exception
// to be thrown at the end of the enumeration.
// All other exceptions are thrown immediately.
// Exceptions shouldn't be thrown here anyhow because
// process_return_code() is called before the constructor
// is called, so these are just safety checks.
if ((answer.status != LdapClient.LDAP_SUCCESS) &&
(answer.status != LdapClient.LDAP_SIZE_LIMIT_EXCEEDED) &&
(answer.status != LdapClient.LDAP_TIME_LIMIT_EXCEEDED) &&
(answer.status != LdapClient.LDAP_ADMIN_LIMIT_EXCEEDED) &&
(answer.status != LdapClient.LDAP_REFERRAL) &&
(answer.status != LdapClient.LDAP_PARTIAL_RESULTS)) {
// %%% need to deal with referral
NamingException e = new NamingException(
LdapClient.getErrorMessage(
answer.status, answer.errorMessage));
throw cont.fillInException(e);
}
// otherwise continue
res = answer;
entries = answer.entries;
limit = (entries == null) ? 0 : entries.size(); // handle empty set
this.listArg = listArg;
this.cont = cont;
if (answer.refEx != null) {
refEx = answer.refEx;
}
// Ensures that context won't get closed from underneath us
this.homeCtx = homeCtx;
homeCtx.incEnumCount();
enumClnt = homeCtx.clnt; // remember
}
@Override
public final T nextElement() {
try {
return next();
} catch (NamingException e) {
// can't throw exception
cleanup();
return null;
}
}
@Override
public final boolean hasMoreElements() {
try {
return hasMore();
} catch (NamingException e) {
// can't throw exception
cleanup();
return false;
}
}
/*
* Retrieve the next set of entries and/or referrals.
*/
private void getNextBatch() throws NamingException {
res = homeCtx.getSearchReply(enumClnt, res);
if (res == null) {
limit = posn = 0;
return;
}
entries = res.entries;
limit = (entries == null) ? 0 : entries.size(); // handle empty set
posn = 0; // reset
// mimimize the number of calls to processReturnCode()
// (expensive when batchSize is small and there are many results)
if ((res.status != LdapClient.LDAP_SUCCESS) ||
((res.status == LdapClient.LDAP_SUCCESS) &&
(res.referrals != null))) {
try {
// convert referrals into a chain of LdapReferralException
homeCtx.processReturnCode(res, listArg);
} catch (LimitExceededException | PartialResultException e) {
setNamingException(e);
}
}
// merge any newly received referrals with any current referrals
if (res.refEx != null) {
if (refEx == null) {
refEx = res.refEx;
} else {
refEx = refEx.appendUnprocessedReferrals(res.refEx);
}
res.refEx = null; // reset
}
if (res.resControls != null) {
homeCtx.respCtls = res.resControls;
}
}
private boolean more = true; // assume we have something to start with
private boolean hasMoreCalled = false;
/*
* Test if unprocessed entries or referrals exist.
*/
@Override
public final boolean hasMore() throws NamingException {
if (hasMoreCalled) {
return more;
}
hasMoreCalled = true;
if (!more) {
return false;
} else {
return (more = hasMoreImpl());
}
}
/*
* Retrieve the next entry.
*/
@Override
public final T next() throws NamingException {
if (!hasMoreCalled) {
hasMore();
}
hasMoreCalled = false;
return nextImpl();
}
/*
* Test if unprocessed entries or referrals exist.
*/
private boolean hasMoreImpl() throws NamingException {
// when page size is supported, this
// might generate an exception while attempting
// to fetch the next batch to determine
// whether there are any more elements
// test if the current set of entries has been processed
if (posn == limit) {
getNextBatch();
}
// test if any unprocessed entries exist
if (posn < limit) {
return true;
} else {
try {
// try to process another referral
return hasMoreReferrals();
} catch (LdapReferralException |
LimitExceededException |
PartialResultException e) {
cleanup();
throw e;
} catch (NamingException e) {
cleanup();
PartialResultException pre = new PartialResultException();
pre.setRootCause(e);
throw pre;
}
}
}
/*
* Retrieve the next entry.
*/
private T nextImpl() throws NamingException {
try {
return nextAux();
} catch (NamingException e) {
cleanup();
throw cont.fillInException(e);
}
}
private T nextAux() throws NamingException {
if (posn == limit) {
getNextBatch(); // updates posn and limit
}
if (posn >= limit) {
cleanup();
throw new NoSuchElementException("invalid enumeration handle");
}
LdapEntry result = entries.elementAt(posn++);
// gets and outputs DN from the entry
return createItem(result.DN, result.attributes, result.respCtls);
}
protected final String getAtom(String dn) {
// need to strip off all but lowest component of dn
// so that is relative to current context (currentDN)
try {
Name parsed = new LdapName(dn);
return parsed.get(parsed.size() - 1);
} catch (NamingException e) {
return dn;
}
}
protected abstract T createItem(String dn, Attributes attrs,
Vector<Control> respCtls) throws NamingException;
/*
* Append the supplied (chain of) referrals onto the
* end of the current (chain of) referrals.
*/
@Override
public void appendUnprocessedReferrals(LdapReferralException ex) {
if (refEx != null) {
refEx = refEx.appendUnprocessedReferrals(ex);
} else {
refEx = ex.appendUnprocessedReferrals(refEx);
}
}
final void setNamingException(NamingException e) {
errEx = e;
}
protected abstract AbstractLdapNamingEnumeration<T> getReferredResults(
LdapReferralContext refCtx) throws NamingException;
/*
* Iterate through the URLs of a referral. If successful then perform
* a search operation and merge the received results with the current
* results.
*/
protected final boolean hasMoreReferrals() throws NamingException {
if ((refEx != null) &&
(refEx.hasMoreReferrals() ||
refEx.hasMoreReferralExceptions())) {
if (homeCtx.handleReferrals == LdapClient.LDAP_REF_THROW) {
throw (NamingException)(refEx.fillInStackTrace());
}
// process the referrals sequentially
while (true) {
LdapReferralContext refCtx =
(LdapReferralContext)refEx.getReferralContext(
homeCtx.envprops, homeCtx.reqCtls);
try {
update(getReferredResults(refCtx));
break;
} catch (LdapReferralException re) {
// record a previous exception
if (errEx == null) {
errEx = re.getNamingException();
}
refEx = re;
continue;
} finally {
// Make sure we close referral context
refCtx.close();
}
}
return hasMoreImpl();
} else {
cleanup();
if (errEx != null) {
throw errEx;
}
return (false);
}
}
/*
* Merge the entries and/or referrals from the supplied enumeration
* with those of the current enumeration.
*/
protected void update(AbstractLdapNamingEnumeration<T> ne) {
// Cleanup previous context first
homeCtx.decEnumCount();
// New enum will have already incremented enum count and recorded clnt
homeCtx = ne.homeCtx;
enumClnt = ne.enumClnt;
// Do this to prevent referral enumeration (ne) from decrementing
// enum count because we'll be doing that here from this
// enumeration.
ne.homeCtx = null;
// Record rest of information from new enum
posn = ne.posn;
limit = ne.limit;
res = ne.res;
entries = ne.entries;
refEx = ne.refEx;
listArg = ne.listArg;
}
protected final void finalize() {
cleanup();
}
protected final void cleanup() {
if (cleaned) return; // been there; done that
if(enumClnt != null) {
enumClnt.clearSearchReply(res, homeCtx.reqCtls);
}
enumClnt = null;
cleaned = true;
if (homeCtx != null) {
homeCtx.decEnumCount();
homeCtx = null;
}
}
@Override
public final void close() {
cleanup();
}
}
/* /*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -94,12 +94,14 @@ public abstract class Ber { ...@@ -94,12 +94,14 @@ public abstract class Ber {
public static final int ASN_ENUMERATED = 0x0a; public static final int ASN_ENUMERATED = 0x0a;
final static class EncodeException extends IOException { final static class EncodeException extends IOException {
private static final long serialVersionUID = -5247359637775781768L;
EncodeException(String msg) { EncodeException(String msg) {
super(msg); super(msg);
} }
} }
final static class DecodeException extends IOException { final static class DecodeException extends IOException {
private static final long serialVersionUID = 8735036969244425583L;
DecodeException(String msg) { DecodeException(String msg) {
super(msg); super(msg);
} }
......
/* /*
* Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -74,7 +74,7 @@ class ClientId { ...@@ -74,7 +74,7 @@ class ClientId {
this.hostname = hostname.toLowerCase(); // ignore case this.hostname = hostname.toLowerCase(); // ignore case
this.port = port; this.port = port;
this.protocol = protocol; this.protocol = protocol;
this.bindCtls = (bindCtls != null ? (Control[]) bindCtls.clone() : null); this.bindCtls = (bindCtls != null ? bindCtls.clone() : null);
this.trace = trace; this.trace = trace;
// //
// Needed for custom socket factory pooling // Needed for custom socket factory pooling
...@@ -83,12 +83,12 @@ class ClientId { ...@@ -83,12 +83,12 @@ class ClientId {
if ((socketFactory != null) && if ((socketFactory != null) &&
!socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) { !socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) {
try { try {
Class socketFactoryClass = Obj.helper.loadClass(socketFactory); Class<?> socketFactoryClass = Obj.helper.loadClass(socketFactory);
Class objClass = Class.forName("java.lang.Object"); Class<?> objClass = Class.forName("java.lang.Object");
this.sockComparator = socketFactoryClass.getMethod( this.sockComparator = socketFactoryClass.getMethod(
"compare", new Class[]{objClass, objClass}); "compare", new Class<?>[]{objClass, objClass});
Method getDefault = Method getDefault =
socketFactoryClass.getMethod("getDefault", new Class[]{}); socketFactoryClass.getMethod("getDefault", new Class<?>[]{});
this.factory = (SocketFactory) getDefault.invoke(null, new Object[]{}); this.factory = (SocketFactory) getDefault.invoke(null, new Object[]{});
} catch (Exception e) { } catch (Exception e) {
// Ignore it here, the same exceptions are/will be handled by // Ignore it here, the same exceptions are/will be handled by
......
...@@ -238,27 +238,22 @@ public final class Connection implements Runnable { ...@@ -238,27 +238,22 @@ public final class Connection implements Runnable {
throws NoSuchMethodException { throws NoSuchMethodException {
try { try {
Class inetSocketAddressClass = Class<?> inetSocketAddressClass =
Class.forName("java.net.InetSocketAddress"); Class.forName("java.net.InetSocketAddress");
Constructor inetSocketAddressCons = Constructor<?> inetSocketAddressCons =
inetSocketAddressClass.getConstructor(new Class[]{ inetSocketAddressClass.getConstructor(new Class<?>[]{
String.class, int.class}); String.class, int.class});
return inetSocketAddressCons.newInstance(new Object[]{ return inetSocketAddressCons.newInstance(new Object[]{
host, new Integer(port)}); host, new Integer(port)});
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException |
InstantiationException |
InvocationTargetException |
IllegalAccessException e) {
throw new NoSuchMethodException(); throw new NoSuchMethodException();
} catch (InstantiationException e) {
throw new NoSuchMethodException();
} catch (InvocationTargetException e) {
throw new NoSuchMethodException();
} catch (IllegalAccessException e) {
throw new NoSuchMethodException();
} }
} }
...@@ -280,9 +275,9 @@ public final class Connection implements Runnable { ...@@ -280,9 +275,9 @@ public final class Connection implements Runnable {
// create the factory // create the factory
Class socketFactoryClass = Obj.helper.loadClass(socketFactory); Class<?> socketFactoryClass = Obj.helper.loadClass(socketFactory);
Method getDefault = Method getDefault =
socketFactoryClass.getMethod("getDefault", new Class[]{}); socketFactoryClass.getMethod("getDefault", new Class<?>[]{});
Object factory = getDefault.invoke(null, new Object[]{}); Object factory = getDefault.invoke(null, new Object[]{});
// create the socket // create the socket
...@@ -293,10 +288,10 @@ public final class Connection implements Runnable { ...@@ -293,10 +288,10 @@ public final class Connection implements Runnable {
try { try {
createSocket = socketFactoryClass.getMethod("createSocket", createSocket = socketFactoryClass.getMethod("createSocket",
new Class[]{}); new Class<?>[]{});
Method connect = Socket.class.getMethod("connect", Method connect = Socket.class.getMethod("connect",
new Class[]{Class.forName("java.net.SocketAddress"), new Class<?>[]{Class.forName("java.net.SocketAddress"),
int.class}); int.class});
Object endpoint = createInetSocketAddress(host, port); Object endpoint = createInetSocketAddress(host, port);
...@@ -320,7 +315,7 @@ public final class Connection implements Runnable { ...@@ -320,7 +315,7 @@ public final class Connection implements Runnable {
if (socket == null) { if (socket == null) {
createSocket = socketFactoryClass.getMethod("createSocket", createSocket = socketFactoryClass.getMethod("createSocket",
new Class[]{String.class, int.class}); new Class<?>[]{String.class, int.class});
if (debug) { if (debug) {
System.err.println("Connection: creating socket using " + System.err.println("Connection: creating socket using " +
...@@ -335,15 +330,15 @@ public final class Connection implements Runnable { ...@@ -335,15 +330,15 @@ public final class Connection implements Runnable {
if (connectTimeout > 0) { if (connectTimeout > 0) {
try { try {
Constructor socketCons = Constructor<Socket> socketCons =
Socket.class.getConstructor(new Class[]{}); Socket.class.getConstructor(new Class<?>[]{});
Method connect = Socket.class.getMethod("connect", Method connect = Socket.class.getMethod("connect",
new Class[]{Class.forName("java.net.SocketAddress"), new Class<?>[]{Class.forName("java.net.SocketAddress"),
int.class}); int.class});
Object endpoint = createInetSocketAddress(host, port); Object endpoint = createInetSocketAddress(host, port);
socket = (Socket) socketCons.newInstance(new Object[]{}); socket = socketCons.newInstance(new Object[]{});
if (debug) { if (debug) {
System.err.println("Connection: creating socket with " + System.err.println("Connection: creating socket with " +
......
/* /*
* Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -65,7 +65,7 @@ class DigestClientId extends SimpleClientId { ...@@ -65,7 +65,7 @@ class DigestClientId extends SimpleClientId {
DigestClientId(int version, String hostname, int port, DigestClientId(int version, String hostname, int port,
String protocol, Control[] bindCtls, OutputStream trace, String protocol, Control[] bindCtls, OutputStream trace,
String socketFactory, String username, String socketFactory, String username,
Object passwd, Hashtable env) { Object passwd, Hashtable<?,?> env) {
super(version, hostname, port, protocol, bindCtls, trace, super(version, hostname, port, protocol, bindCtls, trace,
socketFactory, username, passwd); socketFactory, username, passwd);
......
/* /*
* Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package com.sun.jndi.ldap; package com.sun.jndi.ldap;
import java.io.*;
import java.util.Vector; import java.util.Vector;
import java.util.EventObject; import java.util.EventObject;
...@@ -52,9 +51,9 @@ final class EventQueue implements Runnable { ...@@ -52,9 +51,9 @@ final class EventQueue implements Runnable {
QueueElement next = null; QueueElement next = null;
QueueElement prev = null; QueueElement prev = null;
EventObject event = null; EventObject event = null;
Vector vector = null; Vector<NamingListener> vector = null;
QueueElement(EventObject event, Vector vector) { QueueElement(EventObject event, Vector<NamingListener> vector) {
this.event = event; this.event = event;
this.vector = vector; this.vector = vector;
} }
...@@ -87,7 +86,7 @@ final class EventQueue implements Runnable { ...@@ -87,7 +86,7 @@ final class EventQueue implements Runnable {
* are notified. * are notified.
* @param vector List of NamingListeners that will be notified of event. * @param vector List of NamingListeners that will be notified of event.
*/ */
synchronized void enqueue(EventObject event, Vector vector) { synchronized void enqueue(EventObject event, Vector<NamingListener> vector) {
QueueElement newElt = new QueueElement(event, vector); QueueElement newElt = new QueueElement(event, vector);
if (head == null) { if (head == null) {
...@@ -133,7 +132,7 @@ final class EventQueue implements Runnable { ...@@ -133,7 +132,7 @@ final class EventQueue implements Runnable {
try { try {
while ((qe = dequeue()) != null) { while ((qe = dequeue()) != null) {
EventObject e = qe.event; EventObject e = qe.event;
Vector v = qe.vector; Vector<NamingListener> v = qe.vector;
for (int i = 0; i < v.size(); i++) { for (int i = 0; i < v.size(); i++) {
...@@ -145,12 +144,11 @@ final class EventQueue implements Runnable { ...@@ -145,12 +144,11 @@ final class EventQueue implements Runnable {
// only enqueue events with listseners of the correct type. // only enqueue events with listseners of the correct type.
if (e instanceof NamingEvent) { if (e instanceof NamingEvent) {
((NamingEvent)e).dispatch((NamingListener)v.elementAt(i)); ((NamingEvent)e).dispatch(v.elementAt(i));
// An exception occurred: if notify all naming listeners // An exception occurred: if notify all naming listeners
} else if (e instanceof NamingExceptionEvent) { } else if (e instanceof NamingExceptionEvent) {
((NamingExceptionEvent)e).dispatch( ((NamingExceptionEvent)e).dispatch(v.elementAt(i));
(NamingListener)v.elementAt(i));
} else if (e instanceof UnsolicitedNotificationEvent) { } else if (e instanceof UnsolicitedNotificationEvent) {
((UnsolicitedNotificationEvent)e).dispatch( ((UnsolicitedNotificationEvent)e).dispatch(
(UnsolicitedNotificationListener)v.elementAt(i)); (UnsolicitedNotificationListener)v.elementAt(i));
......
/* /*
* Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,11 +27,9 @@ package com.sun.jndi.ldap; ...@@ -27,11 +27,9 @@ package com.sun.jndi.ldap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
import java.util.Enumeration;
import java.util.EventObject; import java.util.EventObject;
import javax.naming.*; import javax.naming.*;
import javax.naming.directory.*;
import javax.naming.event.*; import javax.naming.event.*;
import javax.naming.directory.SearchControls; import javax.naming.directory.SearchControls;
import javax.naming.ldap.UnsolicitedNotificationListener; import javax.naming.ldap.UnsolicitedNotificationListener;
...@@ -120,12 +118,13 @@ final class EventSupport { ...@@ -120,12 +118,13 @@ final class EventSupport {
/** /**
* NamingEventNotifiers; hashed by search arguments; * NamingEventNotifiers; hashed by search arguments;
*/ */
private Hashtable notifiers = new Hashtable(11); private Hashtable<NotifierArgs, NamingEventNotifier> notifiers =
new Hashtable<>(11);
/** /**
* List of unsolicited notification listeners. * List of unsolicited notification listeners.
*/ */
private Vector unsolicited = null; private Vector<UnsolicitedNotificationListener> unsolicited = null;
/** /**
* Constructs EventSupport for ctx. * Constructs EventSupport for ctx.
...@@ -155,8 +154,7 @@ final class EventSupport { ...@@ -155,8 +154,7 @@ final class EventSupport {
l instanceof NamespaceChangeListener) { l instanceof NamespaceChangeListener) {
NotifierArgs args = new NotifierArgs(nm, scope, l); NotifierArgs args = new NotifierArgs(nm, scope, l);
NamingEventNotifier notifier = NamingEventNotifier notifier = notifiers.get(args);
(NamingEventNotifier) notifiers.get(args);
if (notifier == null) { if (notifier == null) {
notifier = new NamingEventNotifier(this, ctx, args, l); notifier = new NamingEventNotifier(this, ctx, args, l);
notifiers.put(args, notifier); notifiers.put(args, notifier);
...@@ -167,10 +165,10 @@ final class EventSupport { ...@@ -167,10 +165,10 @@ final class EventSupport {
if (l instanceof UnsolicitedNotificationListener) { if (l instanceof UnsolicitedNotificationListener) {
// Add listener to this's list of unsolicited notifiers // Add listener to this's list of unsolicited notifiers
if (unsolicited == null) { if (unsolicited == null) {
unsolicited = new Vector(3); unsolicited = new Vector<>(3);
} }
unsolicited.addElement(l); unsolicited.addElement((UnsolicitedNotificationListener)l);
} }
} }
...@@ -185,8 +183,7 @@ final class EventSupport { ...@@ -185,8 +183,7 @@ final class EventSupport {
l instanceof NamespaceChangeListener) { l instanceof NamespaceChangeListener) {
NotifierArgs args = new NotifierArgs(nm, filter, ctls, l); NotifierArgs args = new NotifierArgs(nm, filter, ctls, l);
NamingEventNotifier notifier = NamingEventNotifier notifier = notifiers.get(args);
(NamingEventNotifier) notifiers.get(args);
if (notifier == null) { if (notifier == null) {
notifier = new NamingEventNotifier(this, ctx, args, l); notifier = new NamingEventNotifier(this, ctx, args, l);
notifiers.put(args, notifier); notifiers.put(args, notifier);
...@@ -197,9 +194,9 @@ final class EventSupport { ...@@ -197,9 +194,9 @@ final class EventSupport {
if (l instanceof UnsolicitedNotificationListener) { if (l instanceof UnsolicitedNotificationListener) {
// Add listener to this's list of unsolicited notifiers // Add listener to this's list of unsolicited notifiers
if (unsolicited == null) { if (unsolicited == null) {
unsolicited = new Vector(3); unsolicited = new Vector<>(3);
} }
unsolicited.addElement(l); unsolicited.addElement((UnsolicitedNotificationListener)l);
} }
} }
...@@ -207,15 +204,11 @@ final class EventSupport { ...@@ -207,15 +204,11 @@ final class EventSupport {
* Removes <tt>l</tt> from all notifiers in this context. * Removes <tt>l</tt> from all notifiers in this context.
*/ */
synchronized void removeNamingListener(NamingListener l) { synchronized void removeNamingListener(NamingListener l) {
Enumeration allnotifiers = notifiers.elements();
NamingEventNotifier notifier;
if (debug) System.err.println("EventSupport removing listener"); if (debug) System.err.println("EventSupport removing listener");
// Go through list of notifiers, remove 'l' from each. // Go through list of notifiers, remove 'l' from each.
// If 'l' is notifier's only listener, remove notifier too. // If 'l' is notifier's only listener, remove notifier too.
while (allnotifiers.hasMoreElements()) { for (NamingEventNotifier notifier : notifiers.values()) {
notifier = (NamingEventNotifier)allnotifiers.nextElement();
if (notifier != null) { if (notifier != null) {
if (debug) if (debug)
System.err.println("EventSupport removing listener from notifier"); System.err.println("EventSupport removing listener from notifier");
...@@ -305,8 +298,8 @@ final class EventSupport { ...@@ -305,8 +298,8 @@ final class EventSupport {
synchronized void cleanup() { synchronized void cleanup() {
if (debug) System.err.println("EventSupport clean up"); if (debug) System.err.println("EventSupport clean up");
if (notifiers != null) { if (notifiers != null) {
for (Enumeration ns = notifiers.elements(); ns.hasMoreElements(); ) { for (NamingEventNotifier notifier : notifiers.values()) {
((NamingEventNotifier) ns.nextElement()).stop(); notifier.stop();
} }
notifiers = null; notifiers = null;
} }
...@@ -328,7 +321,8 @@ final class EventSupport { ...@@ -328,7 +321,8 @@ final class EventSupport {
* them to the registered listeners. * them to the registered listeners.
* Package private; used by NamingEventNotifier to fire events * Package private; used by NamingEventNotifier to fire events
*/ */
synchronized void queueEvent(EventObject event, Vector vector) { synchronized void queueEvent(EventObject event,
Vector<? extends NamingListener> vector) {
if (eventQueue == null) if (eventQueue == null)
eventQueue = new EventQueue(); eventQueue = new EventQueue();
...@@ -340,7 +334,9 @@ final class EventSupport { ...@@ -340,7 +334,9 @@ final class EventSupport {
* of this event will not take effect until after the event is * of this event will not take effect until after the event is
* delivered. * delivered.
*/ */
Vector v = (Vector)vector.clone(); @SuppressWarnings("unchecked") // clone()
Vector<NamingListener> v =
(Vector<NamingListener>)vector.clone();
eventQueue.enqueue(event, v); eventQueue.enqueue(event, v);
} }
......
/* /*
* Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,8 +26,6 @@ ...@@ -26,8 +26,6 @@
package com.sun.jndi.ldap; package com.sun.jndi.ldap;
import java.io.IOException; import java.io.IOException;
import java.io.Serializable;
import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
import javax.naming.*; import javax.naming.*;
...@@ -50,11 +48,12 @@ final class LdapAttribute extends BasicAttribute { ...@@ -50,11 +48,12 @@ final class LdapAttribute extends BasicAttribute {
// these two are used to reconstruct the baseCtx if this attribute has // these two are used to reconstruct the baseCtx if this attribute has
// been serialized ( // been serialized (
private String baseCtxURL; private String baseCtxURL;
private Hashtable baseCtxEnv; private Hashtable<String, ? super String> baseCtxEnv;
@SuppressWarnings("unchecked") // clone()
public Object clone() { public Object clone() {
LdapAttribute attr = new LdapAttribute(this.attrID, baseCtx, rdn); LdapAttribute attr = new LdapAttribute(this.attrID, baseCtx, rdn);
attr.values = (Vector)values.clone(); attr.values = (Vector<Object>)values.clone();
return attr; return attr;
} }
...@@ -112,7 +111,7 @@ final class LdapAttribute extends BasicAttribute { ...@@ -112,7 +111,7 @@ final class LdapAttribute extends BasicAttribute {
private DirContext getBaseCtx() throws NamingException { private DirContext getBaseCtx() throws NamingException {
if(baseCtx == null) { if(baseCtx == null) {
if (baseCtxEnv == null) { if (baseCtxEnv == null) {
baseCtxEnv = new Hashtable(3); baseCtxEnv = new Hashtable<String, String>(3);
} }
baseCtxEnv.put(Context.INITIAL_CONTEXT_FACTORY, baseCtxEnv.put(Context.INITIAL_CONTEXT_FACTORY,
"com.sun.jndi.ldap.LdapCtxFactory"); "com.sun.jndi.ldap.LdapCtxFactory");
...@@ -144,9 +143,10 @@ final class LdapAttribute extends BasicAttribute { ...@@ -144,9 +143,10 @@ final class LdapAttribute extends BasicAttribute {
* we are serialized. This must be called _before_ the object is * we are serialized. This must be called _before_ the object is
* serialized!!! * serialized!!!
*/ */
@SuppressWarnings("unchecked") // clone()
private void setBaseCtxInfo() { private void setBaseCtxInfo() {
Hashtable realEnv = null; Hashtable<String, Object> realEnv = null;
Hashtable secureEnv = null; Hashtable<String, Object> secureEnv = null;
if (baseCtx != null) { if (baseCtx != null) {
realEnv = ((LdapCtx)baseCtx).envprops; realEnv = ((LdapCtx)baseCtx).envprops;
...@@ -156,16 +156,14 @@ final class LdapAttribute extends BasicAttribute { ...@@ -156,16 +156,14 @@ final class LdapAttribute extends BasicAttribute {
if(realEnv != null && realEnv.size() > 0 ) { if(realEnv != null && realEnv.size() > 0 ) {
// remove any security credentials - otherwise the serialized form // remove any security credentials - otherwise the serialized form
// would store them in the clear // would store them in the clear
Enumeration keys = realEnv.keys(); for (String key : realEnv.keySet()){
while(keys.hasMoreElements()) {
String key = (String)keys.nextElement();
if (key.indexOf("security") != -1 ) { if (key.indexOf("security") != -1 ) {
//if we need to remove props, we must do it to a clone //if we need to remove props, we must do it to a clone
//of the environment. cloning is expensive, so we only do //of the environment. cloning is expensive, so we only do
//it if we have to. //it if we have to.
if(secureEnv == null) { if(secureEnv == null) {
secureEnv = (Hashtable)realEnv.clone(); secureEnv = (Hashtable<String, Object>)realEnv.clone();
} }
secureEnv.remove(key); secureEnv.remove(key);
} }
......
/* /*
* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,11 +28,13 @@ package com.sun.jndi.ldap; ...@@ -28,11 +28,13 @@ package com.sun.jndi.ldap;
import java.util.Vector; import java.util.Vector;
import javax.naming.*; import javax.naming.*;
import javax.naming.directory.*; import javax.naming.directory.*;
import javax.naming.ldap.Control;
import javax.naming.spi.*; import javax.naming.spi.*;
import com.sun.jndi.toolkit.ctx.Continuation; import com.sun.jndi.toolkit.ctx.Continuation;
final class LdapBindingEnumeration extends LdapNamingEnumeration { final class LdapBindingEnumeration
extends AbstractLdapNamingEnumeration<Binding> {
LdapBindingEnumeration(LdapCtx homeCtx, LdapResult answer, Name remain, LdapBindingEnumeration(LdapCtx homeCtx, LdapResult answer, Name remain,
Continuation cont) throws NamingException Continuation cont) throws NamingException
...@@ -40,8 +42,9 @@ final class LdapBindingEnumeration extends LdapNamingEnumeration { ...@@ -40,8 +42,9 @@ final class LdapBindingEnumeration extends LdapNamingEnumeration {
super(homeCtx, answer, remain, cont); super(homeCtx, answer, remain, cont);
} }
protected NameClassPair @Override
createItem(String dn, Attributes attrs, Vector respCtls) protected Binding
createItem(String dn, Attributes attrs, Vector<Control> respCtls)
throws NamingException { throws NamingException {
Object obj = null; Object obj = null;
...@@ -85,9 +88,10 @@ final class LdapBindingEnumeration extends LdapNamingEnumeration { ...@@ -85,9 +88,10 @@ final class LdapBindingEnumeration extends LdapNamingEnumeration {
return binding; return binding;
} }
protected LdapNamingEnumeration @Override
getReferredResults(LdapReferralContext refCtx) throws NamingException{ protected LdapBindingEnumeration getReferredResults(
LdapReferralContext refCtx) throws NamingException{
// repeat the original operation at the new context // repeat the original operation at the new context
return (LdapNamingEnumeration) refCtx.listBindings(listArg); return (LdapBindingEnumeration)refCtx.listBindings(listArg);
} }
} }
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
package com.sun.jndi.ldap; package com.sun.jndi.ldap;
import java.net.*;
import java.io.*; import java.io.*;
import java.util.Vector; import java.util.Vector;
import java.util.Hashtable; import java.util.Hashtable;
...@@ -81,7 +80,8 @@ public final class LdapClient implements PooledConnection { ...@@ -81,7 +80,8 @@ public final class LdapClient implements PooledConnection {
static final boolean caseIgnore = true; static final boolean caseIgnore = true;
// Default list of binary attributes // Default list of binary attributes
private static final Hashtable defaultBinaryAttrs = new Hashtable(23,0.75f); private static final Hashtable<String, Boolean> defaultBinaryAttrs =
new Hashtable<>(23,0.75f);
static { static {
defaultBinaryAttrs.put("userpassword", Boolean.TRUE); //2.5.4.35 defaultBinaryAttrs.put("userpassword", Boolean.TRUE); //2.5.4.35
defaultBinaryAttrs.put("javaserializeddata", Boolean.TRUE); defaultBinaryAttrs.put("javaserializeddata", Boolean.TRUE);
...@@ -146,7 +146,7 @@ public final class LdapClient implements PooledConnection { ...@@ -146,7 +146,7 @@ public final class LdapClient implements PooledConnection {
synchronized LdapResult synchronized LdapResult
authenticate(boolean initial, String name, Object pw, int version, authenticate(boolean initial, String name, Object pw, int version,
String authMechanism, Control[] ctls, Hashtable env) String authMechanism, Control[] ctls, Hashtable<?,?> env)
throws NamingException { throws NamingException {
authenticateCalled = true; authenticateCalled = true;
...@@ -516,8 +516,8 @@ public final class LdapClient implements PooledConnection { ...@@ -516,8 +516,8 @@ public final class LdapClient implements PooledConnection {
LdapResult search(String dn, int scope, int deref, int sizeLimit, LdapResult search(String dn, int scope, int deref, int sizeLimit,
int timeLimit, boolean attrsOnly, String attrs[], int timeLimit, boolean attrsOnly, String attrs[],
String filter, int batchSize, Control[] reqCtls, String filter, int batchSize, Control[] reqCtls,
Hashtable binaryAttrs, boolean waitFirstReply, Hashtable<String, Boolean> binaryAttrs,
int replyQueueCapacity) boolean waitFirstReply, int replyQueueCapacity)
throws IOException, NamingException { throws IOException, NamingException {
ensureOpen(); ensureOpen();
...@@ -586,7 +586,7 @@ public final class LdapClient implements PooledConnection { ...@@ -586,7 +586,7 @@ public final class LdapClient implements PooledConnection {
* Retrieve the next batch of entries and/or referrals. * Retrieve the next batch of entries and/or referrals.
*/ */
LdapResult getSearchReply(int batchSize, LdapResult res, LdapResult getSearchReply(int batchSize, LdapResult res,
Hashtable binaryAttrs) throws IOException, NamingException { Hashtable<String, Boolean> binaryAttrs) throws IOException, NamingException {
ensureOpen(); ensureOpen();
...@@ -600,7 +600,7 @@ public final class LdapClient implements PooledConnection { ...@@ -600,7 +600,7 @@ public final class LdapClient implements PooledConnection {
} }
private LdapResult getSearchReply(LdapRequest req, private LdapResult getSearchReply(LdapRequest req,
int batchSize, LdapResult res, Hashtable binaryAttrs) int batchSize, LdapResult res, Hashtable<String, Boolean> binaryAttrs)
throws IOException, NamingException { throws IOException, NamingException {
if (batchSize == 0) if (batchSize == 0)
...@@ -610,7 +610,7 @@ public final class LdapClient implements PooledConnection { ...@@ -610,7 +610,7 @@ public final class LdapClient implements PooledConnection {
res.entries.setSize(0); // clear the (previous) set of entries res.entries.setSize(0); // clear the (previous) set of entries
} else { } else {
res.entries = res.entries =
new Vector(batchSize == Integer.MAX_VALUE ? 32 : batchSize); new Vector<>(batchSize == Integer.MAX_VALUE ? 32 : batchSize);
} }
if (res.referrals != null) { if (res.referrals != null) {
...@@ -660,7 +660,7 @@ public final class LdapClient implements PooledConnection { ...@@ -660,7 +660,7 @@ public final class LdapClient implements PooledConnection {
} else if ((seq == LDAP_REP_SEARCH_REF) && isLdapv3) { } else if ((seq == LDAP_REP_SEARCH_REF) && isLdapv3) {
// handle LDAPv3 search reference // handle LDAPv3 search reference
Vector URLs = new Vector(4); Vector<String> URLs = new Vector<>(4);
// %%% Although not strictly correct, some LDAP servers // %%% Although not strictly correct, some LDAP servers
// encode the SEQUENCE OF tag in the SearchResultRef // encode the SEQUENCE OF tag in the SearchResultRef
...@@ -676,7 +676,7 @@ public final class LdapClient implements PooledConnection { ...@@ -676,7 +676,7 @@ public final class LdapClient implements PooledConnection {
} }
if (res.referrals == null) { if (res.referrals == null) {
res.referrals = new Vector(4); res.referrals = new Vector<>(4);
} }
res.referrals.addElement(URLs); res.referrals.addElement(URLs);
res.resControls = isLdapv3 ? parseControls(replyBer) : null; res.resControls = isLdapv3 ? parseControls(replyBer) : null;
...@@ -700,7 +700,8 @@ public final class LdapClient implements PooledConnection { ...@@ -700,7 +700,8 @@ public final class LdapClient implements PooledConnection {
return res; return res;
} }
private Attribute parseAttribute(BerDecoder ber, Hashtable binaryAttrs) private Attribute parseAttribute(BerDecoder ber,
Hashtable<String, Boolean> binaryAttrs)
throws IOException { throws IOException {
int len[] = new int[1]; int len[] = new int[1];
...@@ -742,7 +743,8 @@ public final class LdapClient implements PooledConnection { ...@@ -742,7 +743,8 @@ public final class LdapClient implements PooledConnection {
return len[0]; return len[0];
} }
private boolean isBinaryValued(String attrid, Hashtable binaryAttrs) { private boolean isBinaryValued(String attrid,
Hashtable<String, Boolean> binaryAttrs) {
String id = attrid.toLowerCase(); String id = attrid.toLowerCase();
return ((id.indexOf(";binary") != -1) || return ((id.indexOf(";binary") != -1) ||
...@@ -763,7 +765,7 @@ public final class LdapClient implements PooledConnection { ...@@ -763,7 +765,7 @@ public final class LdapClient implements PooledConnection {
(replyBer.bytesLeft() > 0) && (replyBer.bytesLeft() > 0) &&
(replyBer.peekByte() == LDAP_REP_REFERRAL)) { (replyBer.peekByte() == LDAP_REP_REFERRAL)) {
Vector URLs = new Vector(4); Vector<String> URLs = new Vector<>(4);
int[] seqlen = new int[1]; int[] seqlen = new int[1];
replyBer.parseSeq(seqlen); replyBer.parseSeq(seqlen);
...@@ -775,18 +777,18 @@ public final class LdapClient implements PooledConnection { ...@@ -775,18 +777,18 @@ public final class LdapClient implements PooledConnection {
} }
if (res.referrals == null) { if (res.referrals == null) {
res.referrals = new Vector(4); res.referrals = new Vector<>(4);
} }
res.referrals.addElement(URLs); res.referrals.addElement(URLs);
} }
} }
// package entry point; used by Connection // package entry point; used by Connection
static Vector parseControls(BerDecoder replyBer) throws IOException { static Vector<Control> parseControls(BerDecoder replyBer) throws IOException {
// handle LDAPv3 controls (if present) // handle LDAPv3 controls (if present)
if ((replyBer.bytesLeft() > 0) && (replyBer.peekByte() == LDAP_CONTROLS)) { if ((replyBer.bytesLeft() > 0) && (replyBer.peekByte() == LDAP_CONTROLS)) {
Vector ctls = new Vector(4); Vector<Control> ctls = new Vector<>(4);
String controlOID; String controlOID;
boolean criticality = false; // default boolean criticality = false; // default
byte[] controlValue = null; // optional byte[] controlValue = null; // optional
...@@ -957,7 +959,7 @@ public final class LdapClient implements PooledConnection { ...@@ -957,7 +959,7 @@ public final class LdapClient implements PooledConnection {
ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR); ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
ber.encodeString(attr.getID(), isLdapv3); ber.encodeString(attr.getID(), isLdapv3);
ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR | 1); ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR | 1);
NamingEnumeration enum_ = attr.getAll(); NamingEnumeration<?> enum_ = attr.getAll();
Object val; Object val;
while (enum_.hasMore()) { while (enum_.hasMore()) {
val = enum_.next(); val = enum_.next();
...@@ -1007,9 +1009,10 @@ public final class LdapClient implements PooledConnection { ...@@ -1007,9 +1009,10 @@ public final class LdapClient implements PooledConnection {
ber.beginSeq(LDAP_REQ_ADD); ber.beginSeq(LDAP_REQ_ADD);
ber.encodeString(entry.DN, isLdapv3); ber.encodeString(entry.DN, isLdapv3);
ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR); ber.beginSeq(Ber.ASN_SEQUENCE | Ber.ASN_CONSTRUCTOR);
NamingEnumeration enum_ = entry.attributes.getAll(); NamingEnumeration<? extends Attribute> enum_ =
entry.attributes.getAll();
while (enum_.hasMore()) { while (enum_.hasMore()) {
attr = (Attribute)enum_.next(); attr = enum_.next();
// zero values is not permitted // zero values is not permitted
if (hasNoValue(attr)) { if (hasNoValue(attr)) {
...@@ -1474,7 +1477,7 @@ public final class LdapClient implements PooledConnection { ...@@ -1474,7 +1477,7 @@ public final class LdapClient implements PooledConnection {
// removeUnsolicited() is invoked to remove an LdapCtx from this client. // removeUnsolicited() is invoked to remove an LdapCtx from this client.
// //
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
private Vector unsolicited = new Vector(3); private Vector<LdapCtx> unsolicited = new Vector<>(3);
void addUnsolicited(LdapCtx ctx) { void addUnsolicited(LdapCtx ctx) {
if (debug > 0) { if (debug > 0) {
System.err.println("LdapClient.addUnsolicited" + ctx); System.err.println("LdapClient.addUnsolicited" + ctx);
...@@ -1500,70 +1503,70 @@ public final class LdapClient implements PooledConnection { ...@@ -1500,70 +1503,70 @@ public final class LdapClient implements PooledConnection {
if (debug > 0) { if (debug > 0) {
System.err.println("LdapClient.processUnsolicited"); System.err.println("LdapClient.processUnsolicited");
} }
synchronized (unsolicited) { synchronized (unsolicited) {
try { try {
// Parse the response // Parse the response
LdapResult res = new LdapResult(); LdapResult res = new LdapResult();
ber.parseSeq(null); // init seq ber.parseSeq(null); // init seq
ber.parseInt(); // msg id; should be 0; ignored ber.parseInt(); // msg id; should be 0; ignored
if (ber.parseByte() != LDAP_REP_EXTENSION) { if (ber.parseByte() != LDAP_REP_EXTENSION) {
throw new IOException( throw new IOException(
"Unsolicited Notification must be an Extended Response"); "Unsolicited Notification must be an Extended Response");
} }
ber.parseLength(); ber.parseLength();
parseExtResponse(ber, res); parseExtResponse(ber, res);
if (DISCONNECT_OID.equals(res.extensionId)) {
// force closing of connection
forceClose(pooled);
}
if (unsolicited.size() > 0) {
// Create an UnsolicitedNotification using the parsed data
// Need a 'ctx' object because we want to use the context's
// list of provider control factories.
UnsolicitedNotification notice = new UnsolicitedResponseImpl(
res.extensionId,
res.extensionValue,
res.referrals,
res.status,
res.errorMessage,
res.matchedDN,
(res.resControls != null) ?
((LdapCtx)unsolicited.elementAt(0)).convertControls(res.resControls) :
null);
// Fire UnsolicitedNotification events to listeners
notifyUnsolicited(notice);
// If "disconnect" notification,
// notify unsolicited listeners via NamingException
if (DISCONNECT_OID.equals(res.extensionId)) { if (DISCONNECT_OID.equals(res.extensionId)) {
notifyUnsolicited( // force closing of connection
new CommunicationException("Connection closed")); forceClose(pooled);
} }
}
} catch (IOException e) {
if (unsolicited.size() == 0)
return; // no one registered; ignore
NamingException ne = new CommunicationException( if (unsolicited.size() > 0) {
"Problem parsing unsolicited notification"); // Create an UnsolicitedNotification using the parsed data
ne.setRootCause(e); // Need a 'ctx' object because we want to use the context's
// list of provider control factories.
UnsolicitedNotification notice = new UnsolicitedResponseImpl(
res.extensionId,
res.extensionValue,
res.referrals,
res.status,
res.errorMessage,
res.matchedDN,
(res.resControls != null) ?
unsolicited.elementAt(0).convertControls(res.resControls) :
null);
// Fire UnsolicitedNotification events to listeners
notifyUnsolicited(notice);
// If "disconnect" notification,
// notify unsolicited listeners via NamingException
if (DISCONNECT_OID.equals(res.extensionId)) {
notifyUnsolicited(
new CommunicationException("Connection closed"));
}
}
} catch (IOException e) {
if (unsolicited.size() == 0)
return; // no one registered; ignore
NamingException ne = new CommunicationException(
"Problem parsing unsolicited notification");
ne.setRootCause(e);
notifyUnsolicited(ne); notifyUnsolicited(ne);
} catch (NamingException e) { } catch (NamingException e) {
notifyUnsolicited(e); notifyUnsolicited(e);
}
} }
}
} }
private void notifyUnsolicited(Object e) { private void notifyUnsolicited(Object e) {
for (int i = 0; i < unsolicited.size(); i++) { for (int i = 0; i < unsolicited.size(); i++) {
((LdapCtx)unsolicited.elementAt(i)).fireUnsolicited(e); unsolicited.elementAt(i).fireUnsolicited(e);
} }
if (e instanceof NamingException) { if (e instanceof NamingException) {
unsolicited.setSize(0); // no more listeners after exception unsolicited.setSize(0); // no more listeners after exception
...@@ -1584,7 +1587,7 @@ public final class LdapClient implements PooledConnection { ...@@ -1584,7 +1587,7 @@ public final class LdapClient implements PooledConnection {
static LdapClient getInstance(boolean usePool, String hostname, int port, static LdapClient getInstance(boolean usePool, String hostname, int port,
String factory, int connectTimeout, int readTimeout, OutputStream trace, String factory, int connectTimeout, int readTimeout, OutputStream trace,
int version, String authMechanism, Control[] ctls, String protocol, int version, String authMechanism, Control[] ctls, String protocol,
String user, Object passwd, Hashtable env) throws NamingException { String user, Object passwd, Hashtable<?,?> env) throws NamingException {
if (usePool) { if (usePool) {
if (LdapPoolManager.isPoolingAllowed(factory, trace, if (LdapPoolManager.isPoolingAllowed(factory, trace,
......
/* /*
* Copyright (c) 1999, 2006, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,7 +28,6 @@ package com.sun.jndi.ldap; ...@@ -28,7 +28,6 @@ package com.sun.jndi.ldap;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
import java.util.Enumeration; import java.util.Enumeration;
import java.net.MalformedURLException;
import javax.naming.*; import javax.naming.*;
import javax.naming.directory.*; import javax.naming.directory.*;
...@@ -119,9 +118,9 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor ...@@ -119,9 +118,9 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor
int size = 0; // number of URLs int size = 0; // number of URLs
String[] urls = new String[ref.size()]; String[] urls = new String[ref.size()];
Enumeration addrs = ref.getAll(); Enumeration<RefAddr> addrs = ref.getAll();
while (addrs.hasMoreElements()) { while (addrs.hasMoreElements()) {
RefAddr addr = (RefAddr)addrs.nextElement(); RefAddr addr = addrs.nextElement();
if ((addr instanceof StringRefAddr) && if ((addr instanceof StringRefAddr) &&
addr.getType().equals(ADDRESS_TYPE)) { addr.getType().equals(ADDRESS_TYPE)) {
...@@ -145,7 +144,7 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor ...@@ -145,7 +144,7 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor
// ------------ Utilities used by other classes ---------------- // ------------ Utilities used by other classes ----------------
public static DirContext getLdapCtxInstance(Object urlInfo, Hashtable env) public static DirContext getLdapCtxInstance(Object urlInfo, Hashtable<?,?> env)
throws NamingException { throws NamingException {
if (urlInfo instanceof String) { if (urlInfo instanceof String) {
...@@ -158,7 +157,7 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor ...@@ -158,7 +157,7 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor
} }
} }
private static DirContext getUsingURL(String url, Hashtable env) private static DirContext getUsingURL(String url, Hashtable<?,?> env)
throws NamingException { throws NamingException {
DirContext ctx = null; DirContext ctx = null;
LdapURL ldapUrl = new LdapURL(url); LdapURL ldapUrl = new LdapURL(url);
...@@ -202,7 +201,7 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor ...@@ -202,7 +201,7 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor
* If all URLs fail, throw one of the exceptions arbitrarily. * If all URLs fail, throw one of the exceptions arbitrarily.
* Not pretty, but potentially more informative than returning null. * Not pretty, but potentially more informative than returning null.
*/ */
private static DirContext getUsingURLs(String[] urls, Hashtable env) private static DirContext getUsingURLs(String[] urls, Hashtable<?,?> env)
throws NamingException { throws NamingException {
NamingException ne = null; NamingException ne = null;
DirContext ctx = null; DirContext ctx = null;
...@@ -221,8 +220,8 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor ...@@ -221,8 +220,8 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor
/** /**
* Used by Obj and obj/RemoteToAttrs too so must be public * Used by Obj and obj/RemoteToAttrs too so must be public
*/ */
public static Attribute createTypeNameAttr(Class cl) { public static Attribute createTypeNameAttr(Class<?> cl) {
Vector v = new Vector(10); Vector<String> v = new Vector<>(10);
String[] types = getTypeNames(cl, v); String[] types = getTypeNames(cl, v);
if (types.length > 0) { if (types.length > 0) {
BasicAttribute tAttr = BasicAttribute tAttr =
...@@ -235,7 +234,7 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor ...@@ -235,7 +234,7 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor
return null; return null;
} }
private static String[] getTypeNames(Class currentClass, Vector v) { private static String[] getTypeNames(Class<?> currentClass, Vector<String> v) {
getClassesAux(currentClass, v); getClassesAux(currentClass, v);
Class[] members = currentClass.getInterfaces(); Class[] members = currentClass.getInterfaces();
...@@ -244,13 +243,14 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor ...@@ -244,13 +243,14 @@ final public class LdapCtxFactory implements ObjectFactory, InitialContextFactor
} }
String[] ret = new String[v.size()]; String[] ret = new String[v.size()];
int i = 0; int i = 0;
for (java.util.Enumeration e = v.elements(); e.hasMoreElements();) {
ret[i++] = (String)e.nextElement(); for (String name : v) {
ret[i++] = name;
} }
return ret; return ret;
} }
private static void getClassesAux(Class currentClass, Vector v) { private static void getClassesAux(Class<?> currentClass, Vector<String> v) {
if (!v.contains(currentClass.getName())) { if (!v.contains(currentClass.getName())) {
v.addElement(currentClass.getName()); v.addElement(currentClass.getName());
} }
......
/* /*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,7 +27,7 @@ package com.sun.jndi.ldap; ...@@ -27,7 +27,7 @@ package com.sun.jndi.ldap;
import java.util.Vector; import java.util.Vector;
import javax.naming.directory.Attributes; import javax.naming.directory.Attributes;
import javax.naming.directory.Attribute; import javax.naming.ldap.Control;
/** /**
* A holder for an LDAP entry read from an LDAP server. * A holder for an LDAP entry read from an LDAP server.
...@@ -38,14 +38,14 @@ import javax.naming.directory.Attribute; ...@@ -38,14 +38,14 @@ import javax.naming.directory.Attribute;
final class LdapEntry { final class LdapEntry {
String DN; String DN;
Attributes attributes; Attributes attributes;
Vector respCtls = null; Vector<Control> respCtls = null;
LdapEntry(String DN, Attributes attrs) { LdapEntry(String DN, Attributes attrs) {
this.DN = DN; this.DN = DN;
this.attributes = attrs; this.attributes = attrs;
} }
LdapEntry(String DN, Attributes attrs, Vector respCtls) { LdapEntry(String DN, Attributes attrs, Vector<Control> respCtls) {
this.DN = DN; this.DN = DN;
this.attributes = attrs; this.attributes = attrs;
this.respCtls = respCtls; this.respCtls = respCtls;
......
/* /*
* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -78,7 +78,7 @@ import javax.naming.directory.BasicAttributes; ...@@ -78,7 +78,7 @@ import javax.naming.directory.BasicAttributes;
public final class LdapName implements Name { public final class LdapName implements Name {
private transient String unparsed; // if non-null, the DN in unparsed form private transient String unparsed; // if non-null, the DN in unparsed form
private transient Vector rdns; // parsed name components private transient Vector<Rdn> rdns; // parsed name components
private transient boolean valuesCaseSensitive = false; private transient boolean valuesCaseSensitive = false;
/** /**
...@@ -97,9 +97,10 @@ public final class LdapName implements Name { ...@@ -97,9 +97,10 @@ public final class LdapName implements Name {
* Constructs an LDAP name given its parsed components and, optionally * Constructs an LDAP name given its parsed components and, optionally
* (if "name" is not null), the unparsed DN. * (if "name" is not null), the unparsed DN.
*/ */
private LdapName(String name, Vector rdns) { @SuppressWarnings("unchecked") // clone()
private LdapName(String name, Vector<Rdn> rdns) {
unparsed = name; unparsed = name;
this.rdns = (Vector)rdns.clone(); this.rdns = (Vector<Rdn>)rdns.clone();
} }
/* /*
...@@ -107,9 +108,9 @@ public final class LdapName implements Name { ...@@ -107,9 +108,9 @@ public final class LdapName implements Name {
* of "rdns" in the range [beg,end)) and, optionally * of "rdns" in the range [beg,end)) and, optionally
* (if "name" is not null), the unparsed DN. * (if "name" is not null), the unparsed DN.
*/ */
private LdapName(String name, Vector rdns, int beg, int end) { private LdapName(String name, Vector<Rdn> rdns, int beg, int end) {
unparsed = name; unparsed = name;
this.rdns = new Vector(); this.rdns = new Vector<>();
for (int i = beg; i < end; i++) { for (int i = beg; i < end; i++) {
this.rdns.addElement(rdns.elementAt(i)); this.rdns.addElement(rdns.elementAt(i));
} }
...@@ -130,7 +131,7 @@ public final class LdapName implements Name { ...@@ -130,7 +131,7 @@ public final class LdapName implements Name {
if (i < rdns.size() - 1) { if (i < rdns.size() - 1) {
buf.append(','); buf.append(',');
} }
Rdn rdn = (Rdn)rdns.elementAt(i); Rdn rdn = rdns.elementAt(i);
buf.append(rdn); buf.append(rdn);
} }
...@@ -155,8 +156,8 @@ public final class LdapName implements Name { ...@@ -155,8 +156,8 @@ public final class LdapName implements Name {
int minSize = Math.min(rdns.size(), that.rdns.size()); int minSize = Math.min(rdns.size(), that.rdns.size());
for (int i = 0 ; i < minSize; i++) { for (int i = 0 ; i < minSize; i++) {
// Compare a single pair of RDNs. // Compare a single pair of RDNs.
Rdn rdn1 = (Rdn)rdns.elementAt(i); Rdn rdn1 = rdns.elementAt(i);
Rdn rdn2 = (Rdn)that.rdns.elementAt(i); Rdn rdn2 = that.rdns.elementAt(i);
int diff = rdn1.compareTo(rdn2); int diff = rdn1.compareTo(rdn2);
if (diff != 0) { if (diff != 0) {
...@@ -172,7 +173,7 @@ public final class LdapName implements Name { ...@@ -172,7 +173,7 @@ public final class LdapName implements Name {
// For each RDN... // For each RDN...
for (int i = 0; i < rdns.size(); i++) { for (int i = 0; i < rdns.size(); i++) {
Rdn rdn = (Rdn)rdns.elementAt(i); Rdn rdn = rdns.elementAt(i);
hash += rdn.hashCode(); hash += rdn.hashCode();
} }
return hash; return hash;
...@@ -186,14 +187,14 @@ public final class LdapName implements Name { ...@@ -186,14 +187,14 @@ public final class LdapName implements Name {
return rdns.isEmpty(); return rdns.isEmpty();
} }
public Enumeration getAll() { public Enumeration<String> getAll() {
final Enumeration enum_ = rdns.elements(); final Enumeration<Rdn> enum_ = rdns.elements();
return new Enumeration () { return new Enumeration<String>() {
public boolean hasMoreElements() { public boolean hasMoreElements() {
return enum_.hasMoreElements(); return enum_.hasMoreElements();
} }
public Object nextElement() { public String nextElement() {
return enum_.nextElement().toString(); return enum_.nextElement().toString();
} }
}; };
...@@ -254,7 +255,7 @@ public final class LdapName implements Name { ...@@ -254,7 +255,7 @@ public final class LdapName implements Name {
Rdn rdn; Rdn rdn;
if (n instanceof LdapName) { if (n instanceof LdapName) {
LdapName ln = (LdapName)n; LdapName ln = (LdapName)n;
rdn = (Rdn)ln.rdns.elementAt(i - beg); rdn = ln.rdns.elementAt(i - beg);
} else { } else {
String rdnString = n.get(i - beg); String rdnString = n.get(i - beg);
try { try {
...@@ -286,9 +287,9 @@ public final class LdapName implements Name { ...@@ -286,9 +287,9 @@ public final class LdapName implements Name {
rdns.insertElementAt(s.rdns.elementAt(i), pos++); rdns.insertElementAt(s.rdns.elementAt(i), pos++);
} }
} else { } else {
Enumeration comps = suffix.getAll(); Enumeration<String> comps = suffix.getAll();
while (comps.hasMoreElements()) { while (comps.hasMoreElements()) {
DnParser p = new DnParser((String)comps.nextElement(), DnParser p = new DnParser(comps.nextElement(),
valuesCaseSensitive); valuesCaseSensitive);
rdns.insertElementAt(p.getRdn(), pos++); rdns.insertElementAt(p.getRdn(), pos++);
} }
...@@ -406,9 +407,9 @@ public final class LdapName implements Name { ...@@ -406,9 +407,9 @@ public final class LdapName implements Name {
/* /*
* Parses the DN, returning a Vector of its RDNs. * Parses the DN, returning a Vector of its RDNs.
*/ */
Vector getDn() throws InvalidNameException { Vector<Rdn> getDn() throws InvalidNameException {
cur = 0; cur = 0;
Vector rdns = new Vector(len / 3 + 10); // leave room for growth Vector<Rdn> rdns = new Vector<>(len / 3 + 10); // leave room for growth
if (len == 0) { if (len == 0) {
return rdns; return rdns;
...@@ -595,7 +596,7 @@ public final class LdapName implements Name { ...@@ -595,7 +596,7 @@ public final class LdapName implements Name {
* A vector of the TypeAndValue elements of this Rdn. * A vector of the TypeAndValue elements of this Rdn.
* It is sorted to facilitate set operations. * It is sorted to facilitate set operations.
*/ */
private final Vector tvs = new Vector(); private final Vector<TypeAndValue> tvs = new Vector<>();
void add(TypeAndValue tv) { void add(TypeAndValue tv) {
...@@ -636,7 +637,7 @@ public final class LdapName implements Name { ...@@ -636,7 +637,7 @@ public final class LdapName implements Name {
int minSize = Math.min(tvs.size(), that.tvs.size()); int minSize = Math.min(tvs.size(), that.tvs.size());
for (int i = 0; i < minSize; i++) { for (int i = 0; i < minSize; i++) {
// Compare a single pair of type/value pairs. // Compare a single pair of type/value pairs.
TypeAndValue tv = (TypeAndValue)tvs.elementAt(i); TypeAndValue tv = tvs.elementAt(i);
int diff = tv.compareTo(that.tvs.elementAt(i)); int diff = tv.compareTo(that.tvs.elementAt(i));
if (diff != 0) { if (diff != 0) {
return diff; return diff;
...@@ -662,7 +663,7 @@ public final class LdapName implements Name { ...@@ -662,7 +663,7 @@ public final class LdapName implements Name {
Attribute attr; Attribute attr;
for (int i = 0; i < tvs.size(); i++) { for (int i = 0; i < tvs.size(); i++) {
tv = (TypeAndValue) tvs.elementAt(i); tv = tvs.elementAt(i);
if ((attr = attrs.get(tv.getType())) == null) { if ((attr = attrs.get(tv.getType())) == null) {
attrs.put(tv.getType(), tv.getUnescapedValue()); attrs.put(tv.getType(), tv.getUnescapedValue());
} else { } else {
......
/* /*
* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,267 +27,25 @@ package com.sun.jndi.ldap; ...@@ -27,267 +27,25 @@ package com.sun.jndi.ldap;
import javax.naming.*; import javax.naming.*;
import javax.naming.directory.*; import javax.naming.directory.*;
import javax.naming.spi.*;
import com.sun.jndi.toolkit.ctx.Continuation; import com.sun.jndi.toolkit.ctx.Continuation;
import java.util.NoSuchElementException;
import java.util.Vector; import java.util.Vector;
import javax.naming.ldap.LdapName; import javax.naming.ldap.Control;
/**
* Basic enumeration for NameClassPair, Binding, and SearchResults.
*/
class LdapNamingEnumeration implements NamingEnumeration, ReferralEnumeration { final class LdapNamingEnumeration
protected Name listArg; extends AbstractLdapNamingEnumeration<NameClassPair> {
private boolean cleaned = false;
private LdapResult res;
private LdapClient enumClnt;
private Continuation cont; // used to fill in exceptions
private Vector entries = null;
private int limit = 0;
private int posn = 0;
protected LdapCtx homeCtx;
private LdapReferralException refEx = null;
private NamingException errEx = null;
private static final String defaultClassName = DirContext.class.getName(); private static final String defaultClassName = DirContext.class.getName();
/*
* Record the next set of entries and/or referrals.
*/
LdapNamingEnumeration(LdapCtx homeCtx, LdapResult answer, Name listArg, LdapNamingEnumeration(LdapCtx homeCtx, LdapResult answer, Name listArg,
Continuation cont) throws NamingException { Continuation cont) throws NamingException {
super(homeCtx, answer, listArg, cont);
// These checks are to accommodate referrals and limit exceptions
// which will generate an enumeration and defer the exception
// to be thrown at the end of the enumeration.
// All other exceptions are thrown immediately.
// Exceptions shouldn't be thrown here anyhow because
// process_return_code() is called before the constructor
// is called, so these are just safety checks.
if ((answer.status != LdapClient.LDAP_SUCCESS) &&
(answer.status != LdapClient.LDAP_SIZE_LIMIT_EXCEEDED) &&
(answer.status != LdapClient.LDAP_TIME_LIMIT_EXCEEDED) &&
(answer.status != LdapClient.LDAP_ADMIN_LIMIT_EXCEEDED) &&
(answer.status != LdapClient.LDAP_REFERRAL) &&
(answer.status != LdapClient.LDAP_PARTIAL_RESULTS)) {
// %%% need to deal with referral
NamingException e = new NamingException(
LdapClient.getErrorMessage(
answer.status, answer.errorMessage));
throw cont.fillInException(e);
}
// otherwise continue
res = answer;
entries = answer.entries;
limit = (entries == null) ? 0 : entries.size(); // handle empty set
this.listArg = listArg;
this.cont = cont;
if (answer.refEx != null) {
refEx = answer.refEx;
}
// Ensures that context won't get closed from underneath us
this.homeCtx = homeCtx;
homeCtx.incEnumCount();
enumClnt = homeCtx.clnt; // remember
}
public Object nextElement() {
try {
return next();
} catch (NamingException e) {
// can't throw exception
cleanup();
return null;
}
}
public boolean hasMoreElements() {
try {
return hasMore();
} catch (NamingException e) {
// can't throw exception
cleanup();
return false;
}
}
/*
* Retrieve the next set of entries and/or referrals.
*/
private void getNextBatch() throws NamingException {
res = homeCtx.getSearchReply(enumClnt, res);
if (res == null) {
limit = posn = 0;
return;
}
entries = res.entries;
limit = (entries == null) ? 0 : entries.size(); // handle empty set
posn = 0; // reset
// mimimize the number of calls to processReturnCode()
// (expensive when batchSize is small and there are many results)
if ((res.status != LdapClient.LDAP_SUCCESS) ||
((res.status == LdapClient.LDAP_SUCCESS) &&
(res.referrals != null))) {
try {
// convert referrals into a chain of LdapReferralException
homeCtx.processReturnCode(res, listArg);
} catch (LimitExceededException e) {
setNamingException(e);
} catch (PartialResultException e) {
setNamingException(e);
}
}
// merge any newly received referrals with any current referrals
if (res.refEx != null) {
if (refEx == null) {
refEx = res.refEx;
} else {
refEx = refEx.appendUnprocessedReferrals(res.refEx);
}
res.refEx = null; // reset
}
if (res.resControls != null) {
homeCtx.respCtls = res.resControls;
}
}
private boolean more = true; // assume we have something to start with
private boolean hasMoreCalled = false;
/*
* Test if unprocessed entries or referrals exist.
*/
public boolean hasMore() throws NamingException {
if (hasMoreCalled) {
return more;
}
hasMoreCalled = true;
if (!more) {
return false;
} else {
return (more = hasMoreImpl());
}
}
/*
* Retrieve the next entry.
*/
public Object next() throws NamingException {
if (!hasMoreCalled) {
hasMore();
}
hasMoreCalled = false;
return nextImpl();
}
/*
* Test if unprocessed entries or referrals exist.
*/
private boolean hasMoreImpl() throws NamingException {
// when page size is supported, this
// might generate an exception while attempting
// to fetch the next batch to determine
// whether there are any more elements
// test if the current set of entries has been processed
if (posn == limit) {
getNextBatch();
}
// test if any unprocessed entries exist
if (posn < limit) {
return true;
} else {
try {
// try to process another referral
return hasMoreReferrals();
} catch (LdapReferralException e) {
cleanup();
throw e;
} catch (LimitExceededException e) {
cleanup();
throw e;
} catch (PartialResultException e) {
cleanup();
throw e;
} catch (NamingException e) {
cleanup();
PartialResultException pre = new PartialResultException();
pre.setRootCause(e);
throw pre;
}
}
}
/*
* Retrieve the next entry.
*/
private Object nextImpl() throws NamingException {
try {
return nextAux();
} catch (NamingException e) {
cleanup();
throw cont.fillInException(e);
}
}
private Object nextAux() throws NamingException {
if (posn == limit) {
getNextBatch(); // updates posn and limit
}
if (posn >= limit) {
cleanup();
throw new NoSuchElementException("invalid enumeration handle");
}
LdapEntry result = (LdapEntry)entries.elementAt(posn++);
// gets and outputs DN from the entry
return createItem(result.DN, result.attributes, result.respCtls);
}
protected String getAtom(String dn) {
String atom;
// need to strip off all but lowest component of dn
// so that is relative to current context (currentDN)
try {
Name parsed = new LdapName(dn);
return parsed.get(parsed.size() - 1);
} catch (NamingException e) {
return dn;
}
} }
@Override
protected NameClassPair createItem(String dn, Attributes attrs, protected NameClassPair createItem(String dn, Attributes attrs,
Vector respCtls) throws NamingException { Vector<Control> respCtls) throws NamingException {
Attribute attr; Attribute attr;
String className = null; String className = null;
...@@ -313,128 +71,10 @@ class LdapNamingEnumeration implements NamingEnumeration, ReferralEnumeration { ...@@ -313,128 +71,10 @@ class LdapNamingEnumeration implements NamingEnumeration, ReferralEnumeration {
return ncp; return ncp;
} }
/* @Override
* Append the supplied (chain of) referrals onto the protected LdapNamingEnumeration getReferredResults(
* end of the current (chain of) referrals. LdapReferralContext refCtx) throws NamingException {
*/
public void appendUnprocessedReferrals(LdapReferralException ex) {
if (refEx != null) {
refEx = refEx.appendUnprocessedReferrals(ex);
} else {
refEx = ex.appendUnprocessedReferrals(refEx);
}
}
void setNamingException(NamingException e) {
errEx = e;
}
protected LdapNamingEnumeration
getReferredResults(LdapReferralContext refCtx) throws NamingException {
// repeat the original operation at the new context // repeat the original operation at the new context
return (LdapNamingEnumeration)refCtx.list(listArg); return (LdapNamingEnumeration)refCtx.list(listArg);
} }
/*
* Iterate through the URLs of a referral. If successful then perform
* a search operation and merge the received results with the current
* results.
*/
protected boolean hasMoreReferrals() throws NamingException {
if ((refEx != null) &&
(refEx.hasMoreReferrals() ||
refEx.hasMoreReferralExceptions())) {
if (homeCtx.handleReferrals == LdapClient.LDAP_REF_THROW) {
throw (NamingException)(refEx.fillInStackTrace());
}
// process the referrals sequentially
while (true) {
LdapReferralContext refCtx =
(LdapReferralContext)refEx.getReferralContext(
homeCtx.envprops, homeCtx.reqCtls);
try {
update(getReferredResults(refCtx));
break;
} catch (LdapReferralException re) {
// record a previous exception
if (errEx == null) {
errEx = re.getNamingException();
}
refEx = re;
continue;
} finally {
// Make sure we close referral context
refCtx.close();
}
}
return hasMoreImpl();
} else {
cleanup();
if (errEx != null) {
throw errEx;
}
return (false);
}
}
/*
* Merge the entries and/or referrals from the supplied enumeration
* with those of the current enumeration.
*/
protected void update(LdapNamingEnumeration ne) {
// Cleanup previous context first
homeCtx.decEnumCount();
// New enum will have already incremented enum count and recorded clnt
homeCtx = ne.homeCtx;
enumClnt = ne.enumClnt;
// Do this to prevent referral enumeration (ne) from decrementing
// enum count because we'll be doing that here from this
// enumeration.
ne.homeCtx = null;
// Record rest of information from new enum
posn = ne.posn;
limit = ne.limit;
res = ne.res;
entries = ne.entries;
refEx = ne.refEx;
listArg = ne.listArg;
}
protected void finalize() {
cleanup();
}
protected void cleanup() {
if (cleaned) return; // been there; done that
if(enumClnt != null) {
enumClnt.clearSearchReply(res, homeCtx.reqCtls);
}
enumClnt = null;
cleaned = true;
if (homeCtx != null) {
homeCtx.decEnumCount();
homeCtx = null;
}
}
public void close() {
cleanup();
}
} }
/* /*
* Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -214,7 +214,7 @@ public final class LdapPoolManager { ...@@ -214,7 +214,7 @@ public final class LdapPoolManager {
* *
*/ */
static boolean isPoolingAllowed(String socketFactory, OutputStream trace, static boolean isPoolingAllowed(String socketFactory, OutputStream trace,
String authMech, String protocol, Hashtable env) String authMech, String protocol, Hashtable<?,?> env)
throws NamingException { throws NamingException {
if (trace != null && !debug if (trace != null && !debug
...@@ -235,7 +235,7 @@ public final class LdapPoolManager { ...@@ -235,7 +235,7 @@ public final class LdapPoolManager {
if ((socketFactory != null) && if ((socketFactory != null) &&
!socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) { !socketFactory.equals(LdapCtx.DEFAULT_SSL_FACTORY)) {
try { try {
Class socketFactoryClass = Obj.helper.loadClass(socketFactory); Class<?> socketFactoryClass = Obj.helper.loadClass(socketFactory);
Class[] interfaces = socketFactoryClass.getInterfaces(); Class[] interfaces = socketFactoryClass.getInterfaces();
for (int i = 0; i < interfaces.length; i++) { for (int i = 0; i < interfaces.length; i++) {
if (interfaces[i].getCanonicalName().equals(COMPARATOR)) { if (interfaces[i].getCanonicalName().equals(COMPARATOR)) {
...@@ -294,7 +294,7 @@ public final class LdapPoolManager { ...@@ -294,7 +294,7 @@ public final class LdapPoolManager {
static LdapClient getLdapClient(String host, int port, String socketFactory, static LdapClient getLdapClient(String host, int port, String socketFactory,
int connTimeout, int readTimeout, OutputStream trace, int version, int connTimeout, int readTimeout, OutputStream trace, int version,
String authMech, Control[] ctls, String protocol, String user, String authMech, Control[] ctls, String protocol, String user,
Object passwd, Hashtable env) throws NamingException { Object passwd, Hashtable<?,?> env) throws NamingException {
// Create base identity for LdapClient // Create base identity for LdapClient
ClientId id = null; ClientId id = null;
...@@ -385,9 +385,9 @@ public final class LdapPoolManager { ...@@ -385,9 +385,9 @@ public final class LdapPoolManager {
private static final String getProperty(final String propName, private static final String getProperty(final String propName,
final String defVal) { final String defVal) {
return (String) AccessController.doPrivileged( return AccessController.doPrivileged(
new PrivilegedAction() { new PrivilegedAction<String>() {
public Object run() { public String run() {
try { try {
return System.getProperty(propName, defVal); return System.getProperty(propName, defVal);
} catch (SecurityException e) { } catch (SecurityException e) {
...@@ -399,9 +399,9 @@ public final class LdapPoolManager { ...@@ -399,9 +399,9 @@ public final class LdapPoolManager {
private static final int getInteger(final String propName, private static final int getInteger(final String propName,
final int defVal) { final int defVal) {
Integer val = (Integer) AccessController.doPrivileged( Integer val = AccessController.doPrivileged(
new PrivilegedAction() { new PrivilegedAction<Integer>() {
public Object run() { public Integer run() {
try { try {
return Integer.getInteger(propName, defVal); return Integer.getInteger(propName, defVal);
} catch (SecurityException e) { } catch (SecurityException e) {
...@@ -414,9 +414,9 @@ public final class LdapPoolManager { ...@@ -414,9 +414,9 @@ public final class LdapPoolManager {
private static final long getLong(final String propName, private static final long getLong(final String propName,
final long defVal) { final long defVal) {
Long val = (Long) AccessController.doPrivileged( Long val = AccessController.doPrivileged(
new PrivilegedAction() { new PrivilegedAction<Long>() {
public Object run() { public Long run() {
try { try {
return Long.getLong(propName, defVal); return Long.getLong(propName, defVal);
} catch (SecurityException e) { } catch (SecurityException e) {
......
/* /*
* Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -52,7 +52,9 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -52,7 +52,9 @@ final class LdapReferralContext implements DirContext, LdapContext {
private int hopCount = 1; private int hopCount = 1;
private NamingException previousEx = null; private NamingException previousEx = null;
LdapReferralContext(LdapReferralException ex, Hashtable env, @SuppressWarnings("unchecked") // clone()
LdapReferralContext(LdapReferralException ex,
Hashtable<?,?> env,
Control[] connCtls, Control[] connCtls,
Control[] reqCtls, Control[] reqCtls,
String nextName, String nextName,
...@@ -69,20 +71,21 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -69,20 +71,21 @@ final class LdapReferralContext implements DirContext, LdapContext {
// Make copies of environment and connect controls for our own use. // Make copies of environment and connect controls for our own use.
if (env != null) { if (env != null) {
env = (Hashtable) env.clone(); env = (Hashtable<?,?>) env.clone();
// Remove old connect controls from environment, unless we have new // Remove old connect controls from environment, unless we have new
// ones that will override them anyway. // ones that will override them anyway.
if (connCtls == null) { if (connCtls == null) {
env.remove(LdapCtx.BIND_CONTROLS); env.remove(LdapCtx.BIND_CONTROLS);
} }
} else if (connCtls != null) { } else if (connCtls != null) {
env = new Hashtable(5); env = new Hashtable<String, Control[]>(5);
} }
if (connCtls != null) { if (connCtls != null) {
Control[] copiedCtls = new Control[connCtls.length]; Control[] copiedCtls = new Control[connCtls.length];
System.arraycopy(connCtls, 0, copiedCtls, 0, connCtls.length); System.arraycopy(connCtls, 0, copiedCtls, 0, connCtls.length);
// Add copied controls to environment, replacing any old ones. // Add copied controls to environment, replacing any old ones.
env.put(LdapCtx.BIND_CONTROLS, copiedCtls); ((Hashtable<? super String, ? super Control[]>)env)
.put(LdapCtx.BIND_CONTROLS, copiedCtls);
} }
while (true) { while (true) {
...@@ -260,24 +263,26 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -260,24 +263,26 @@ final class LdapReferralContext implements DirContext, LdapContext {
refCtx.rename(overrideName(oldName), toName(refEx.getNewRdn())); refCtx.rename(overrideName(oldName), toName(refEx.getNewRdn()));
} }
public NamingEnumeration list(String name) throws NamingException { public NamingEnumeration<NameClassPair> list(String name) throws NamingException {
return list(toName(name)); return list(toName(name));
} }
public NamingEnumeration list(Name name) throws NamingException { @SuppressWarnings("unchecked")
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
if (skipThisReferral) { if (skipThisReferral) {
throw (NamingException) throw (NamingException)
((refEx.appendUnprocessedReferrals(null)).fillInStackTrace()); ((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());
} }
try { try {
NamingEnumeration ne = null; NamingEnumeration<NameClassPair> ne = null;
if (urlScope != null && urlScope.equals("base")) { if (urlScope != null && urlScope.equals("base")) {
SearchControls cons = new SearchControls(); SearchControls cons = new SearchControls();
cons.setReturningObjFlag(true); cons.setReturningObjFlag(true);
cons.setSearchScope(SearchControls.OBJECT_SCOPE); cons.setSearchScope(SearchControls.OBJECT_SCOPE);
ne = refCtx.search(overrideName(name), "(objectclass=*)", cons); ne = (NamingEnumeration)
refCtx.search(overrideName(name), "(objectclass=*)", cons);
} else { } else {
ne = refCtx.list(overrideName(name)); ne = refCtx.list(overrideName(name));
...@@ -318,25 +323,29 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -318,25 +323,29 @@ final class LdapReferralContext implements DirContext, LdapContext {
} }
} }
public NamingEnumeration listBindings(String name) throws NamingException { public NamingEnumeration<Binding> listBindings(String name) throws
NamingException {
return listBindings(toName(name)); return listBindings(toName(name));
} }
public NamingEnumeration listBindings(Name name) throws NamingException { @SuppressWarnings("unchecked")
public NamingEnumeration<Binding> listBindings(Name name) throws
NamingException {
if (skipThisReferral) { if (skipThisReferral) {
throw (NamingException) throw (NamingException)
((refEx.appendUnprocessedReferrals(null)).fillInStackTrace()); ((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());
} }
try { try {
NamingEnumeration be = null; NamingEnumeration<Binding> be = null;
if (urlScope != null && urlScope.equals("base")) { if (urlScope != null && urlScope.equals("base")) {
SearchControls cons = new SearchControls(); SearchControls cons = new SearchControls();
cons.setReturningObjFlag(true); cons.setReturningObjFlag(true);
cons.setSearchScope(SearchControls.OBJECT_SCOPE); cons.setSearchScope(SearchControls.OBJECT_SCOPE);
be = refCtx.search(overrideName(name), "(objectclass=*)", cons); be = (NamingEnumeration)refCtx.search(overrideName(name),
"(objectclass=*)", cons);
} else { } else {
be = refCtx.listBindings(overrideName(name)); be = refCtx.listBindings(overrideName(name));
...@@ -347,7 +356,7 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -347,7 +356,7 @@ final class LdapReferralContext implements DirContext, LdapContext {
// append (referrals from) the exception that generated this // append (referrals from) the exception that generated this
// context to the new search results, so that referral processing // context to the new search results, so that referral processing
// can continue // can continue
((ReferralEnumeration)be).appendUnprocessedReferrals(refEx); ((ReferralEnumeration<Binding>)be).appendUnprocessedReferrals(refEx);
return (be); return (be);
...@@ -462,7 +471,7 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -462,7 +471,7 @@ final class LdapReferralContext implements DirContext, LdapContext {
return refCtx.removeFromEnvironment(propName); return refCtx.removeFromEnvironment(propName);
} }
public Hashtable getEnvironment() throws NamingException { public Hashtable<?,?> getEnvironment() throws NamingException {
if (skipThisReferral) { if (skipThisReferral) {
throw (NamingException) throw (NamingException)
((refEx.appendUnprocessedReferrals(null)).fillInStackTrace()); ((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());
...@@ -602,23 +611,23 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -602,23 +611,23 @@ final class LdapReferralContext implements DirContext, LdapContext {
return refCtx.getSchemaClassDefinition(overrideName(name)); return refCtx.getSchemaClassDefinition(overrideName(name));
} }
public NamingEnumeration search(String name, public NamingEnumeration<SearchResult> search(String name,
Attributes matchingAttributes) Attributes matchingAttributes)
throws NamingException { throws NamingException {
return search(toName(name), SearchFilter.format(matchingAttributes), return search(toName(name), SearchFilter.format(matchingAttributes),
new SearchControls()); new SearchControls());
} }
public NamingEnumeration search(Name name, public NamingEnumeration<SearchResult> search(Name name,
Attributes matchingAttributes) Attributes matchingAttributes)
throws NamingException { throws NamingException {
return search(name, SearchFilter.format(matchingAttributes), return search(name, SearchFilter.format(matchingAttributes),
new SearchControls()); new SearchControls());
} }
public NamingEnumeration search(String name, public NamingEnumeration<SearchResult> search(String name,
Attributes matchingAttributes, Attributes matchingAttributes,
String[] attributesToReturn) String[] attributesToReturn)
throws NamingException { throws NamingException {
SearchControls cons = new SearchControls(); SearchControls cons = new SearchControls();
cons.setReturningAttributes(attributesToReturn); cons.setReturningAttributes(attributesToReturn);
...@@ -627,9 +636,9 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -627,9 +636,9 @@ final class LdapReferralContext implements DirContext, LdapContext {
cons); cons);
} }
public NamingEnumeration search(Name name, public NamingEnumeration<SearchResult> search(Name name,
Attributes matchingAttributes, Attributes matchingAttributes,
String[] attributesToReturn) String[] attributesToReturn)
throws NamingException { throws NamingException {
SearchControls cons = new SearchControls(); SearchControls cons = new SearchControls();
cons.setReturningAttributes(attributesToReturn); cons.setReturningAttributes(attributesToReturn);
...@@ -637,15 +646,15 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -637,15 +646,15 @@ final class LdapReferralContext implements DirContext, LdapContext {
return search(name, SearchFilter.format(matchingAttributes), cons); return search(name, SearchFilter.format(matchingAttributes), cons);
} }
public NamingEnumeration search(String name, public NamingEnumeration<SearchResult> search(String name,
String filter, String filter,
SearchControls cons) SearchControls cons)
throws NamingException { throws NamingException {
return search(toName(name), filter, cons); return search(toName(name), filter, cons);
} }
public NamingEnumeration search(Name name, public NamingEnumeration<SearchResult> search(Name name,
String filter, String filter,
SearchControls cons) throws NamingException { SearchControls cons) throws NamingException {
if (skipThisReferral) { if (skipThisReferral) {
...@@ -654,8 +663,10 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -654,8 +663,10 @@ final class LdapReferralContext implements DirContext, LdapContext {
} }
try { try {
NamingEnumeration se = refCtx.search(overrideName(name), NamingEnumeration<SearchResult> se =
overrideFilter(filter), overrideAttributesAndScope(cons)); refCtx.search(overrideName(name),
overrideFilter(filter),
overrideAttributesAndScope(cons));
refEx.setNameResolved(true); refEx.setNameResolved(true);
...@@ -694,15 +705,15 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -694,15 +705,15 @@ final class LdapReferralContext implements DirContext, LdapContext {
} }
} }
public NamingEnumeration search(String name, public NamingEnumeration<SearchResult> search(String name,
String filterExpr, String filterExpr,
Object[] filterArgs, Object[] filterArgs,
SearchControls cons) SearchControls cons)
throws NamingException { throws NamingException {
return search(toName(name), filterExpr, filterArgs, cons); return search(toName(name), filterExpr, filterArgs, cons);
} }
public NamingEnumeration search(Name name, public NamingEnumeration<SearchResult> search(Name name,
String filterExpr, String filterExpr,
Object[] filterArgs, Object[] filterArgs,
SearchControls cons) throws NamingException { SearchControls cons) throws NamingException {
...@@ -713,7 +724,7 @@ final class LdapReferralContext implements DirContext, LdapContext { ...@@ -713,7 +724,7 @@ final class LdapReferralContext implements DirContext, LdapContext {
} }
try { try {
NamingEnumeration se; NamingEnumeration<SearchResult> se;
if (urlFilter != null) { if (urlFilter != null) {
se = refCtx.search(overrideName(name), urlFilter, se = refCtx.search(overrideName(name), urlFilter,
......
/* /*
* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
package com.sun.jndi.ldap; package com.sun.jndi.ldap;
import javax.naming.*; import javax.naming.*;
import javax.naming.spi.*;
import javax.naming.ldap.Control; import javax.naming.ldap.Control;
import java.util.Hashtable; import java.util.Hashtable;
...@@ -67,15 +66,16 @@ import java.util.Vector; ...@@ -67,15 +66,16 @@ import java.util.Vector;
*/ */
final public class LdapReferralException extends final public class LdapReferralException extends
javax.naming.ldap.LdapReferralException { javax.naming.ldap.LdapReferralException {
private static final long serialVersionUID = 627059076356906399L;
// ----------- fields initialized in constructor --------------- // ----------- fields initialized in constructor ---------------
private int handleReferrals; private int handleReferrals;
private Hashtable envprops; private Hashtable<?,?> envprops;
private String nextName; private String nextName;
private Control[] reqCtls; private Control[] reqCtls;
// ----------- fields that have defaults ----------------------- // ----------- fields that have defaults -----------------------
private Vector referrals = null; // alternatives,set by setReferralInfo() private Vector<?> referrals = null; // alternatives,set by setReferralInfo()
private int referralIndex = 0; // index into referrals private int referralIndex = 0; // index into referrals
private int referralCount = 0; // count of referrals private int referralCount = 0; // count of referrals
private boolean foundEntry = false; // will stop when entry is found private boolean foundEntry = false; // will stop when entry is found
...@@ -98,7 +98,7 @@ final public class LdapReferralException extends ...@@ -98,7 +98,7 @@ final public class LdapReferralException extends
Object resolvedObj, Object resolvedObj,
Name remainingName, Name remainingName,
String explanation, String explanation,
Hashtable envprops, Hashtable<?,?> envprops,
String nextName, String nextName,
int handleReferrals, int handleReferrals,
Control[] reqCtls) { Control[] reqCtls) {
...@@ -210,7 +210,7 @@ final public class LdapReferralException extends ...@@ -210,7 +210,7 @@ final public class LdapReferralException extends
/** /**
* Sets referral information. * Sets referral information.
*/ */
void setReferralInfo(Vector referrals, boolean continuationRef) { void setReferralInfo(Vector<?> referrals, boolean continuationRef) {
// %%% continuationRef is currently ignored // %%% continuationRef is currently ignored
if (debug) if (debug)
......
/* /*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -28,6 +28,7 @@ package com.sun.jndi.ldap; ...@@ -28,6 +28,7 @@ package com.sun.jndi.ldap;
import java.util.Vector; import java.util.Vector;
import javax.naming.directory.Attributes; import javax.naming.directory.Attributes;
import javax.naming.directory.BasicAttributes; import javax.naming.directory.BasicAttributes;
import javax.naming.ldap.Control;
/** /**
* %%% public for use by LdapSasl %%% * %%% public for use by LdapSasl %%%
...@@ -37,10 +38,11 @@ public final class LdapResult { ...@@ -37,10 +38,11 @@ public final class LdapResult {
public int status; // %%% public for use by LdapSasl public int status; // %%% public for use by LdapSasl
String matchedDN; String matchedDN;
String errorMessage; String errorMessage;
Vector referrals = null; // Vector<String | Vector<String>>
Vector<Vector<String>> referrals = null;
LdapReferralException refEx = null; LdapReferralException refEx = null;
Vector entries = null; Vector<LdapEntry> entries = null;
Vector resControls = null; Vector<Control> resControls = null;
public byte[] serverCreds = null; // %%% public for use by LdapSasl public byte[] serverCreds = null; // %%% public for use by LdapSasl
String extensionId = null; // string OID String extensionId = null; // string OID
byte[] extensionValue = null; // BER OCTET STRING byte[] extensionValue = null; // BER OCTET STRING
...@@ -57,7 +59,7 @@ public final class LdapResult { ...@@ -57,7 +59,7 @@ public final class LdapResult {
switch (status) { switch (status) {
case LdapClient.LDAP_COMPARE_TRUE: case LdapClient.LDAP_COMPARE_TRUE:
status = LdapClient.LDAP_SUCCESS; status = LdapClient.LDAP_SUCCESS;
entries = new Vector(1,1); entries = new Vector<>(1,1);
Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
LdapEntry entry = new LdapEntry( name, attrs ); LdapEntry entry = new LdapEntry( name, attrs );
entries.addElement(entry); entries.addElement(entry);
...@@ -66,7 +68,7 @@ public final class LdapResult { ...@@ -66,7 +68,7 @@ public final class LdapResult {
case LdapClient.LDAP_COMPARE_FALSE: case LdapClient.LDAP_COMPARE_FALSE:
status = LdapClient.LDAP_SUCCESS; status = LdapClient.LDAP_SUCCESS;
entries = new Vector(0); entries = new Vector<>(0);
successful = true; successful = true;
break; break;
......
/* /*
* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -61,8 +61,9 @@ final class LdapSchemaCtx extends HierMemDirCtx { ...@@ -61,8 +61,9 @@ final class LdapSchemaCtx extends HierMemDirCtx {
private int objectType; private int objectType;
static DirContext createSchemaTree(Hashtable env, String subschemasubentry, static DirContext createSchemaTree(Hashtable<String,Object> env,
LdapCtx schemaEntry, Attributes schemaAttrs, boolean netscapeBug) String subschemasubentry, LdapCtx schemaEntry,
Attributes schemaAttrs, boolean netscapeBug)
throws NamingException { throws NamingException {
try { try {
LdapSchemaParser parser = new LdapSchemaParser(netscapeBug); LdapSchemaParser parser = new LdapSchemaParser(netscapeBug);
...@@ -71,7 +72,7 @@ final class LdapSchemaCtx extends HierMemDirCtx { ...@@ -71,7 +72,7 @@ final class LdapSchemaCtx extends HierMemDirCtx {
schemaEntry, parser); schemaEntry, parser);
LdapSchemaCtx root = new LdapSchemaCtx(SCHEMA_ROOT, env, allinfo); LdapSchemaCtx root = new LdapSchemaCtx(SCHEMA_ROOT, env, allinfo);
parser.LDAP2JNDISchema(schemaAttrs, root); LdapSchemaParser.LDAP2JNDISchema(schemaAttrs, root);
return root; return root;
} catch (NamingException e) { } catch (NamingException e) {
schemaEntry.close(); // cleanup schemaEntry.close(); // cleanup
...@@ -80,7 +81,8 @@ final class LdapSchemaCtx extends HierMemDirCtx { ...@@ -80,7 +81,8 @@ final class LdapSchemaCtx extends HierMemDirCtx {
} }
// Called by createNewCtx // Called by createNewCtx
private LdapSchemaCtx(int objectType, Hashtable environment, SchemaInfo info) { private LdapSchemaCtx(int objectType, Hashtable<String,Object> environment,
SchemaInfo info) {
super(environment, LdapClient.caseIgnore); super(environment, LdapClient.caseIgnore);
this.objectType = objectType; this.objectType = objectType;
...@@ -223,9 +225,9 @@ final class LdapSchemaCtx extends HierMemDirCtx { ...@@ -223,9 +225,9 @@ final class LdapSchemaCtx extends HierMemDirCtx {
final private static Attributes deepClone(Attributes orig) final private static Attributes deepClone(Attributes orig)
throws NamingException { throws NamingException {
BasicAttributes copy = new BasicAttributes(true); BasicAttributes copy = new BasicAttributes(true);
NamingEnumeration attrs = orig.getAll(); NamingEnumeration<? extends Attribute> attrs = orig.getAll();
while (attrs.hasMore()) { while (attrs.hasMore()) {
copy.put((Attribute)((Attribute)attrs.next()).clone()); copy.put((Attribute)attrs.next().clone());
} }
return copy; return copy;
} }
...@@ -409,13 +411,14 @@ final class LdapSchemaCtx extends HierMemDirCtx { ...@@ -409,13 +411,14 @@ final class LdapSchemaCtx extends HierMemDirCtx {
} }
} }
private LdapCtx reopenEntry(Hashtable env) throws NamingException { private LdapCtx reopenEntry(Hashtable<?,?> env) throws NamingException {
// Use subschemasubentry name as DN // Use subschemasubentry name as DN
return new LdapCtx(schemaEntryName, host, port, return new LdapCtx(schemaEntryName, host, port,
env, hasLdapsScheme); env, hasLdapsScheme);
} }
synchronized void modifyAttributes(Hashtable env, ModificationItem[] mods) synchronized void modifyAttributes(Hashtable<?,?> env,
ModificationItem[] mods)
throws NamingException { throws NamingException {
if (schemaEntry == null) { if (schemaEntry == null) {
schemaEntry = reopenEntry(env); schemaEntry = reopenEntry(env);
...@@ -423,7 +426,7 @@ final class LdapSchemaCtx extends HierMemDirCtx { ...@@ -423,7 +426,7 @@ final class LdapSchemaCtx extends HierMemDirCtx {
schemaEntry.modifyAttributes("", mods); schemaEntry.modifyAttributes("", mods);
} }
synchronized void modifyAttributes(Hashtable env, int mod, synchronized void modifyAttributes(Hashtable<?,?> env, int mod,
Attributes attrs) throws NamingException { Attributes attrs) throws NamingException {
if (schemaEntry == null) { if (schemaEntry == null) {
schemaEntry = reopenEntry(env); schemaEntry = reopenEntry(env);
......
/* /*
* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,7 +27,6 @@ package com.sun.jndi.ldap; ...@@ -27,7 +27,6 @@ package com.sun.jndi.ldap;
import javax.naming.*; import javax.naming.*;
import javax.naming.directory.*; import javax.naming.directory.*;
import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
/** /**
...@@ -141,9 +140,9 @@ final class LdapSchemaParser { ...@@ -141,9 +140,9 @@ final class LdapSchemaParser {
LdapSchemaCtx schemaRoot) LdapSchemaCtx schemaRoot)
throws NamingException { throws NamingException {
NamingEnumeration objDescs; NamingEnumeration<?> objDescs;
Attributes objDef; Attributes objDef;
LdapSchemaCtx classDefTree; LdapSchemaCtx classDefTree;
// create the class def subtree // create the class def subtree
Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
...@@ -173,9 +172,9 @@ final class LdapSchemaParser { ...@@ -173,9 +172,9 @@ final class LdapSchemaParser {
LdapSchemaCtx schemaRoot) LdapSchemaCtx schemaRoot)
throws NamingException { throws NamingException {
NamingEnumeration attrDescs; NamingEnumeration<?> attrDescs;
Attributes attrDef; Attributes attrDef;
LdapSchemaCtx attrDefTree; LdapSchemaCtx attrDefTree;
// create the AttributeDef subtree // create the AttributeDef subtree
Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
...@@ -206,9 +205,9 @@ final class LdapSchemaParser { ...@@ -206,9 +205,9 @@ final class LdapSchemaParser {
LdapSchemaCtx schemaRoot) LdapSchemaCtx schemaRoot)
throws NamingException { throws NamingException {
NamingEnumeration syntaxDescs; NamingEnumeration<?> syntaxDescs;
Attributes syntaxDef; Attributes syntaxDef;
LdapSchemaCtx syntaxDefTree; LdapSchemaCtx syntaxDefTree;
// create the SyntaxDef subtree // create the SyntaxDef subtree
Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
...@@ -239,9 +238,9 @@ final class LdapSchemaParser { ...@@ -239,9 +238,9 @@ final class LdapSchemaParser {
LdapSchemaCtx schemaRoot) LdapSchemaCtx schemaRoot)
throws NamingException { throws NamingException {
NamingEnumeration matchRuleDescs; NamingEnumeration<?> matchRuleDescs;
Attributes matchRuleDef; Attributes matchRuleDef;
LdapSchemaCtx matchRuleDefTree; LdapSchemaCtx matchRuleDefTree;
// create the MatchRuleDef subtree // create the MatchRuleDef subtree
Attributes attrs = new BasicAttributes(LdapClient.caseIgnore); Attributes attrs = new BasicAttributes(LdapClient.caseIgnore);
...@@ -519,8 +518,8 @@ final class LdapSchemaParser { ...@@ -519,8 +518,8 @@ final class LdapSchemaParser {
final private static String[] readQDescrList(String string, int[] pos) final private static String[] readQDescrList(String string, int[] pos)
throws NamingException { throws NamingException {
int begin, end; int begin, end;
Vector values = new Vector(5); Vector<String> values = new Vector<>(5);
if (debug) { if (debug) {
System.err.println("ReadQDescrList: pos="+pos[0]); System.err.println("ReadQDescrList: pos="+pos[0]);
...@@ -553,7 +552,7 @@ final class LdapSchemaParser { ...@@ -553,7 +552,7 @@ final class LdapSchemaParser {
String[] answer = new String[values.size()]; String[] answer = new String[values.size()];
for (int i = 0; i < answer.length; i++) { for (int i = 0; i < answer.length; i++) {
answer[i] = (String)values.elementAt(i); answer[i] = values.elementAt(i);
} }
return answer; return answer;
} }
...@@ -614,7 +613,7 @@ final class LdapSchemaParser { ...@@ -614,7 +613,7 @@ final class LdapSchemaParser {
int begin, cur, end; int begin, cur, end;
String oidName = null; String oidName = null;
Vector values = new Vector(5); Vector<String> values = new Vector<>(5);
if (debug) { if (debug) {
System.err.println("ReadOIDList: pos="+pos[0]); System.err.println("ReadOIDList: pos="+pos[0]);
...@@ -663,7 +662,7 @@ final class LdapSchemaParser { ...@@ -663,7 +662,7 @@ final class LdapSchemaParser {
String[] answer = new String[values.size()]; String[] answer = new String[values.size()];
for (int i = 0; i < answer.length; i++) { for (int i = 0; i < answer.length; i++) {
answer[i] = (String)values.elementAt(i); answer[i] = values.elementAt(i);
} }
return answer; return answer;
} }
...@@ -843,10 +842,10 @@ final class LdapSchemaParser { ...@@ -843,10 +842,10 @@ final class LdapSchemaParser {
String attrId = null; String attrId = null;
// use enumeration because attribute ID is not known // use enumeration because attribute ID is not known
for (NamingEnumeration ae = attrs.getAll(); for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
ae.hasMoreElements(); ) { ae.hasMoreElements(); ) {
attr = (Attribute)ae.next(); attr = ae.next();
attrId = attr.getID(); attrId = attr.getID();
// skip those already processed // skip those already processed
...@@ -973,10 +972,10 @@ final class LdapSchemaParser { ...@@ -973,10 +972,10 @@ final class LdapSchemaParser {
String attrId = null; String attrId = null;
// use enumeration because attribute ID is not known // use enumeration because attribute ID is not known
for (NamingEnumeration ae = attrs.getAll(); for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
ae.hasMoreElements(); ) { ae.hasMoreElements(); ) {
attr = (Attribute)ae.next(); attr = ae.next();
attrId = attr.getID(); attrId = attr.getID();
// skip those already processed // skip those already processed
...@@ -1040,10 +1039,10 @@ final class LdapSchemaParser { ...@@ -1040,10 +1039,10 @@ final class LdapSchemaParser {
String attrId = null; String attrId = null;
// use enumeration because attribute ID is not known // use enumeration because attribute ID is not known
for (NamingEnumeration ae = attrs.getAll(); for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
ae.hasMoreElements(); ) { ae.hasMoreElements(); ) {
attr = (Attribute)ae.next(); attr = ae.next();
attrId = attr.getID(); attrId = attr.getID();
// skip those already processed // skip those already processed
...@@ -1117,10 +1116,10 @@ final class LdapSchemaParser { ...@@ -1117,10 +1116,10 @@ final class LdapSchemaParser {
String attrId = null; String attrId = null;
// use enumeration because attribute ID is not known // use enumeration because attribute ID is not known
for (NamingEnumeration ae = attrs.getAll(); for (NamingEnumeration<? extends Attribute> ae = attrs.getAll();
ae.hasMoreElements(); ) { ae.hasMoreElements(); ) {
attr = (Attribute)ae.next(); attr = ae.next();
attrId = attr.getID(); attrId = attr.getID();
// skip those already processed // skip those already processed
...@@ -1201,7 +1200,7 @@ final class LdapSchemaParser { ...@@ -1201,7 +1200,7 @@ final class LdapSchemaParser {
qdList.append(WHSP); qdList.append(WHSP);
qdList.append(OID_LIST_BEGIN); qdList.append(OID_LIST_BEGIN);
NamingEnumeration values = attr.getAll(); NamingEnumeration<?> values = attr.getAll();
while(values.hasMore()) { while(values.hasMore()) {
qdList.append(WHSP); qdList.append(WHSP);
...@@ -1238,7 +1237,7 @@ final class LdapSchemaParser { ...@@ -1238,7 +1237,7 @@ final class LdapSchemaParser {
oidList.append(WHSP); oidList.append(WHSP);
oidList.append(OID_LIST_BEGIN); oidList.append(OID_LIST_BEGIN);
NamingEnumeration values = oidsAttr.getAll(); NamingEnumeration<?> values = oidsAttr.getAll();
oidList.append(WHSP); oidList.append(WHSP);
oidList.append(values.next()); oidList.append(values.next());
......
/* /*
* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -34,7 +34,8 @@ import javax.naming.ldap.LdapName; ...@@ -34,7 +34,8 @@ import javax.naming.ldap.LdapName;
import com.sun.jndi.toolkit.ctx.Continuation; import com.sun.jndi.toolkit.ctx.Continuation;
final class LdapSearchEnumeration extends LdapNamingEnumeration { final class LdapSearchEnumeration
extends AbstractLdapNamingEnumeration<SearchResult> {
private Name startName; // prefix of names of search results private Name startName; // prefix of names of search results
private LdapCtx.SearchArgs searchArgs = null; private LdapCtx.SearchArgs searchArgs = null;
...@@ -52,9 +53,10 @@ final class LdapSearchEnumeration extends LdapNamingEnumeration { ...@@ -52,9 +53,10 @@ final class LdapSearchEnumeration extends LdapNamingEnumeration {
searchArgs = args; searchArgs = args;
} }
protected NameClassPair @Override
createItem(String dn, Attributes attrs, Vector respCtls) protected SearchResult createItem(String dn, Attributes attrs,
throws NamingException { Vector<Control> respCtls)
throws NamingException {
Object obj = null; Object obj = null;
...@@ -174,6 +176,7 @@ final class LdapSearchEnumeration extends LdapNamingEnumeration { ...@@ -174,6 +176,7 @@ final class LdapSearchEnumeration extends LdapNamingEnumeration {
return sr; return sr;
} }
@Override
public void appendUnprocessedReferrals(LdapReferralException ex) { public void appendUnprocessedReferrals(LdapReferralException ex) {
// a referral has been followed so do not create relative names // a referral has been followed so do not create relative names
...@@ -181,14 +184,16 @@ final class LdapSearchEnumeration extends LdapNamingEnumeration { ...@@ -181,14 +184,16 @@ final class LdapSearchEnumeration extends LdapNamingEnumeration {
super.appendUnprocessedReferrals(ex); super.appendUnprocessedReferrals(ex);
} }
protected LdapNamingEnumeration @Override
getReferredResults(LdapReferralContext refCtx) throws NamingException { protected LdapSearchEnumeration getReferredResults(
LdapReferralContext refCtx) throws NamingException {
// repeat the original operation at the new context // repeat the original operation at the new context
return (LdapSearchEnumeration) return (LdapSearchEnumeration)refCtx.search(
refCtx.search(searchArgs.name, searchArgs.filter, searchArgs.cons); searchArgs.name, searchArgs.filter, searchArgs.cons);
} }
protected void update(LdapNamingEnumeration ne) { @Override
protected void update(AbstractLdapNamingEnumeration<SearchResult> ne) {
super.update(ne); super.update(ne);
// Update search-specific variables // Update search-specific variables
......
/* /*
* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -50,12 +50,12 @@ import com.sun.jndi.toolkit.ctx.Continuation; ...@@ -50,12 +50,12 @@ import com.sun.jndi.toolkit.ctx.Continuation;
final class NamingEventNotifier implements Runnable { final class NamingEventNotifier implements Runnable {
private final static boolean debug = false; private final static boolean debug = false;
private Vector namingListeners; private Vector<NamingListener> namingListeners;
private Thread worker; private Thread worker;
private LdapCtx context; private LdapCtx context;
private EventContext eventSrc; private EventContext eventSrc;
private EventSupport support; private EventSupport support;
private NamingEnumeration results; private NamingEnumeration<SearchResult> results;
// package private; used by EventSupport to remove it // package private; used by EventSupport to remove it
NotifierArgs info; NotifierArgs info;
...@@ -83,7 +83,7 @@ final class NamingEventNotifier implements Runnable { ...@@ -83,7 +83,7 @@ final class NamingEventNotifier implements Runnable {
context = (LdapCtx)ctx.newInstance(new Control[]{psearch}); context = (LdapCtx)ctx.newInstance(new Control[]{psearch});
eventSrc = ctx; eventSrc = ctx;
namingListeners = new Vector(); namingListeners = new Vector<>();
namingListeners.addElement(firstListener); namingListeners.addElement(firstListener);
worker = Obj.helper.createThread(this); worker = Obj.helper.createThread(this);
...@@ -124,7 +124,8 @@ final class NamingEventNotifier implements Runnable { ...@@ -124,7 +124,8 @@ final class NamingEventNotifier implements Runnable {
// Change root of search results so that it will generate // Change root of search results so that it will generate
// names relative to the event context instead of that // names relative to the event context instead of that
// named by nm // named by nm
((LdapSearchEnumeration)results).setStartName(context.currentParsedDN); ((LdapSearchEnumeration)(NamingEnumeration)results)
.setStartName(context.currentParsedDN);
SearchResult si; SearchResult si;
Control[] respctls; Control[] respctls;
...@@ -132,7 +133,7 @@ final class NamingEventNotifier implements Runnable { ...@@ -132,7 +133,7 @@ final class NamingEventNotifier implements Runnable {
long changeNum; long changeNum;
while (results.hasMore()) { while (results.hasMore()) {
si = (SearchResult)results.next(); si = results.next();
respctls = (si instanceof HasControls) ? respctls = (si instanceof HasControls) ?
((HasControls) si).getControls() : null; ((HasControls) si).getControls() : null;
......
/* /*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -133,7 +133,7 @@ final class NotifierArgs { ...@@ -133,7 +133,7 @@ final class NotifierArgs {
private int controlsCode() { private int controlsCode() {
if (controls == null) return 0; if (controls == null) return 0;
int total = (int)controls.getTimeLimit() + (int)controls.getCountLimit() + int total = controls.getTimeLimit() + (int)controls.getCountLimit() +
(controls.getDerefLinkFlag() ? 1 : 0) + (controls.getDerefLinkFlag() ? 1 : 0) +
(controls.getReturningObjFlag() ? 1 : 0); (controls.getReturningObjFlag() ? 1 : 0);
......
/* /*
* Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -84,6 +84,7 @@ final class Obj { ...@@ -84,6 +84,7 @@ final class Obj {
/** /**
* @deprecated * @deprecated
*/ */
@Deprecated
private static final int REMOTE_LOC = 7; private static final int REMOTE_LOC = 7;
// LDAP object classes to support Java objects // LDAP object classes to support Java objects
...@@ -206,13 +207,13 @@ final class Obj { ...@@ -206,13 +207,13 @@ final class Obj {
} else { } else {
StringTokenizer parser = StringTokenizer parser =
new StringTokenizer((String)codebaseAttr.get()); new StringTokenizer((String)codebaseAttr.get());
Vector vec = new Vector(10); Vector<String> vec = new Vector<>(10);
while (parser.hasMoreTokens()) { while (parser.hasMoreTokens()) {
vec.addElement(parser.nextToken()); vec.addElement(parser.nextToken());
} }
String[] answer = new String[vec.size()]; String[] answer = new String[vec.size()];
for (int i = 0; i < answer.length; i++) { for (int i = 0; i < answer.length; i++) {
answer[i] = (String)vec.elementAt(i); answer[i] = vec.elementAt(i);
} }
return answer; return answer;
} }
...@@ -410,10 +411,10 @@ final class Obj { ...@@ -410,10 +411,10 @@ final class Obj {
* Temporary Vector for decoded RefAddr addresses - used to ensure * Temporary Vector for decoded RefAddr addresses - used to ensure
* unordered addresses are correctly re-ordered. * unordered addresses are correctly re-ordered.
*/ */
Vector refAddrList = new Vector(); Vector<RefAddr> refAddrList = new Vector<>();
refAddrList.setSize(attr.size()); refAddrList.setSize(attr.size());
for (NamingEnumeration vals = attr.getAll(); vals.hasMore(); ) { for (NamingEnumeration<?> vals = attr.getAll(); vals.hasMore(); ) {
val = (String)vals.next(); val = (String)vals.next();
...@@ -488,7 +489,7 @@ final class Obj { ...@@ -488,7 +489,7 @@ final class Obj {
// Copy to real reference // Copy to real reference
for (int i = 0; i < refAddrList.size(); i++) { for (int i = 0; i < refAddrList.size(); i++) {
ref.add((RefAddr)refAddrList.elementAt(i)); ref.add(refAddrList.elementAt(i));
} }
} }
...@@ -502,9 +503,9 @@ final class Obj { ...@@ -502,9 +503,9 @@ final class Obj {
try { try {
ByteArrayOutputStream bytes = new ByteArrayOutputStream(); ByteArrayOutputStream bytes = new ByteArrayOutputStream();
ObjectOutputStream serial = new ObjectOutputStream(bytes); try (ObjectOutputStream serial = new ObjectOutputStream(bytes)) {
serial.writeObject(obj); serial.writeObject(obj);
serial.close(); }
return (bytes.toByteArray()); return (bytes.toByteArray());
...@@ -524,18 +525,14 @@ final class Obj { ...@@ -524,18 +525,14 @@ final class Obj {
try { try {
// Create ObjectInputStream for deserialization // Create ObjectInputStream for deserialization
ByteArrayInputStream bytes = new ByteArrayInputStream(obj); ByteArrayInputStream bytes = new ByteArrayInputStream(obj);
ObjectInputStream deserial = (cl == null ? try (ObjectInputStream deserial = cl == null ?
new ObjectInputStream(bytes) : new ObjectInputStream(bytes) :
new LoaderInputStream(bytes, cl)); new LoaderInputStream(bytes, cl)) {
try {
return deserial.readObject(); return deserial.readObject();
} catch (ClassNotFoundException e) { } catch (ClassNotFoundException e) {
NamingException ne = new NamingException(); NamingException ne = new NamingException();
ne.setRootCause(e); ne.setRootCause(e);
throw ne; throw ne;
} finally {
deserial.close();
} }
} catch (IOException e) { } catch (IOException e) {
NamingException ne = new NamingException(); NamingException ne = new NamingException();
...@@ -549,7 +546,7 @@ final class Obj { ...@@ -549,7 +546,7 @@ final class Obj {
*/ */
static Attributes determineBindAttrs( static Attributes determineBindAttrs(
char separator, Object obj, Attributes attrs, boolean cloned, char separator, Object obj, Attributes attrs, boolean cloned,
Name name, Context ctx, Hashtable env) Name name, Context ctx, Hashtable<?,?> env)
throws NamingException { throws NamingException {
// Call state factories to convert object and attrs // Call state factories to convert object and attrs
...@@ -582,10 +579,10 @@ final class Obj { ...@@ -582,10 +579,10 @@ final class Obj {
} else { } else {
// Get existing objectclass attribute // Get existing objectclass attribute
objectClass = (Attribute)attrs.get("objectClass"); objectClass = attrs.get("objectClass");
if (objectClass == null && !attrs.isCaseIgnored()) { if (objectClass == null && !attrs.isCaseIgnored()) {
// %%% workaround // %%% workaround
objectClass = (Attribute)attrs.get("objectclass"); objectClass = attrs.get("objectclass");
} }
// No objectclasses supplied, use "top" to start // No objectclasses supplied, use "top" to start
...@@ -614,8 +611,8 @@ final class Obj { ...@@ -614,8 +611,8 @@ final class Obj {
classLoader = cl; classLoader = cl;
} }
protected Class resolveClass(ObjectStreamClass desc) throws IOException, protected Class<?> resolveClass(ObjectStreamClass desc) throws
ClassNotFoundException { IOException, ClassNotFoundException {
try { try {
// %%% Should use Class.forName(desc.getName(), false, classLoader); // %%% Should use Class.forName(desc.getName(), false, classLoader);
// except we can't because that is only available on JDK1.2 // except we can't because that is only available on JDK1.2
...@@ -625,15 +622,15 @@ final class Obj { ...@@ -625,15 +622,15 @@ final class Obj {
} }
} }
protected Class resolveProxyClass(String[] interfaces) throws protected Class<?> resolveProxyClass(String[] interfaces) throws
IOException, ClassNotFoundException { IOException, ClassNotFoundException {
ClassLoader nonPublicLoader = null; ClassLoader nonPublicLoader = null;
boolean hasNonPublicInterface = false; boolean hasNonPublicInterface = false;
// define proxy in class loader of non-public interface(s), if any // define proxy in class loader of non-public interface(s), if any
Class[] classObjs = new Class[interfaces.length]; Class<?>[] classObjs = new Class<>[interfaces.length];
for (int i = 0; i < interfaces.length; i++) { for (int i = 0; i < interfaces.length; i++) {
Class cl = Class.forName(interfaces[i], false, classLoader); Class<?> cl = Class.forName(interfaces[i], false, classLoader);
if ((cl.getModifiers() & Modifier.PUBLIC) == 0) { if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
if (hasNonPublicInterface) { if (hasNonPublicInterface) {
if (nonPublicLoader != cl.getClassLoader()) { if (nonPublicLoader != cl.getClassLoader()) {
......
/* /*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,6 +27,6 @@ package com.sun.jndi.ldap; ...@@ -27,6 +27,6 @@ package com.sun.jndi.ldap;
import javax.naming.NamingEnumeration; import javax.naming.NamingEnumeration;
interface ReferralEnumeration extends NamingEnumeration { interface ReferralEnumeration<T> extends NamingEnumeration<T> {
void appendUnprocessedReferrals(LdapReferralException ex); void appendUnprocessedReferrals(LdapReferralException ex);
} }
/* /*
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -26,9 +26,7 @@ ...@@ -26,9 +26,7 @@
package com.sun.jndi.ldap; package com.sun.jndi.ldap;
import java.util.Arrays; import java.util.Arrays;
import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.NoSuchElementException;
import java.util.Random; import java.util.Random;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.List; import java.util.List;
...@@ -39,8 +37,6 @@ import javax.naming.spi.NamingManager; ...@@ -39,8 +37,6 @@ import javax.naming.spi.NamingManager;
import javax.naming.ldap.LdapName; import javax.naming.ldap.LdapName;
import javax.naming.ldap.Rdn; import javax.naming.ldap.Rdn;
import com.sun.jndi.ldap.LdapURL;
/** /**
* This class discovers the location of LDAP services by querying DNS. * This class discovers the location of LDAP services by querying DNS.
* See http://www.ietf.org/internet-drafts/draft-ietf-ldapext-locate-07.txt * See http://www.ietf.org/internet-drafts/draft-ietf-ldapext-locate-07.txt
...@@ -78,10 +74,10 @@ class ServiceLocator { ...@@ -78,10 +74,10 @@ class ServiceLocator {
// process RDNs left-to-right // process RDNs left-to-right
//List<Rdn> rdnList = ldapName.getRdns(); //List<Rdn> rdnList = ldapName.getRdns();
List rdnList = ldapName.getRdns(); List<Rdn> rdnList = ldapName.getRdns();
for (int i = rdnList.size() - 1; i >= 0; i--) { for (int i = rdnList.size() - 1; i >= 0; i--) {
//Rdn rdn = rdnList.get(i); //Rdn rdn = rdnList.get(i);
Rdn rdn = (Rdn) rdnList.get(i); Rdn rdn = rdnList.get(i);
// single-valued RDN with a DC attribute // single-valued RDN with a DC attribute
if ((rdn.size() == 1) && if ((rdn.size() == 1) &&
...@@ -117,7 +113,7 @@ class ServiceLocator { ...@@ -117,7 +113,7 @@ class ServiceLocator {
* @return An ordered list of hostports for the LDAP service or null if * @return An ordered list of hostports for the LDAP service or null if
* the service has not been located. * the service has not been located.
*/ */
static String[] getLdapService(String domainName, Hashtable environment) { static String[] getLdapService(String domainName, Hashtable<?,?> environment) {
if (domainName == null || domainName.length() == 0) { if (domainName == null || domainName.length() == 0) {
return null; return null;
...@@ -252,7 +248,7 @@ class ServiceLocator { ...@@ -252,7 +248,7 @@ class ServiceLocator {
* See http://www.ietf.org/rfc/rfc2782.txt * See http://www.ietf.org/rfc/rfc2782.txt
*/ */
static class SrvRecord implements Comparable { static class SrvRecord implements Comparable<SrvRecord> {
int priority; int priority;
int weight; int weight;
...@@ -284,8 +280,7 @@ static class SrvRecord implements Comparable { ...@@ -284,8 +280,7 @@ static class SrvRecord implements Comparable {
* Sort records in ascending order of priority value. For records with * Sort records in ascending order of priority value. For records with
* equal priority move those with weight 0 to the top of the list. * equal priority move those with weight 0 to the top of the list.
*/ */
public int compareTo(Object o) { public int compareTo(SrvRecord that) {
SrvRecord that = (SrvRecord) o;
if (priority > that.priority) { if (priority > that.priority) {
return 1; // this > that return 1; // this > that
} else if (priority < that.priority) { } else if (priority < that.priority) {
......
/* /*
* Copyright (c) 2002, 2005, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -54,9 +54,9 @@ class SimpleClientId extends ClientId { ...@@ -54,9 +54,9 @@ class SimpleClientId extends ClientId {
} else if (passwd instanceof String) { } else if (passwd instanceof String) {
this.passwd = passwd; this.passwd = passwd;
} else if (passwd instanceof byte[]) { } else if (passwd instanceof byte[]) {
this.passwd = (byte[]) ((byte[])passwd).clone(); this.passwd = ((byte[])passwd).clone();
} else if (passwd instanceof char[]) { } else if (passwd instanceof char[]) {
this.passwd = (char[]) ((char[])passwd).clone(); this.passwd = ((char[])passwd).clone();
} else { } else {
this.passwd = passwd; this.passwd = passwd;
} }
......
/* /*
* Copyright (c) 1999, 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -41,7 +41,7 @@ final class UnsolicitedResponseImpl implements UnsolicitedNotification { ...@@ -41,7 +41,7 @@ final class UnsolicitedResponseImpl implements UnsolicitedNotification {
private NamingException exception; private NamingException exception;
private Control[] controls; private Control[] controls;
UnsolicitedResponseImpl(String oid, byte[] berVal, Vector ref, UnsolicitedResponseImpl(String oid, byte[] berVal, Vector<Vector<String>> ref,
int status, String msg, String matchedDN, Control[] controls) { int status, String msg, String matchedDN, Control[] controls) {
this.oid = oid; this.oid = oid;
this.extensionValue = berVal; this.extensionValue = berVal;
...@@ -50,7 +50,8 @@ final class UnsolicitedResponseImpl implements UnsolicitedNotification { ...@@ -50,7 +50,8 @@ final class UnsolicitedResponseImpl implements UnsolicitedNotification {
int len = ref.size(); int len = ref.size();
referrals = new String[len]; referrals = new String[len];
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
referrals[i] = (String)ref.elementAt(i); // ref is a list of single-String Vectors
referrals[i] = ref.elementAt(i).elementAt(0);
} }
} }
exception = LdapCtx.mapErrorCode(status, msg); exception = LdapCtx.mapErrorCode(status, msg);
......
/* /*
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -72,7 +72,7 @@ abstract class VersionHelper { ...@@ -72,7 +72,7 @@ abstract class VersionHelper {
return urlArray; return urlArray;
} }
abstract Class loadClass(String className) throws ClassNotFoundException; abstract Class<?> loadClass(String className) throws ClassNotFoundException;
abstract Thread createThread(Runnable r); abstract Thread createThread(Runnable r);
} }
/* /*
* Copyright (c) 1999, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -66,15 +66,15 @@ final class VersionHelper12 extends VersionHelper { ...@@ -66,15 +66,15 @@ final class VersionHelper12 extends VersionHelper {
} }
} }
Class loadClass(String className) throws ClassNotFoundException { Class<?> loadClass(String className) throws ClassNotFoundException {
ClassLoader cl = getContextClassLoader(); ClassLoader cl = getContextClassLoader();
return Class.forName(className, true, cl); return Class.forName(className, true, cl);
} }
private ClassLoader getContextClassLoader() { private ClassLoader getContextClassLoader() {
return (ClassLoader) AccessController.doPrivileged( return AccessController.doPrivileged(
new PrivilegedAction() { new PrivilegedAction<ClassLoader>() {
public Object run() { public ClassLoader run() {
return Thread.currentThread().getContextClassLoader(); return Thread.currentThread().getContextClassLoader();
} }
} }
...@@ -82,9 +82,9 @@ final class VersionHelper12 extends VersionHelper { ...@@ -82,9 +82,9 @@ final class VersionHelper12 extends VersionHelper {
} }
Thread createThread(final Runnable r) { Thread createThread(final Runnable r) {
return (Thread) AccessController.doPrivileged( return AccessController.doPrivileged(
new PrivilegedAction() { new PrivilegedAction<Thread>() {
public Object run() { public Thread run() {
return new Thread(r); return new Thread(r);
} }
} }
......
/* /*
* Copyright (c) 2000, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -27,16 +27,8 @@ package com.sun.jndi.ldap.ext; ...@@ -27,16 +27,8 @@ package com.sun.jndi.ldap.ext;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException; import java.io.IOException;
import java.net.Socket;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.security.Principal; import java.security.Principal;
import java.security.cert.X509Certificate; import java.security.cert.X509Certificate;
import java.security.cert.CertificateException; import java.security.cert.CertificateException;
...@@ -45,11 +37,9 @@ import javax.net.ssl.SSLSession; ...@@ -45,11 +37,9 @@ import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.SSLPeerUnverifiedException; import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HostnameVerifier;
import sun.security.util.HostnameChecker; import sun.security.util.HostnameChecker;
import javax.naming.*;
import javax.naming.ldap.*; import javax.naming.ldap.*;
import com.sun.jndi.ldap.Connection; import com.sun.jndi.ldap.Connection;
...@@ -415,7 +405,7 @@ final public class StartTlsResponseImpl extends StartTlsResponse { ...@@ -415,7 +405,7 @@ final public class StartTlsResponseImpl extends StartTlsResponse {
// Use ciphersuite to determine whether Kerberos is active. // Use ciphersuite to determine whether Kerberos is active.
if (session.getCipherSuite().startsWith("TLS_KRB5")) { if (session.getCipherSuite().startsWith("TLS_KRB5")) {
Principal principal = getPeerPrincipal(session); Principal principal = getPeerPrincipal(session);
if (!checker.match(hostname, principal)) { if (!HostnameChecker.match(hostname, principal)) {
throw new SSLPeerUnverifiedException( throw new SSLPeerUnverifiedException(
"hostname of the kerberos principal:" + principal + "hostname of the kerberos principal:" + principal +
" does not match the hostname:" + hostname); " does not match the hostname:" + hostname);
......
/* /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -71,10 +71,10 @@ final class Connections implements PoolCallback { ...@@ -71,10 +71,10 @@ final class Connections implements PoolCallback {
final private int maxSize; final private int maxSize;
final private int prefSize; final private int prefSize;
final private List conns; final private List<ConnectionDesc> conns;
private boolean closed = false; // Closed for business private boolean closed = false; // Closed for business
private Reference ref; // maintains reference to id to prevent premature GC private Reference<Object> ref; // maintains reference to id to prevent premature GC
/** /**
* @param id the identity (connection request) of the connections in the list * @param id the identity (connection request) of the connections in the list
...@@ -99,11 +99,11 @@ final class Connections implements PoolCallback { ...@@ -99,11 +99,11 @@ final class Connections implements PoolCallback {
} else { } else {
this.prefSize = prefSize; this.prefSize = prefSize;
} }
conns = new ArrayList(maxSize > 0 ? maxSize : DEFAULT_SIZE); conns = new ArrayList<>(maxSize > 0 ? maxSize : DEFAULT_SIZE);
// Maintain soft ref to id so that this Connections' entry in // Maintain soft ref to id so that this Connections' entry in
// Pool doesn't get GC'ed prematurely // Pool doesn't get GC'ed prematurely
ref = new SoftReference(id); ref = new SoftReference<>(id);
d("init size=", initSize); d("init size=", initSize);
d("max size=", maxSize); d("max size=", maxSize);
...@@ -186,7 +186,7 @@ final class Connections implements PoolCallback { ...@@ -186,7 +186,7 @@ final class Connections implements PoolCallback {
// exceeds prefSize, then first look for an idle connection // exceeds prefSize, then first look for an idle connection
ConnectionDesc entry; ConnectionDesc entry;
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
entry = (ConnectionDesc) conns.get(i); entry = conns.get(i);
if ((conn = entry.tryUse()) != null) { if ((conn = entry.tryUse()) != null) {
d("get(): use ", conn); d("get(): use ", conn);
td("Use ", conn); td("Use ", conn);
...@@ -239,7 +239,7 @@ final class Connections implements PoolCallback { ...@@ -239,7 +239,7 @@ final class Connections implements PoolCallback {
td("Release ", conn); td("Release ", conn);
// Get ConnectionDesc from list to get correct state info // Get ConnectionDesc from list to get correct state info
entry = (ConnectionDesc) conns.get(loc); entry = conns.get(loc);
// Return connection to list, ready for reuse // Return connection to list, ready for reuse
entry.release(); entry.release();
} }
...@@ -291,10 +291,10 @@ final class Connections implements PoolCallback { ...@@ -291,10 +291,10 @@ final class Connections implements PoolCallback {
* @return true if no more connections in list * @return true if no more connections in list
*/ */
synchronized boolean expire(long threshold) { synchronized boolean expire(long threshold) {
Iterator iter = conns.iterator(); Iterator<ConnectionDesc> iter = conns.iterator();
ConnectionDesc entry; ConnectionDesc entry;
while (iter.hasNext()) { while (iter.hasNext()) {
entry = (ConnectionDesc) iter.next(); entry = iter.next();
if (entry.expire(threshold)) { if (entry.expire(threshold)) {
d("expire(): removing ", entry); d("expire(): removing ", entry);
td("Expired ", entry); td("Expired ", entry);
...@@ -333,7 +333,7 @@ final class Connections implements PoolCallback { ...@@ -333,7 +333,7 @@ final class Connections implements PoolCallback {
ConnectionDesc entry; ConnectionDesc entry;
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
entry = (ConnectionDesc) conns.get(i); entry = conns.get(i);
use += entry.getUseCount(); use += entry.getUseCount();
switch (entry.getState()) { switch (entry.getState()) {
case ConnectionDesc.BUSY: case ConnectionDesc.BUSY:
......
/* /*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -55,11 +55,12 @@ import java.lang.ref.ReferenceQueue; ...@@ -55,11 +55,12 @@ import java.lang.ref.ReferenceQueue;
* reference to Connections used for closing (which in turn terminates * reference to Connections used for closing (which in turn terminates
* the Connection thread) it by monitoring the ReferenceQueue. * the Connection thread) it by monitoring the ReferenceQueue.
*/ */
class ConnectionsWeakRef extends WeakReference { class ConnectionsWeakRef extends WeakReference<ConnectionsRef> {
private final Connections conns; private final Connections conns;
ConnectionsWeakRef (ConnectionsRef connsRef, ReferenceQueue queue) { ConnectionsWeakRef (ConnectionsRef connsRef,
ReferenceQueue<? super ConnectionsRef> queue) {
super(connsRef, queue); super(connsRef, queue);
this.conns = connsRef.getConnections(); this.conns = connsRef.getConnections();
} }
......
/* /*
* Copyright (c) 2002, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -30,7 +30,6 @@ import java.util.WeakHashMap; ...@@ -30,7 +30,6 @@ import java.util.WeakHashMap;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set;
import java.util.LinkedList; import java.util.LinkedList;
import java.io.PrintStream; import java.io.PrintStream;
...@@ -83,17 +82,18 @@ final public class Pool { ...@@ -83,17 +82,18 @@ final public class Pool {
/* /*
* Used for connections cleanup * Used for connections cleanup
*/ */
private static final ReferenceQueue queue = new ReferenceQueue(); private static final ReferenceQueue<ConnectionsRef> queue =
private static final Collection weakRefs = new ReferenceQueue<>();
Collections.synchronizedList(new LinkedList()); private static final Collection<Reference<ConnectionsRef>> weakRefs =
Collections.synchronizedList(new LinkedList<Reference<ConnectionsRef>>());
final private int maxSize; // max num of identical conn per pool final private int maxSize; // max num of identical conn per pool
final private int prefSize; // preferred num of identical conn per pool final private int prefSize; // preferred num of identical conn per pool
final private int initSize; // initial number of identical conn to create final private int initSize; // initial number of identical conn to create
final private Map map; final private Map<Object, ConnectionsRef> map;
public Pool(int initSize, int prefSize, int maxSize) { public Pool(int initSize, int prefSize, int maxSize) {
map = new WeakHashMap(); map = new WeakHashMap<>();
this.prefSize = prefSize; this.prefSize = prefSize;
this.maxSize = maxSize; this.maxSize = maxSize;
this.initSize = initSize; this.initSize = initSize;
...@@ -135,7 +135,8 @@ final public class Pool { ...@@ -135,7 +135,8 @@ final public class Pool {
map.put(id, connsRef); map.put(id, connsRef);
// Create a weak reference to ConnectionsRef // Create a weak reference to ConnectionsRef
Reference weakRef = new ConnectionsWeakRef(connsRef, queue); Reference<ConnectionsRef> weakRef =
new ConnectionsWeakRef(connsRef, queue);
// Keep the weak reference through the element of a linked list // Keep the weak reference through the element of a linked list
weakRefs.add(weakRef); weakRefs.add(weakRef);
...@@ -148,7 +149,7 @@ final public class Pool { ...@@ -148,7 +149,7 @@ final public class Pool {
} }
private Connections getConnections(Object id) { private Connections getConnections(Object id) {
ConnectionsRef ref = (ConnectionsRef) map.get(id); ConnectionsRef ref = map.get(id);
return (ref != null) ? ref.getConnections() : null; return (ref != null) ? ref.getConnections() : null;
} }
...@@ -163,11 +164,10 @@ final public class Pool { ...@@ -163,11 +164,10 @@ final public class Pool {
*/ */
public void expire(long threshold) { public void expire(long threshold) {
synchronized (map) { synchronized (map) {
Collection coll = map.values(); Iterator<ConnectionsRef> iter = map.values().iterator();
Iterator iter = coll.iterator();
Connections conns; Connections conns;
while (iter.hasNext()) { while (iter.hasNext()) {
conns = ((ConnectionsRef) (iter.next())).getConnections(); conns = iter.next().getConnections();
if (conns.expire(threshold)) { if (conns.expire(threshold)) {
d("expire(): removing ", conns); d("expire(): removing ", conns);
iter.remove(); iter.remove();
...@@ -202,7 +202,6 @@ final public class Pool { ...@@ -202,7 +202,6 @@ final public class Pool {
public void showStats(PrintStream out) { public void showStats(PrintStream out) {
Map.Entry entry;
Object id; Object id;
Connections conns; Connections conns;
...@@ -212,13 +211,9 @@ final public class Pool { ...@@ -212,13 +211,9 @@ final public class Pool {
out.println("initial pool size: " + initSize); out.println("initial pool size: " + initSize);
out.println("current pool size: " + map.size()); out.println("current pool size: " + map.size());
Set entries = map.entrySet(); for (Map.Entry<Object, ConnectionsRef> entry : map.entrySet()) {
Iterator iter = entries.iterator();
while (iter.hasNext()) {
entry = (Map.Entry) iter.next();
id = entry.getKey(); id = entry.getKey();
conns = ((ConnectionsRef) entry.getValue()).getConnections(); conns = entry.getValue().getConnections();
out.println(" " + id + ":" + conns.getStats()); out.println(" " + id + ":" + conns.getStats());
} }
......
/* /*
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -41,7 +41,7 @@ final public class PoolCleaner extends Thread { ...@@ -41,7 +41,7 @@ final public class PoolCleaner extends Thread {
public PoolCleaner(long period, Pool[] pools) { public PoolCleaner(long period, Pool[] pools) {
super(); super();
this.period = period; this.period = period;
this.pools = (Pool[]) pools.clone(); this.pools = pools.clone();
setDaemon(true); setDaemon(true);
} }
......
/* /*
* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -57,7 +57,7 @@ final class DefaultCallbackHandler implements CallbackHandler { ...@@ -57,7 +57,7 @@ final class DefaultCallbackHandler implements CallbackHandler {
if (cred instanceof String) { if (cred instanceof String) {
passwd = ((String)cred).toCharArray(); passwd = ((String)cred).toCharArray();
} else if (cred instanceof char[]) { } else if (cred instanceof char[]) {
passwd = (char[])((char[])cred).clone(); passwd = ((char[])cred).clone();
} else if (cred != null) { } else if (cred != null) {
// assume UTF-8 encoding // assume UTF-8 encoding
String orig = new String((byte[])cred, "UTF8"); String orig = new String((byte[])cred, "UTF8");
......
/* /*
* Copyright (c) 1999, 2003, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -89,9 +89,10 @@ final public class LdapSasl { ...@@ -89,9 +89,10 @@ final public class LdapSasl {
* @param bindCtls The possibly null controls to accompany the bind * @param bindCtls The possibly null controls to accompany the bind
* @return LdapResult containing status of the bind * @return LdapResult containing status of the bind
*/ */
@SuppressWarnings("unchecked")
public static LdapResult saslBind(LdapClient clnt, Connection conn, public static LdapResult saslBind(LdapClient clnt, Connection conn,
String server, String dn, Object pw, String server, String dn, Object pw,
String authMech, Hashtable env, Control[] bindCtls) String authMech, Hashtable<?,?> env, Control[] bindCtls)
throws IOException, NamingException { throws IOException, NamingException {
SaslClient saslClnt = null; SaslClient saslClnt = null;
...@@ -112,7 +113,7 @@ final public class LdapSasl { ...@@ -112,7 +113,7 @@ final public class LdapSasl {
try { try {
// Create SASL client to use using SASL package // Create SASL client to use using SASL package
saslClnt = Sasl.createSaslClient( saslClnt = Sasl.createSaslClient(
mechs, authzId, "ldap", server, env, cbh); mechs, authzId, "ldap", server, (Hashtable<String, ?>)env, cbh);
if (saslClnt == null) { if (saslClnt == null) {
throw new AuthenticationNotSupportedException(authMech); throw new AuthenticationNotSupportedException(authMech);
...@@ -185,13 +186,13 @@ final public class LdapSasl { ...@@ -185,13 +186,13 @@ final public class LdapSasl {
*/ */
private static String[] getSaslMechanismNames(String str) { private static String[] getSaslMechanismNames(String str) {
StringTokenizer parser = new StringTokenizer(str); StringTokenizer parser = new StringTokenizer(str);
Vector mechs = new Vector(10); Vector<String> mechs = new Vector<>(10);
while (parser.hasMoreTokens()) { while (parser.hasMoreTokens()) {
mechs.addElement(parser.nextToken()); mechs.addElement(parser.nextToken());
} }
String[] mechNames = new String[mechs.size()]; String[] mechNames = new String[mechs.size()];
for (int i = 0; i < mechs.size(); i++) { for (int i = 0; i < mechs.size(); i++) {
mechNames[i] = (String)mechs.elementAt(i); mechNames[i] = mechs.elementAt(i);
} }
return mechNames; return mechNames;
} }
......
/* /*
* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -50,7 +50,7 @@ import java.util.Hashtable; ...@@ -50,7 +50,7 @@ import java.util.Hashtable;
abstract public class GenericURLDirContext extends GenericURLContext abstract public class GenericURLDirContext extends GenericURLContext
implements DirContext { implements DirContext {
protected GenericURLDirContext(Hashtable env) { protected GenericURLDirContext(Hashtable<?,?> env) {
super(env); super(env);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册