src/java.naming/share/classes/com/sun/jndi/ldap/LdapCtx.java
changeset 57739 6717d7e59db4
parent 52902 e3398b2e1ab0
equal deleted inserted replaced
57738:807d192fb7dd 57739:6717d7e59db4
     1 /*
     1 /*
     2  * Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
   222 
   222 
   223     int port_number;                    // port number of server
   223     int port_number;                    // port number of server
   224     String hostname = null;             // host name of server (no brackets
   224     String hostname = null;             // host name of server (no brackets
   225                                         //   for IPv6 literals)
   225                                         //   for IPv6 literals)
   226     LdapClient clnt = null;             // connection handle
   226     LdapClient clnt = null;             // connection handle
   227     private boolean reconnect = false;  // indicates that re-connect requested
       
   228     Hashtable<String, java.lang.Object> envprops = null; // environment properties of context
   227     Hashtable<String, java.lang.Object> envprops = null; // environment properties of context
   229     int handleReferrals = DEFAULT_REFERRAL_MODE; // how referral is handled
   228     int handleReferrals = DEFAULT_REFERRAL_MODE; // how referral is handled
   230     boolean hasLdapsScheme = false;     // true if the context was created
   229     boolean hasLdapsScheme = false;     // true if the context was created
   231                                         //  using an LDAPS URL.
   230                                         //  using an LDAPS URL.
   232 
   231 
  2666         } else {
  2665         } else {
  2667             envprops.put(BIND_CONTROLS, bindCtls = cloneControls(connCtls));
  2666             envprops.put(BIND_CONTROLS, bindCtls = cloneControls(connCtls));
  2668         }
  2667         }
  2669 
  2668 
  2670         sharable = false;  // can't share with existing contexts
  2669         sharable = false;  // can't share with existing contexts
  2671         reconnect = true;
       
  2672         ensureOpen();      // open or reauthenticated
  2670         ensureOpen();      // open or reauthenticated
  2673     }
  2671     }
  2674 
  2672 
  2675     private void ensureOpen() throws NamingException {
  2673     private void ensureOpen() throws NamingException {
  2676         ensureOpen(false);
  2674         ensureOpen(false);
  2691             } else if (!sharable || startTLS) {
  2689             } else if (!sharable || startTLS) {
  2692 
  2690 
  2693                 synchronized (clnt) {
  2691                 synchronized (clnt) {
  2694                     if (!clnt.isLdapv3
  2692                     if (!clnt.isLdapv3
  2695                         || clnt.referenceCount > 1
  2693                         || clnt.referenceCount > 1
  2696                         || clnt.usingSaslStreams()) {
  2694                         || clnt.usingSaslStreams()
       
  2695                         || !clnt.conn.useable) {
  2697                         closeConnection(SOFT_CLOSE);
  2696                         closeConnection(SOFT_CLOSE);
  2698                     }
  2697                     }
  2699                 }
  2698                 }
  2700                 // reset the cache before a new connection is established
  2699                 // reset the cache before a new connection is established
  2701                 schemaTrees = new Hashtable<>(11, 0.75f);
  2700                 schemaTrees = new Hashtable<>(11, 0.75f);
  2743         }
  2742         }
  2744 
  2743 
  2745         try {
  2744         try {
  2746             boolean initial = (clnt == null);
  2745             boolean initial = (clnt == null);
  2747 
  2746 
  2748             if (initial || reconnect) {
  2747             if (initial) {
  2749                 ldapVersion = (ver != null) ? Integer.parseInt(ver) :
  2748                 ldapVersion = (ver != null) ? Integer.parseInt(ver) :
  2750                     DEFAULT_LDAP_VERSION;
  2749                     DEFAULT_LDAP_VERSION;
  2751 
  2750 
  2752                 clnt = LdapClient.getInstance(
  2751                 clnt = LdapClient.getInstance(
  2753                     usePool, // Whether to use connection pooling
  2752                     usePool, // Whether to use connection pooling
  2770                     user,
  2769                     user,
  2771                     passwd,
  2770                     passwd,
  2772 
  2771 
  2773                     // Required for SASL client identity
  2772                     // Required for SASL client identity
  2774                     envprops);
  2773                     envprops);
  2775 
       
  2776                 reconnect = false;
       
  2777 
  2774 
  2778                 /**
  2775                 /**
  2779                  * Pooled connections are preauthenticated;
  2776                  * Pooled connections are preauthenticated;
  2780                  * newly created ones are not.
  2777                  * newly created ones are not.
  2781                  */
  2778                  */