feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 2001, 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.url.corbaname;
|
||||
|
||||
import com.sun.jndi.url.iiop.iiopURLContextFactory;
|
||||
|
||||
/**
|
||||
* A corbaname URL context factory.
|
||||
* It just uses the iiop URL context factory but is needed here
|
||||
* so that NamingManager.getURLContext() will find it.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
*/
|
||||
final public class corbanameURLContextFactory extends iiopURLContextFactory {
|
||||
}
|
||||
74
jdkSrc/jdk8/com/sun/jndi/url/dns/dnsURLContext.java
Normal file
74
jdkSrc/jdk8/com/sun/jndi/url/dns/dnsURLContext.java
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 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.url.dns;
|
||||
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.*;
|
||||
import javax.naming.spi.ResolveResult;
|
||||
import com.sun.jndi.dns.*;
|
||||
import com.sun.jndi.toolkit.url.GenericURLDirContext;
|
||||
|
||||
|
||||
/**
|
||||
* A DNS URL context resolves names that are DNS pseudo-URLs.
|
||||
* See com.sun.jndi.dns.DnsUrl for a description of the URL format.
|
||||
*
|
||||
* @author Scott Seligman
|
||||
*/
|
||||
|
||||
|
||||
public class dnsURLContext extends GenericURLDirContext {
|
||||
|
||||
public dnsURLContext(Hashtable<?,?> env) {
|
||||
super(env);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the host and port of "url" to a root context connected
|
||||
* to the named DNS server, and returns the domain name as the
|
||||
* remaining name.
|
||||
*/
|
||||
protected ResolveResult getRootURLContext(String url, Hashtable<?,?> env)
|
||||
throws NamingException {
|
||||
|
||||
DnsUrl dnsUrl;
|
||||
try {
|
||||
dnsUrl = new DnsUrl(url);
|
||||
} catch (MalformedURLException e) {
|
||||
throw new InvalidNameException(e.getMessage());
|
||||
}
|
||||
|
||||
DnsUrl[] urls = new DnsUrl[] { dnsUrl };
|
||||
String domain = dnsUrl.getDomain();
|
||||
|
||||
return new ResolveResult(
|
||||
DnsContextFactory.getContext(".", urls, env),
|
||||
new CompositeName().add(domain));
|
||||
}
|
||||
}
|
||||
103
jdkSrc/jdk8/com/sun/jndi/url/dns/dnsURLContextFactory.java
Normal file
103
jdkSrc/jdk8/com/sun/jndi/url/dns/dnsURLContextFactory.java
Normal file
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (c) 2000, 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.url.dns;
|
||||
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.*;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
|
||||
/**
|
||||
* A DNS URL context factory creates contexts that can resolve names
|
||||
* that are DNS pseudo-URLs.
|
||||
* In addition, if given a specific DNS URL (or an array of them), the
|
||||
* factory will resolve all the way to the named context.
|
||||
* See com.sun.jndi.dns.DnsUrl for a description of the URL format.
|
||||
*
|
||||
* @author Scott Seligman
|
||||
*/
|
||||
|
||||
|
||||
public class dnsURLContextFactory implements ObjectFactory {
|
||||
|
||||
public Object getObjectInstance(Object urlInfo, Name name,
|
||||
Context nameCtx, Hashtable<?,?> env)
|
||||
throws NamingException {
|
||||
|
||||
if (urlInfo == null) {
|
||||
return (new dnsURLContext(env));
|
||||
} else if (urlInfo instanceof String) {
|
||||
return getUsingURL((String) urlInfo, env);
|
||||
} else if (urlInfo instanceof String[]) {
|
||||
return getUsingURLs((String[]) urlInfo, env);
|
||||
} else {
|
||||
throw (new ConfigurationException(
|
||||
"dnsURLContextFactory.getObjectInstance: " +
|
||||
"argument must be a DNS URL String or an array of them"));
|
||||
}
|
||||
}
|
||||
|
||||
private static Object getUsingURL(String url, Hashtable<?,?> env)
|
||||
throws NamingException {
|
||||
|
||||
dnsURLContext urlCtx = new dnsURLContext(env);
|
||||
try {
|
||||
return urlCtx.lookup(url);
|
||||
} finally {
|
||||
urlCtx.close();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Try each URL until lookup() succeeds for one of them.
|
||||
* If all URLs fail, throw one of the exceptions arbitrarily.
|
||||
* Not pretty, but potentially more informative than returning null.
|
||||
*/
|
||||
private static Object getUsingURLs(String[] urls, Hashtable<?,?> env)
|
||||
throws NamingException {
|
||||
|
||||
if (urls.length == 0) {
|
||||
throw (new ConfigurationException(
|
||||
"dnsURLContextFactory: empty URL array"));
|
||||
}
|
||||
dnsURLContext urlCtx = new dnsURLContext(env);
|
||||
try {
|
||||
NamingException ne = null;
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
try {
|
||||
return urlCtx.lookup(urls[i]);
|
||||
} catch (NamingException e) {
|
||||
ne = e;
|
||||
}
|
||||
}
|
||||
throw ne; // failure: throw one of the exceptions caught
|
||||
} finally {
|
||||
urlCtx.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
84
jdkSrc/jdk8/com/sun/jndi/url/iiop/iiopURLContext.java
Normal file
84
jdkSrc/jdk8/com/sun/jndi/url/iiop/iiopURLContext.java
Normal file
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* 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.url.iiop;
|
||||
|
||||
import javax.naming.spi.ResolveResult;
|
||||
import javax.naming.*;
|
||||
import java.util.Hashtable;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import com.sun.jndi.cosnaming.IiopUrl;
|
||||
import com.sun.jndi.cosnaming.CorbanameUrl;
|
||||
|
||||
/**
|
||||
* An IIOP URL context.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
*/
|
||||
|
||||
public class iiopURLContext
|
||||
extends com.sun.jndi.toolkit.url.GenericURLContext {
|
||||
|
||||
iiopURLContext(Hashtable<?,?> env) {
|
||||
super(env);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves 'name' into a target context with remaining name.
|
||||
* It only resolves the hostname/port number. The remaining name
|
||||
* contains the rest of the name found in the URL.
|
||||
*
|
||||
* For example, with a iiop URL "iiop://localhost:900/rest/of/name",
|
||||
* this method resolves "iiop://localhost:900/" to the "NameService"
|
||||
* context on for the ORB at 'localhost' on port 900,
|
||||
* and returns as the remaining name "rest/of/name".
|
||||
*/
|
||||
protected ResolveResult getRootURLContext(String name, Hashtable<?,?> env)
|
||||
throws NamingException {
|
||||
return iiopURLContextFactory.getUsingURLIgnoreRest(name, env);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the suffix of an "iiop", "iiopname", or "corbaname" url.
|
||||
* prefix parameter is ignored.
|
||||
*/
|
||||
protected Name getURLSuffix(String prefix, String url)
|
||||
throws NamingException {
|
||||
try {
|
||||
if (url.startsWith("iiop://") || url.startsWith("iiopname://")) {
|
||||
IiopUrl parsedUrl = new IiopUrl(url);
|
||||
return parsedUrl.getCosName();
|
||||
} else if (url.startsWith("corbaname:")) {
|
||||
CorbanameUrl parsedUrl = new CorbanameUrl(url);
|
||||
return parsedUrl.getCosName();
|
||||
} else {
|
||||
throw new MalformedURLException("Not a valid URL: " + url);
|
||||
}
|
||||
} catch (MalformedURLException e) {
|
||||
throw new InvalidNameException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
101
jdkSrc/jdk8/com/sun/jndi/url/iiop/iiopURLContextFactory.java
Normal file
101
jdkSrc/jdk8/com/sun/jndi/url/iiop/iiopURLContextFactory.java
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* 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.url.iiop;
|
||||
|
||||
import javax.naming.*;
|
||||
import javax.naming.spi.*;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import com.sun.jndi.cosnaming.CNCtx;
|
||||
|
||||
/**
|
||||
* An IIOP URL context factory.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
*/
|
||||
|
||||
public class iiopURLContextFactory implements ObjectFactory {
|
||||
|
||||
public Object getObjectInstance(Object urlInfo, Name name, Context nameCtx,
|
||||
Hashtable<?,?> env) throws Exception {
|
||||
|
||||
//System.out.println("iiopURLContextFactory " + urlInfo);
|
||||
if (urlInfo == null) {
|
||||
return new iiopURLContext(env);
|
||||
}
|
||||
if (urlInfo instanceof String) {
|
||||
return getUsingURL((String)urlInfo, env);
|
||||
} else if (urlInfo instanceof String[]) {
|
||||
return getUsingURLs((String[])urlInfo, env);
|
||||
} else {
|
||||
throw (new IllegalArgumentException(
|
||||
"iiopURLContextFactory.getObjectInstance: " +
|
||||
"argument must be a URL String or array of URLs"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves 'name' into a target context with remaining name.
|
||||
* It only resolves the hostname/port number. The remaining name
|
||||
* contains the rest of the name found in the URL.
|
||||
*
|
||||
* For example, with a iiop URL "iiop://localhost:900/rest/of/name",
|
||||
* this method resolves "iiop://localhost:900/" to the "NameService"
|
||||
* context on for the ORB at 'localhost' on port 900,
|
||||
* and returns as the remaining name "rest/of/name".
|
||||
*/
|
||||
static ResolveResult getUsingURLIgnoreRest(String url, Hashtable<?,?> env)
|
||||
throws NamingException {
|
||||
return CNCtx.createUsingURL(url, env);
|
||||
}
|
||||
|
||||
private static Object getUsingURL(String url, Hashtable<?,?> env)
|
||||
throws NamingException {
|
||||
ResolveResult res = getUsingURLIgnoreRest(url, env);
|
||||
|
||||
Context ctx = (Context)res.getResolvedObj();
|
||||
try {
|
||||
return ctx.lookup(res.getRemainingName());
|
||||
} finally {
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
private static Object getUsingURLs(String[] urls, Hashtable<?,?> env) {
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
String url = urls[i];
|
||||
try {
|
||||
Object obj = getUsingURL(url, env);
|
||||
if (obj != null) {
|
||||
return obj;
|
||||
}
|
||||
} catch (NamingException e) {
|
||||
}
|
||||
}
|
||||
return null; // %%% exception??
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 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.url.iiopname;
|
||||
|
||||
import com.sun.jndi.url.iiop.iiopURLContextFactory;
|
||||
|
||||
/**
|
||||
* An iiopname URL context factory.
|
||||
* It just uses the iiop URL context factory but is needed here
|
||||
* so that NamingManager.getURLContext() will find it.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
*/
|
||||
final public class iiopnameURLContextFactory extends iiopURLContextFactory {
|
||||
}
|
||||
633
jdkSrc/jdk8/com/sun/jndi/url/ldap/ldapURLContext.java
Normal file
633
jdkSrc/jdk8/com/sun/jndi/url/ldap/ldapURLContext.java
Normal file
@@ -0,0 +1,633 @@
|
||||
/*
|
||||
* 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.url.ldap;
|
||||
|
||||
import javax.naming.spi.ResolveResult;
|
||||
import javax.naming.*;
|
||||
import javax.naming.directory.*;
|
||||
import java.util.Hashtable;
|
||||
import java.util.StringTokenizer;
|
||||
import com.sun.jndi.ldap.LdapURL;
|
||||
|
||||
/**
|
||||
* An LDAP URL context.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
*/
|
||||
|
||||
final public class ldapURLContext
|
||||
extends com.sun.jndi.toolkit.url.GenericURLDirContext {
|
||||
|
||||
ldapURLContext(Hashtable<?,?> env) {
|
||||
super(env);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves 'name' into a target context with remaining name.
|
||||
* It only resolves the hostname/port number. The remaining name
|
||||
* contains the root DN.
|
||||
*
|
||||
* For example, with a LDAP URL "ldap://localhost:389/o=widget,c=us",
|
||||
* this method resolves "ldap://localhost:389/" to the root LDAP
|
||||
* context on the server 'localhost' on port 389,
|
||||
* and returns as the remaining name "o=widget, c=us".
|
||||
*/
|
||||
protected ResolveResult getRootURLContext(String name, Hashtable<?,?> env)
|
||||
throws NamingException {
|
||||
return ldapURLContextFactory.getUsingURLIgnoreRootDN(name, env);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the suffix of an ldap url.
|
||||
* prefix parameter is ignored.
|
||||
*/
|
||||
protected Name getURLSuffix(String prefix, String url)
|
||||
throws NamingException {
|
||||
|
||||
LdapURL ldapUrl = new LdapURL(url);
|
||||
String dn = (ldapUrl.getDN() != null? ldapUrl.getDN() : "");
|
||||
|
||||
// Represent DN as empty or single-component composite name.
|
||||
CompositeName remaining = new CompositeName();
|
||||
if (!"".equals(dn)) {
|
||||
// if nonempty, add component
|
||||
remaining.add(dn);
|
||||
}
|
||||
return remaining;
|
||||
}
|
||||
|
||||
/*
|
||||
* Override context operations.
|
||||
* Test for presence of LDAP URL query components in the name argument.
|
||||
* Query components are permitted only for search operations and only
|
||||
* when the name has a single component.
|
||||
*/
|
||||
|
||||
public Object lookup(String name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.lookup(name);
|
||||
}
|
||||
}
|
||||
|
||||
public Object lookup(Name name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.lookup(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void bind(String name, Object obj) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
super.bind(name, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
super.bind(name, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public void rebind(String name, Object obj) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
super.rebind(name, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public void rebind(Name name, Object obj) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
super.rebind(name, obj);
|
||||
}
|
||||
}
|
||||
|
||||
public void unbind(String name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
super.unbind(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void unbind(Name name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
super.unbind(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void rename(String oldName, String newName) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(oldName)) {
|
||||
throw new InvalidNameException(oldName);
|
||||
} else if (LdapURL.hasQueryComponents(newName)) {
|
||||
throw new InvalidNameException(newName);
|
||||
} else {
|
||||
super.rename(oldName, newName);
|
||||
}
|
||||
}
|
||||
|
||||
public void rename(Name oldName, Name newName) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(oldName.get(0))) {
|
||||
throw new InvalidNameException(oldName.toString());
|
||||
} else if (LdapURL.hasQueryComponents(newName.get(0))) {
|
||||
throw new InvalidNameException(newName.toString());
|
||||
} else {
|
||||
super.rename(oldName, newName);
|
||||
}
|
||||
}
|
||||
|
||||
public NamingEnumeration<NameClassPair> list(String name)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.list(name);
|
||||
}
|
||||
}
|
||||
|
||||
public NamingEnumeration<NameClassPair> list(Name name)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.list(name);
|
||||
}
|
||||
}
|
||||
|
||||
public NamingEnumeration<Binding> listBindings(String name)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.listBindings(name);
|
||||
}
|
||||
}
|
||||
|
||||
public NamingEnumeration<Binding> listBindings(Name name)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.listBindings(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroySubcontext(String name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
super.destroySubcontext(name);
|
||||
}
|
||||
}
|
||||
|
||||
public void destroySubcontext(Name name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
super.destroySubcontext(name);
|
||||
}
|
||||
}
|
||||
|
||||
public Context createSubcontext(String name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.createSubcontext(name);
|
||||
}
|
||||
}
|
||||
|
||||
public Context createSubcontext(Name name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.createSubcontext(name);
|
||||
}
|
||||
}
|
||||
|
||||
public Object lookupLink(String name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.lookupLink(name);
|
||||
}
|
||||
}
|
||||
|
||||
public Object lookupLink(Name name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.lookupLink(name);
|
||||
}
|
||||
}
|
||||
|
||||
public NameParser getNameParser(String name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.getNameParser(name);
|
||||
}
|
||||
}
|
||||
|
||||
public NameParser getNameParser(Name name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.getNameParser(name);
|
||||
}
|
||||
}
|
||||
|
||||
public String composeName(String name, String prefix)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else if (LdapURL.hasQueryComponents(prefix)) {
|
||||
throw new InvalidNameException(prefix);
|
||||
} else {
|
||||
return super.composeName(name, prefix);
|
||||
}
|
||||
}
|
||||
|
||||
public Name composeName(Name name, Name prefix) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else if (LdapURL.hasQueryComponents(prefix.get(0))) {
|
||||
throw new InvalidNameException(prefix.toString());
|
||||
} else {
|
||||
return super.composeName(name, prefix);
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes getAttributes(String name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.getAttributes(name);
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.getAttributes(name);
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes getAttributes(String name, String[] attrIds)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.getAttributes(name, attrIds);
|
||||
}
|
||||
}
|
||||
|
||||
public Attributes getAttributes(Name name, String[] attrIds)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.getAttributes(name, attrIds);
|
||||
}
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, int mod_op, Attributes attrs)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
super.modifyAttributes(name, mod_op, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, int mod_op, Attributes attrs)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
super.modifyAttributes(name, mod_op, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public void modifyAttributes(String name, ModificationItem[] mods)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
super.modifyAttributes(name, mods);
|
||||
}
|
||||
}
|
||||
|
||||
public void modifyAttributes(Name name, ModificationItem[] mods)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
super.modifyAttributes(name, mods);
|
||||
}
|
||||
}
|
||||
|
||||
public void bind(String name, Object obj, Attributes attrs)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
super.bind(name, obj, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj, Attributes attrs)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
super.bind(name, obj, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public void rebind(String name, Object obj, Attributes attrs)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
super.rebind(name, obj, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public void rebind(Name name, Object obj, Attributes attrs)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
super.rebind(name, obj, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public DirContext createSubcontext(String name, Attributes attrs)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.createSubcontext(name, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public DirContext createSubcontext(Name name, Attributes attrs)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.createSubcontext(name, attrs);
|
||||
}
|
||||
}
|
||||
|
||||
public DirContext getSchema(String name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.getSchema(name);
|
||||
}
|
||||
}
|
||||
|
||||
public DirContext getSchema(Name name) throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.getSchema(name);
|
||||
}
|
||||
}
|
||||
|
||||
public DirContext getSchemaClassDefinition(String name)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
throw new InvalidNameException(name);
|
||||
} else {
|
||||
return super.getSchemaClassDefinition(name);
|
||||
}
|
||||
}
|
||||
|
||||
public DirContext getSchemaClassDefinition(Name name)
|
||||
throws NamingException {
|
||||
if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.getSchemaClassDefinition(name);
|
||||
}
|
||||
}
|
||||
|
||||
// divert the search operation when the LDAP URL has query components
|
||||
public NamingEnumeration<SearchResult> search(String name,
|
||||
Attributes matchingAttributes)
|
||||
throws NamingException {
|
||||
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
return searchUsingURL(name);
|
||||
} else {
|
||||
return super.search(name, matchingAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
// divert the search operation when name has a single component
|
||||
public NamingEnumeration<SearchResult> search(Name name,
|
||||
Attributes matchingAttributes)
|
||||
throws NamingException {
|
||||
if (name.size() == 1) {
|
||||
return search(name.get(0), matchingAttributes);
|
||||
} else if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.search(name, matchingAttributes);
|
||||
}
|
||||
}
|
||||
|
||||
// divert the search operation when the LDAP URL has query components
|
||||
public NamingEnumeration<SearchResult> search(String name,
|
||||
Attributes matchingAttributes,
|
||||
String[] attributesToReturn)
|
||||
throws NamingException {
|
||||
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
return searchUsingURL(name);
|
||||
} else {
|
||||
return super.search(name, matchingAttributes, attributesToReturn);
|
||||
}
|
||||
}
|
||||
|
||||
// divert the search operation when name has a single component
|
||||
public NamingEnumeration<SearchResult> search(Name name,
|
||||
Attributes matchingAttributes,
|
||||
String[] attributesToReturn)
|
||||
throws NamingException {
|
||||
|
||||
if (name.size() == 1) {
|
||||
return search(name.get(0), matchingAttributes, attributesToReturn);
|
||||
} else if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.search(name, matchingAttributes, attributesToReturn);
|
||||
}
|
||||
}
|
||||
|
||||
// divert the search operation when the LDAP URL has query components
|
||||
public NamingEnumeration<SearchResult> search(String name,
|
||||
String filter,
|
||||
SearchControls cons)
|
||||
throws NamingException {
|
||||
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
return searchUsingURL(name);
|
||||
} else {
|
||||
return super.search(name, filter, cons);
|
||||
}
|
||||
}
|
||||
|
||||
// divert the search operation when name has a single component
|
||||
public NamingEnumeration<SearchResult> search(Name name,
|
||||
String filter,
|
||||
SearchControls cons)
|
||||
throws NamingException {
|
||||
|
||||
if (name.size() == 1) {
|
||||
return search(name.get(0), filter, cons);
|
||||
} else if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.search(name, filter, cons);
|
||||
}
|
||||
}
|
||||
|
||||
// divert the search operation when the LDAP URL has query components
|
||||
public NamingEnumeration<SearchResult> search(String name,
|
||||
String filterExpr,
|
||||
Object[] filterArgs,
|
||||
SearchControls cons)
|
||||
throws NamingException {
|
||||
|
||||
if (LdapURL.hasQueryComponents(name)) {
|
||||
return searchUsingURL(name);
|
||||
} else {
|
||||
return super.search(name, filterExpr, filterArgs, cons);
|
||||
}
|
||||
}
|
||||
|
||||
// divert the search operation when name has a single component
|
||||
public NamingEnumeration<SearchResult> search(Name name,
|
||||
String filterExpr,
|
||||
Object[] filterArgs,
|
||||
SearchControls cons)
|
||||
throws NamingException {
|
||||
|
||||
if (name.size() == 1) {
|
||||
return search(name.get(0), filterExpr, filterArgs, cons);
|
||||
} else if (LdapURL.hasQueryComponents(name.get(0))) {
|
||||
throw new InvalidNameException(name.toString());
|
||||
} else {
|
||||
return super.search(name, filterExpr, filterArgs, cons);
|
||||
}
|
||||
}
|
||||
|
||||
// Search using the LDAP URL in name.
|
||||
// LDAP URL query components override the search argments.
|
||||
private NamingEnumeration<SearchResult> searchUsingURL(String name)
|
||||
throws NamingException {
|
||||
|
||||
LdapURL url = new LdapURL(name);
|
||||
|
||||
ResolveResult res = getRootURLContext(name, myEnv);
|
||||
DirContext ctx = (DirContext)res.getResolvedObj();
|
||||
try {
|
||||
return ctx.search(res.getRemainingName(),
|
||||
setFilterUsingURL(url),
|
||||
setSearchControlsUsingURL(url));
|
||||
} finally {
|
||||
ctx.close();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize a String filter using the LDAP URL filter component.
|
||||
* If filter is not present in the URL it is initialized to its default
|
||||
* value as specified in RFC-2255.
|
||||
*/
|
||||
private static String setFilterUsingURL(LdapURL url) {
|
||||
|
||||
String filter = url.getFilter();
|
||||
|
||||
if (filter == null) {
|
||||
filter = "(objectClass=*)"; //default value
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize a SearchControls object using LDAP URL query components.
|
||||
* Components not present in the URL are initialized to their default
|
||||
* values as specified in RFC-2255.
|
||||
*/
|
||||
private static SearchControls setSearchControlsUsingURL(LdapURL url) {
|
||||
|
||||
SearchControls cons = new SearchControls();
|
||||
String scope = url.getScope();
|
||||
String attributes = url.getAttributes();
|
||||
|
||||
if (scope == null) {
|
||||
cons.setSearchScope(SearchControls.OBJECT_SCOPE); //default value
|
||||
} else {
|
||||
if (scope.equals("sub")) {
|
||||
cons.setSearchScope(SearchControls.SUBTREE_SCOPE);
|
||||
} else if (scope.equals("one")) {
|
||||
cons.setSearchScope(SearchControls.ONELEVEL_SCOPE);
|
||||
} else if (scope.equals("base")) {
|
||||
cons.setSearchScope(SearchControls.OBJECT_SCOPE);
|
||||
}
|
||||
}
|
||||
|
||||
if (attributes == null) {
|
||||
cons.setReturningAttributes(null); //default value
|
||||
} else {
|
||||
StringTokenizer tokens = new StringTokenizer(attributes, ",");
|
||||
int count = tokens.countTokens();
|
||||
String[] attrs = new String[count];
|
||||
for (int i = 0; i < count; i ++) {
|
||||
attrs[i] = tokens.nextToken();
|
||||
}
|
||||
cons.setReturningAttributes(attrs);
|
||||
}
|
||||
return cons;
|
||||
}
|
||||
}
|
||||
72
jdkSrc/jdk8/com/sun/jndi/url/ldap/ldapURLContextFactory.java
Normal file
72
jdkSrc/jdk8/com/sun/jndi/url/ldap/ldapURLContextFactory.java
Normal file
@@ -0,0 +1,72 @@
|
||||
/*
|
||||
* 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.url.ldap;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import javax.naming.*;
|
||||
import javax.naming.directory.DirContext;
|
||||
import javax.naming.spi.*;
|
||||
import com.sun.jndi.ldap.LdapCtx;
|
||||
import com.sun.jndi.ldap.LdapCtxFactory;
|
||||
import com.sun.jndi.ldap.LdapURL;
|
||||
|
||||
/**
|
||||
* An LDAP URL context factory.
|
||||
*
|
||||
* @author Rosanna Lee
|
||||
* @author Scott Seligman
|
||||
* @author Vincent Ryan
|
||||
*/
|
||||
|
||||
public class ldapURLContextFactory implements ObjectFactory {
|
||||
|
||||
public Object getObjectInstance(Object urlInfo, Name name, Context nameCtx,
|
||||
Hashtable<?,?> env) throws Exception {
|
||||
|
||||
if (urlInfo == null) {
|
||||
return new ldapURLContext(env);
|
||||
} else {
|
||||
return LdapCtxFactory.getLdapCtxInstance(urlInfo, env);
|
||||
}
|
||||
}
|
||||
|
||||
static ResolveResult getUsingURLIgnoreRootDN(String url, Hashtable<?,?> env)
|
||||
throws NamingException {
|
||||
LdapURL ldapUrl = new LdapURL(url);
|
||||
DirContext ctx = new LdapCtx("", ldapUrl.getHost(), ldapUrl.getPort(),
|
||||
env, ldapUrl.useSsl());
|
||||
String dn = (ldapUrl.getDN() != null ? ldapUrl.getDN() : "");
|
||||
|
||||
// Represent DN as empty or single-component composite name.
|
||||
CompositeName remaining = new CompositeName();
|
||||
if (!"".equals(dn)) {
|
||||
// if nonempty, add component
|
||||
remaining.add(dn);
|
||||
}
|
||||
|
||||
return new ResolveResult(ctx, remaining);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2002, 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.url.ldaps;
|
||||
|
||||
import com.sun.jndi.url.ldap.*;
|
||||
|
||||
/**
|
||||
* An LDAP URL context factory that creates secure LDAP contexts (using SSL).
|
||||
*
|
||||
* @author Vincent Ryan
|
||||
*/
|
||||
|
||||
final public class ldapsURLContextFactory extends ldapURLContextFactory {
|
||||
}
|
||||
334
jdkSrc/jdk8/com/sun/jndi/url/rmi/rmiURLContext.java
Normal file
334
jdkSrc/jdk8/com/sun/jndi/url/rmi/rmiURLContext.java
Normal file
@@ -0,0 +1,334 @@
|
||||
/*
|
||||
* Copyright (c) 1999, 2022, 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.url.rmi;
|
||||
|
||||
import java.net.URI;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
import sun.security.action.GetPropertyAction;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.naming.*;
|
||||
import javax.naming.spi.ResolveResult;
|
||||
import com.sun.jndi.toolkit.url.GenericURLContext;
|
||||
import com.sun.jndi.rmi.registry.RegistryContext;
|
||||
import com.sun.jndi.toolkit.url.Uri.ParseMode;
|
||||
|
||||
|
||||
/**
|
||||
* An RMI URL context resolves names that are URLs of the form
|
||||
* <pre>
|
||||
* rmi://[host][:port][/[object]]
|
||||
* or
|
||||
* rmi:[/][object]
|
||||
* </pre>
|
||||
* If an object is specified, the URL resolves to the named object.
|
||||
* Otherwise, the URL resolves to the specified RMI registry.
|
||||
*
|
||||
* @author Scott Seligman
|
||||
*/
|
||||
public class rmiURLContext extends GenericURLContext {
|
||||
|
||||
private static final String PARSE_MODE_PROP = "com.sun.jndi.rmiURLParsing";
|
||||
private static final ParseMode DEFAULT_PARSE_MODE = ParseMode.COMPAT;
|
||||
|
||||
public static final ParseMode PARSE_MODE;
|
||||
static {
|
||||
PrivilegedAction<String> action =
|
||||
new GetPropertyAction(PARSE_MODE_PROP, DEFAULT_PARSE_MODE.toString());
|
||||
ParseMode parseMode = DEFAULT_PARSE_MODE;
|
||||
try {
|
||||
String mode = AccessController.doPrivileged(action);
|
||||
parseMode = ParseMode.valueOf(mode.toUpperCase(Locale.ROOT));
|
||||
} catch (Throwable t) {
|
||||
parseMode = DEFAULT_PARSE_MODE;
|
||||
} finally {
|
||||
PARSE_MODE = parseMode;
|
||||
}
|
||||
}
|
||||
|
||||
public rmiURLContext(Hashtable<?,?> env) {
|
||||
super(env);
|
||||
}
|
||||
|
||||
public static class Parser {
|
||||
final String url;
|
||||
final ParseMode mode;
|
||||
String host = null;
|
||||
int port = -1;
|
||||
String objName = null;
|
||||
public Parser(String url) {
|
||||
this(url, PARSE_MODE);
|
||||
}
|
||||
public Parser(String url, ParseMode mode) {
|
||||
this.url = url;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
public String url() {return url;}
|
||||
public String host() {return host;}
|
||||
public int port() {return port;}
|
||||
public String objName() {return objName;}
|
||||
public ParseMode mode() {return mode;}
|
||||
|
||||
public void parse() throws NamingException {
|
||||
if (!url.startsWith("rmi:")) {
|
||||
throw (new IllegalArgumentException(
|
||||
"rmiURLContext: name is not an RMI URL: " + url));
|
||||
}
|
||||
|
||||
switch (mode) {
|
||||
case STRICT:
|
||||
parseStrict();
|
||||
break;
|
||||
case COMPAT:
|
||||
parseCompat();
|
||||
break;
|
||||
case LEGACY:
|
||||
parseLegacy();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void parseStrict() throws NamingException {
|
||||
assert url.startsWith("rmi:");
|
||||
|
||||
if (url.equals("rmi:") || url.equals("rmi://")) return;
|
||||
|
||||
// index into url, following the "rmi:"
|
||||
int i = 4;
|
||||
|
||||
if (url.startsWith("//", i)) {
|
||||
i += 2;
|
||||
try {
|
||||
URI uri = URI.create(url);
|
||||
host = uri.getHost();
|
||||
port = uri.getPort();
|
||||
String auth = uri.getRawAuthority();
|
||||
String hostport = (host == null ? "" : host)
|
||||
+ (port == -1 ? "" : ":" + port);
|
||||
if (!hostport.equals(auth)) {
|
||||
boolean failed = true;
|
||||
if (hostport.equals("") && auth.startsWith(":")) {
|
||||
// supports missing host
|
||||
try {
|
||||
port = Integer.parseInt(auth.substring(1));
|
||||
failed = false;
|
||||
} catch (NumberFormatException x) {
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
if (failed) {
|
||||
throw newNamingException(new IllegalArgumentException("invalid authority: "
|
||||
+ auth));
|
||||
}
|
||||
}
|
||||
i += auth.length();
|
||||
} catch (IllegalArgumentException iae) {
|
||||
throw newNamingException(iae);
|
||||
}
|
||||
}
|
||||
int fmark = url.indexOf('#', i);
|
||||
if (fmark > -1) {
|
||||
if (!acceptsFragment()) {
|
||||
throw newNamingException(new IllegalArgumentException("URI fragments not supported: " + url));
|
||||
}
|
||||
}
|
||||
|
||||
if ("".equals(host)) {
|
||||
host = null;
|
||||
}
|
||||
if (url.startsWith("/", i)) { // skip "/" before object name
|
||||
i++;
|
||||
}
|
||||
if (i < url.length()) {
|
||||
objName = url.substring(i);
|
||||
}
|
||||
}
|
||||
|
||||
private void parseCompat() throws NamingException {
|
||||
assert url.startsWith("rmi:");
|
||||
|
||||
int i = 4; // index into url, following the "rmi:"
|
||||
boolean hasAuthority = url.startsWith("//", i);
|
||||
if (hasAuthority) i += 2; // skip past "//"
|
||||
int slash = url.indexOf('/', i);
|
||||
int qmark = url.indexOf('?', i);
|
||||
int fmark = url.indexOf('#', i);
|
||||
if (fmark > -1 && qmark > fmark) qmark = -1;
|
||||
if (fmark > -1 && slash > fmark) slash = -1;
|
||||
if (qmark > -1 && slash > qmark) slash = -1;
|
||||
|
||||
// The end of the authority component is either the
|
||||
// slash (slash will be -1 if it doesn't come before
|
||||
// query or fragment), or the question mark (qmark will
|
||||
// be -1 if it doesn't come before the fragment), or
|
||||
// the fragment separator, or the end of the URI
|
||||
// string if there is no path, no query, and no fragment.
|
||||
int enda = slash > -1 ? slash
|
||||
: (qmark > -1 ? qmark
|
||||
: (fmark > -1 ? fmark
|
||||
: url.length()));
|
||||
if (fmark > -1) {
|
||||
if (!acceptsFragment()) {
|
||||
throw newNamingException(new IllegalArgumentException("URI fragments not supported: " + url));
|
||||
}
|
||||
}
|
||||
|
||||
if (hasAuthority && enda > i) { // parse "//host:port"
|
||||
if (url.startsWith(":", i)) {
|
||||
// LdapURL supports empty host.
|
||||
i++;
|
||||
host = "";
|
||||
if (enda > i) {
|
||||
port = Integer.parseInt(url.substring(i, enda));
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
URI uri = URI.create(url.substring(0, enda));
|
||||
host = uri.getHost();
|
||||
port = uri.getPort();
|
||||
String hostport = (host == null ? "" : host)
|
||||
+ (port == -1 ? "" : ":" + port);
|
||||
if (!hostport.equals(uri.getRawAuthority())) {
|
||||
throw newNamingException(new IllegalArgumentException("invalid authority: "
|
||||
+ uri.getRawAuthority()));
|
||||
}
|
||||
} catch (IllegalArgumentException iae) {
|
||||
throw newNamingException(iae);
|
||||
}
|
||||
}
|
||||
i = enda;
|
||||
}
|
||||
if ("".equals(host)) {
|
||||
host = null;
|
||||
}
|
||||
if (url.startsWith("/", i)) { // skip "/" before object name
|
||||
i++;
|
||||
}
|
||||
if (i < url.length()) {
|
||||
objName = url.substring(i);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// The legacy parsing used to only throw IllegalArgumentException
|
||||
// and continues to do so
|
||||
private void parseLegacy() {
|
||||
assert url.startsWith("rmi:");
|
||||
|
||||
// Parse the URL.
|
||||
int i = 4; // index into url, following the "rmi:"
|
||||
|
||||
if (url.startsWith("//", i)) { // parse "//host:port"
|
||||
i += 2; // skip past "//"
|
||||
int slash = url.indexOf('/', i);
|
||||
if (slash < 0) {
|
||||
slash = url.length();
|
||||
}
|
||||
if (url.startsWith("[", i)) { // at IPv6 literal
|
||||
int brac = url.indexOf(']', i + 1);
|
||||
if (brac < 0 || brac > slash) {
|
||||
throw new IllegalArgumentException(
|
||||
"rmiURLContext: name is an Invalid URL: " + url);
|
||||
}
|
||||
host = url.substring(i, brac + 1); // include brackets
|
||||
i = brac + 1; // skip past "[...]"
|
||||
} else { // at host name or IPv4
|
||||
int colon = url.indexOf(':', i);
|
||||
int hostEnd = (colon < 0 || colon > slash)
|
||||
? slash
|
||||
: colon;
|
||||
if (i < hostEnd) {
|
||||
host = url.substring(i, hostEnd);
|
||||
}
|
||||
i = hostEnd; // skip past host
|
||||
}
|
||||
if ((i + 1 < slash)) {
|
||||
if ( url.startsWith(":", i)) { // parse port
|
||||
i++; // skip past ":"
|
||||
port = Integer.parseInt(url.substring(i, slash));
|
||||
} else {
|
||||
throw new IllegalArgumentException(
|
||||
"rmiURLContext: name is an Invalid URL: " + url);
|
||||
}
|
||||
}
|
||||
i = slash;
|
||||
}
|
||||
if ("".equals(host)) {
|
||||
host = null;
|
||||
}
|
||||
if (url.startsWith("/", i)) { // skip "/" before object name
|
||||
i++;
|
||||
}
|
||||
if (i < url.length()) {
|
||||
objName = url.substring(i);
|
||||
}
|
||||
}
|
||||
|
||||
NamingException newNamingException(Throwable cause) {
|
||||
NamingException ne = new InvalidNameException(cause.getMessage());
|
||||
ne.initCause(cause);
|
||||
return ne;
|
||||
}
|
||||
|
||||
protected boolean acceptsFragment() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves the registry portion of "url" to the corresponding
|
||||
* RMI registry, and returns the atomic object name as the
|
||||
* remaining name.
|
||||
*/
|
||||
protected ResolveResult getRootURLContext(String url, Hashtable<?,?> env)
|
||||
throws NamingException
|
||||
{
|
||||
Parser parser = new Parser(url);
|
||||
parser.parse();
|
||||
String host = parser.host;
|
||||
int port = parser.port;
|
||||
String objName = parser.objName;
|
||||
|
||||
// Represent object name as empty or single-component composite name.
|
||||
CompositeName remaining = new CompositeName();
|
||||
if (objName != null) {
|
||||
remaining.add(objName);
|
||||
}
|
||||
|
||||
// Debug
|
||||
//System.out.println("host=" + host + " port=" + port +
|
||||
// " objName=" + remaining.toString() + "\n");
|
||||
|
||||
// Create a registry context.
|
||||
Context regCtx = new RegistryContext(host, port, env);
|
||||
|
||||
return (new ResolveResult(regCtx, remaining));
|
||||
}
|
||||
}
|
||||
104
jdkSrc/jdk8/com/sun/jndi/url/rmi/rmiURLContextFactory.java
Normal file
104
jdkSrc/jdk8/com/sun/jndi/url/rmi/rmiURLContextFactory.java
Normal file
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* 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.url.rmi;
|
||||
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.*;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
|
||||
/**
|
||||
* An RMI URL context factory creates contexts that can resolve names
|
||||
* that are RMI URLs as defined by rmiURLContext.
|
||||
* In addition, if given a specific RMI URL (or an array of them), the
|
||||
* factory will resolve all the way to the named registry or object.
|
||||
*
|
||||
* @author Scott Seligman
|
||||
*
|
||||
* @see rmiURLContext
|
||||
*/
|
||||
|
||||
|
||||
public class rmiURLContextFactory implements ObjectFactory {
|
||||
|
||||
public Object getObjectInstance(Object urlInfo, Name name,
|
||||
Context nameCtx, Hashtable<?,?> env)
|
||||
throws NamingException
|
||||
{
|
||||
if (urlInfo == null) {
|
||||
return (new rmiURLContext(env));
|
||||
} else if (urlInfo instanceof String) {
|
||||
return getUsingURL((String)urlInfo, env);
|
||||
} else if (urlInfo instanceof String[]) {
|
||||
return getUsingURLs((String[])urlInfo, env);
|
||||
} else {
|
||||
throw (new ConfigurationException(
|
||||
"rmiURLContextFactory.getObjectInstance: " +
|
||||
"argument must be an RMI URL String or an array of them"));
|
||||
}
|
||||
}
|
||||
|
||||
private static Object getUsingURL(String url, Hashtable<?,?> env)
|
||||
throws NamingException
|
||||
{
|
||||
rmiURLContext urlCtx = new rmiURLContext(env);
|
||||
try {
|
||||
return urlCtx.lookup(url);
|
||||
} finally {
|
||||
urlCtx.close();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Try each URL until lookup() succeeds for one of them.
|
||||
* If all URLs fail, throw one of the exceptions arbitrarily.
|
||||
* Not pretty, but potentially more informative than returning null.
|
||||
*/
|
||||
private static Object getUsingURLs(String[] urls, Hashtable<?,?> env)
|
||||
throws NamingException
|
||||
{
|
||||
if (urls.length == 0) {
|
||||
throw (new ConfigurationException(
|
||||
"rmiURLContextFactory: empty URL array"));
|
||||
}
|
||||
rmiURLContext urlCtx = new rmiURLContext(env);
|
||||
try {
|
||||
NamingException ne = null;
|
||||
for (int i = 0; i < urls.length; i++) {
|
||||
try {
|
||||
return urlCtx.lookup(urls[i]);
|
||||
} catch (NamingException e) {
|
||||
ne = e;
|
||||
}
|
||||
}
|
||||
throw ne;
|
||||
} finally {
|
||||
urlCtx.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user