src/share/classes/com/sun/jndi/ldap/LdapCtx.java

Print this page


   1 /*
   2  * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


2129             System.arraycopy(retAttrs, 0, attrs, 0, retAttrs.length);
2130             retAttrs = attrs;
2131         }
2132         return new SearchControls(cons.getSearchScope(),
2133                                   cons.getCountLimit(),
2134                                   cons.getTimeLimit(),
2135                                   retAttrs,
2136                                   cons.getReturningObjFlag(),
2137                                   cons.getDerefLinkFlag());
2138     }
2139 
2140    // -------------- Environment Properties ------------------
2141 
2142     /**
2143      * Override with noncloning version.
2144      */
2145     protected Hashtable<String, Object> p_getEnvironment() {
2146         return envprops;
2147     }
2148 
2149     @SuppressWarnings("unchecked") // clone()
2150     public Hashtable<String, Object> getEnvironment() throws NamingException {
2151         return (envprops == null
2152                 ? new Hashtable<String, Object>(5, 0.75f)
2153                 : (Hashtable<String, Object>)envprops.clone());
2154     }
2155 
2156     @SuppressWarnings("unchecked") // clone()
2157     public Object removeFromEnvironment(String propName)
2158         throws NamingException {
2159 
2160         // not there; just return
2161         if (envprops == null || envprops.get(propName) == null) {
2162             return null;
2163         }
2164         switch (propName) {
2165             case REF_SEPARATOR:
2166                 addrEncodingSeparator = DEFAULT_REF_SEPARATOR;
2167                 break;
2168             case TYPES_ONLY:
2169                 typesOnly = DEFAULT_TYPES_ONLY;
2170                 break;
2171             case DELETE_RDN:
2172                 deleteRDN = DEFAULT_DELETE_RDN;
2173                 break;


2207                 if (useSsl && !hasLdapsScheme) {
2208                     useSsl = false;
2209                     url = null;
2210                     if (useDefaultPortNumber) {
2211                         port_number = DEFAULT_PORT;
2212                     }
2213                 }
2214                 break;
2215             case VERSION:
2216             case SOCKET_FACTORY:
2217                 closeConnection(SOFT_CLOSE);
2218                 break;
2219             case Context.SECURITY_AUTHENTICATION:
2220             case Context.SECURITY_PRINCIPAL:
2221             case Context.SECURITY_CREDENTIALS:
2222                 sharable = false;
2223                 break;
2224         }
2225 
2226         // Update environment; reconnection will use new props
2227         envprops = (Hashtable<String, Object>)envprops.clone();
2228         return envprops.remove(propName);
2229     }
2230 
2231     @SuppressWarnings("unchecked") // clone()
2232     public Object addToEnvironment(String propName, Object propVal)
2233         throws NamingException {
2234 
2235             // If adding null, call remove
2236             if (propVal == null) {
2237                 return removeFromEnvironment(propName);
2238             }
2239             switch (propName) {
2240                 case REF_SEPARATOR:
2241                     setRefSeparator((String)propVal);
2242                     break;
2243                 case TYPES_ONLY:
2244                     setTypesOnly((String)propVal);
2245                     break;
2246                 case DELETE_RDN:
2247                     setDeleteRDN((String)propVal);


2284                         url = null;
2285                         if (useDefaultPortNumber) {
2286                             port_number = DEFAULT_SSL_PORT;
2287                         }
2288                     }
2289                     break;
2290                 case VERSION:
2291                 case SOCKET_FACTORY:
2292                     closeConnection(SOFT_CLOSE);
2293                     break;
2294                 case Context.SECURITY_AUTHENTICATION:
2295                 case Context.SECURITY_PRINCIPAL:
2296                 case Context.SECURITY_CREDENTIALS:
2297                     sharable = false;
2298                     break;
2299             }
2300 
2301             // Update environment; reconnection will use new props
2302             envprops = (envprops == null
2303                 ? new Hashtable<String, Object>(5, 0.75f)
2304                 : (Hashtable<String, Object>)envprops.clone());
2305             return envprops.put(propName, propVal);
2306     }
2307 
2308     /**
2309      * Sets the URL that created the context in the java.naming.provider.url
2310      * property.
2311      */
2312     void setProviderUrl(String providerUrl) { // called by LdapCtxFactory
2313         if (envprops != null) {
2314             envprops.put(Context.PROVIDER_URL, providerUrl);
2315         }
2316     }
2317 
2318     /**
2319      * Sets the domain name for the context in the com.sun.jndi.ldap.domainname
2320      * property.
2321      * Used for hostname verification by Start TLS
2322      */
2323     void setDomainName(String domainName) { // called by LdapCtxFactory
2324         if (envprops != null) {


2631         // Enumerations that are keeping the connection alive
2632         if (enumCount > 0) {
2633             if (debug)
2634                 System.err.println("LdapCtx: close deferred");
2635             closeRequested = true;
2636             return;
2637         }
2638         closeConnection(SOFT_CLOSE);
2639 
2640 // %%%: RL: There is no need to set these to null, as they're just
2641 // variables whose contents and references will automatically
2642 // be cleaned up when they're no longer referenced.
2643 // Also, setting these to null creates problems for the attribute
2644 // schema-related methods, which need these to work.
2645 /*
2646         schemaTrees = null;
2647         envprops = null;
2648 */
2649     }
2650 
2651     @SuppressWarnings("unchecked") // clone()
2652     public void reconnect(Control[] connCtls) throws NamingException {
2653         // Update environment
2654         envprops = (envprops == null
2655                 ? new Hashtable<String, Object>(5, 0.75f)
2656                 : (Hashtable<String, Object>)envprops.clone());
2657 
2658         if (connCtls == null) {
2659             envprops.remove(BIND_CONTROLS);
2660             bindCtls = null;
2661         } else {
2662             envprops.put(BIND_CONTROLS, bindCtls = cloneControls(connCtls));
2663         }
2664 
2665         sharable = false;  // can't share with existing contexts
2666         ensureOpen();      // open or reauthenticated
2667     }
2668 
2669     private void ensureOpen() throws NamingException {
2670         ensureOpen(false);
2671     }
2672 
2673     private void ensureOpen(boolean startTLS) throws NamingException {
2674 
2675         try {
2676             if (clnt == null) {


   1 /*
   2  * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


2129             System.arraycopy(retAttrs, 0, attrs, 0, retAttrs.length);
2130             retAttrs = attrs;
2131         }
2132         return new SearchControls(cons.getSearchScope(),
2133                                   cons.getCountLimit(),
2134                                   cons.getTimeLimit(),
2135                                   retAttrs,
2136                                   cons.getReturningObjFlag(),
2137                                   cons.getDerefLinkFlag());
2138     }
2139 
2140    // -------------- Environment Properties ------------------
2141 
2142     /**
2143      * Override with noncloning version.
2144      */
2145     protected Hashtable<String, Object> p_getEnvironment() {
2146         return envprops;
2147     }
2148 

2149     public Hashtable<String, Object> getEnvironment() throws NamingException {
2150         return (envprops == null
2151                 ? new Hashtable<String, Object>(5, 0.75f)
2152                 : envprops.clone());
2153     }
2154 
2155     @SuppressWarnings("unchecked") // clone()
2156     public Object removeFromEnvironment(String propName)
2157         throws NamingException {
2158 
2159         // not there; just return
2160         if (envprops == null || envprops.get(propName) == null) {
2161             return null;
2162         }
2163         switch (propName) {
2164             case REF_SEPARATOR:
2165                 addrEncodingSeparator = DEFAULT_REF_SEPARATOR;
2166                 break;
2167             case TYPES_ONLY:
2168                 typesOnly = DEFAULT_TYPES_ONLY;
2169                 break;
2170             case DELETE_RDN:
2171                 deleteRDN = DEFAULT_DELETE_RDN;
2172                 break;


2206                 if (useSsl && !hasLdapsScheme) {
2207                     useSsl = false;
2208                     url = null;
2209                     if (useDefaultPortNumber) {
2210                         port_number = DEFAULT_PORT;
2211                     }
2212                 }
2213                 break;
2214             case VERSION:
2215             case SOCKET_FACTORY:
2216                 closeConnection(SOFT_CLOSE);
2217                 break;
2218             case Context.SECURITY_AUTHENTICATION:
2219             case Context.SECURITY_PRINCIPAL:
2220             case Context.SECURITY_CREDENTIALS:
2221                 sharable = false;
2222                 break;
2223         }
2224 
2225         // Update environment; reconnection will use new props
2226         envprops = envprops.clone();
2227         return envprops.remove(propName);
2228     }
2229 
2230     @SuppressWarnings("unchecked") // clone()
2231     public Object addToEnvironment(String propName, Object propVal)
2232         throws NamingException {
2233 
2234             // If adding null, call remove
2235             if (propVal == null) {
2236                 return removeFromEnvironment(propName);
2237             }
2238             switch (propName) {
2239                 case REF_SEPARATOR:
2240                     setRefSeparator((String)propVal);
2241                     break;
2242                 case TYPES_ONLY:
2243                     setTypesOnly((String)propVal);
2244                     break;
2245                 case DELETE_RDN:
2246                     setDeleteRDN((String)propVal);


2283                         url = null;
2284                         if (useDefaultPortNumber) {
2285                             port_number = DEFAULT_SSL_PORT;
2286                         }
2287                     }
2288                     break;
2289                 case VERSION:
2290                 case SOCKET_FACTORY:
2291                     closeConnection(SOFT_CLOSE);
2292                     break;
2293                 case Context.SECURITY_AUTHENTICATION:
2294                 case Context.SECURITY_PRINCIPAL:
2295                 case Context.SECURITY_CREDENTIALS:
2296                     sharable = false;
2297                     break;
2298             }
2299 
2300             // Update environment; reconnection will use new props
2301             envprops = (envprops == null
2302                 ? new Hashtable<String, Object>(5, 0.75f)
2303                 : envprops.clone());
2304             return envprops.put(propName, propVal);
2305     }
2306 
2307     /**
2308      * Sets the URL that created the context in the java.naming.provider.url
2309      * property.
2310      */
2311     void setProviderUrl(String providerUrl) { // called by LdapCtxFactory
2312         if (envprops != null) {
2313             envprops.put(Context.PROVIDER_URL, providerUrl);
2314         }
2315     }
2316 
2317     /**
2318      * Sets the domain name for the context in the com.sun.jndi.ldap.domainname
2319      * property.
2320      * Used for hostname verification by Start TLS
2321      */
2322     void setDomainName(String domainName) { // called by LdapCtxFactory
2323         if (envprops != null) {


2630         // Enumerations that are keeping the connection alive
2631         if (enumCount > 0) {
2632             if (debug)
2633                 System.err.println("LdapCtx: close deferred");
2634             closeRequested = true;
2635             return;
2636         }
2637         closeConnection(SOFT_CLOSE);
2638 
2639 // %%%: RL: There is no need to set these to null, as they're just
2640 // variables whose contents and references will automatically
2641 // be cleaned up when they're no longer referenced.
2642 // Also, setting these to null creates problems for the attribute
2643 // schema-related methods, which need these to work.
2644 /*
2645         schemaTrees = null;
2646         envprops = null;
2647 */
2648     }
2649 

2650     public void reconnect(Control[] connCtls) throws NamingException {
2651         // Update environment
2652         envprops = (envprops == null
2653                 ? new Hashtable<String, Object>(5, 0.75f)
2654                 : envprops.clone());
2655 
2656         if (connCtls == null) {
2657             envprops.remove(BIND_CONTROLS);
2658             bindCtls = null;
2659         } else {
2660             envprops.put(BIND_CONTROLS, bindCtls = cloneControls(connCtls));
2661         }
2662 
2663         sharable = false;  // can't share with existing contexts
2664         ensureOpen();      // open or reauthenticated
2665     }
2666 
2667     private void ensureOpen() throws NamingException {
2668         ensureOpen(false);
2669     }
2670 
2671     private void ensureOpen(boolean startTLS) throws NamingException {
2672 
2673         try {
2674             if (clnt == null) {