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

Print this page

        

*** 221,240 **** int port_number; // port number of server String hostname = null; // host name of server (no brackets // for IPv6 literals) LdapClient clnt = null; // connection handle ! Hashtable envprops = null; // environment properties of context int handleReferrals = DEFAULT_REFERRAL_MODE; // how referral is handled boolean hasLdapsScheme = false; // true if the context was created // using an LDAPS URL. // ------- Not inherited by derived context instances String currentDN; // DN of this context Name currentParsedDN; // DN of this context ! Vector respCtls = null; // Response controls read Control[] reqCtls = null; // Controls to be sent with each request // ------------- Private instance variables ------------------------ --- 221,240 ---- int port_number; // port number of server String hostname = null; // host name of server (no brackets // for IPv6 literals) LdapClient clnt = null; // connection handle ! Hashtable<String, java.lang.Object> envprops = null; // environment properties of context int handleReferrals = DEFAULT_REFERRAL_MODE; // how referral is handled boolean hasLdapsScheme = false; // true if the context was created // using an LDAPS URL. // ------- Not inherited by derived context instances String currentDN; // DN of this context Name currentParsedDN; // DN of this context ! Vector<Control> respCtls = null; // Response controls read Control[] reqCtls = null; // Controls to be sent with each request // ------------- Private instance variables ------------------------
*** 242,259 **** private OutputStream trace = null; // output stream for BER debug output private boolean netscapeSchemaBug = false; // workaround private Control[] bindCtls = null; // Controls to be sent with LDAP "bind" private int referralHopLimit = DEFAULT_REFERRAL_LIMIT; // max referral ! private Hashtable schemaTrees = null; // schema root of this context private int batchSize = DEFAULT_BATCH_SIZE; // batch size for search results private boolean deleteRDN = DEFAULT_DELETE_RDN; // delete the old RDN when modifying DN private boolean typesOnly = DEFAULT_TYPES_ONLY; // return attribute types (no values) private int derefAliases = DEFAULT_DEREF_ALIASES;// de-reference alias entries during searching private char addrEncodingSeparator = DEFAULT_REF_SEPARATOR; // encoding RefAddr ! private Hashtable binaryAttrs = null; // attr values returned as byte[] private int connectTimeout = -1; // no timeout value private int readTimeout = -1; // no timeout value private boolean waitForReply = true; // wait for search response private int replyQueueSize = -1; // unlimited queue size private boolean useSsl = false; // true if SSL protocol is active --- 242,259 ---- private OutputStream trace = null; // output stream for BER debug output private boolean netscapeSchemaBug = false; // workaround private Control[] bindCtls = null; // Controls to be sent with LDAP "bind" private int referralHopLimit = DEFAULT_REFERRAL_LIMIT; // max referral ! private Hashtable<String, DirContext> schemaTrees = null; // schema root of this context private int batchSize = DEFAULT_BATCH_SIZE; // batch size for search results private boolean deleteRDN = DEFAULT_DELETE_RDN; // delete the old RDN when modifying DN private boolean typesOnly = DEFAULT_TYPES_ONLY; // return attribute types (no values) private int derefAliases = DEFAULT_DEREF_ALIASES;// de-reference alias entries during searching private char addrEncodingSeparator = DEFAULT_REF_SEPARATOR; // encoding RefAddr ! private Hashtable<String, Boolean> binaryAttrs = null; // attr values returned as byte[] private int connectTimeout = -1; // no timeout value private int readTimeout = -1; // no timeout value private boolean waitForReply = true; // wait for search response private int replyQueueSize = -1; // unlimited queue size private boolean useSsl = false; // true if SSL protocol is active
*** 270,286 **** private boolean unsolicited = false; // if there unsolicited listeners private boolean sharable = true; // can share connection with other ctx // -------------- Constructors ----------------------------------- ! public LdapCtx(String dn, String host, int port_number, Hashtable props, boolean useSsl) throws NamingException { this.useSsl = this.hasLdapsScheme = useSsl; if (props != null) { ! envprops = (Hashtable) props.clone(); // SSL env prop overrides the useSsl argument if ("ssl".equals(envprops.get(Context.SECURITY_PROTOCOL))) { this.useSsl = true; } --- 270,288 ---- private boolean unsolicited = false; // if there unsolicited listeners private boolean sharable = true; // can share connection with other ctx // -------------- Constructors ----------------------------------- ! @SuppressWarnings("unchecked") ! public LdapCtx(String dn, String host, int port_number, ! Hashtable<?,?> props, boolean useSsl) throws NamingException { this.useSsl = this.hasLdapsScheme = useSsl; if (props != null) { ! envprops = (Hashtable<String, java.lang.Object>) props.clone(); // SSL env prop overrides the useSsl argument if ("ssl".equals(envprops.get(Context.SECURITY_PROTOCOL))) { this.useSsl = true; }
*** 308,318 **** } else { this.port_number = this.useSsl ? DEFAULT_SSL_PORT : DEFAULT_PORT; this.useDefaultPortNumber = true; } ! schemaTrees = new Hashtable(11, 0.75f); initEnv(); try { connect(false); } catch (NamingException e) { try { --- 310,320 ---- } else { this.port_number = this.useSsl ? DEFAULT_SSL_PORT : DEFAULT_PORT; this.useDefaultPortNumber = true; } ! schemaTrees = new Hashtable<>(11, 0.75f); initEnv(); try { connect(false); } catch (NamingException e) { try {
*** 916,938 **** if (dn.equals("")) { return attrs; } // Parse string name into list of RDNs ! //List<Rdn> rdnList = (new LdapName(dn)).rdns(); ! List rdnList = (new LdapName(dn)).getRdns(); // Get leaf RDN ! //Rdn rdn = rdnList.get(rdnList.size() - 1); ! Rdn rdn = (Rdn) rdnList.get(rdnList.size() - 1); Attributes nameAttrs = rdn.toAttributes(); // Add attributes of RDN to attrs if not already there ! NamingEnumeration enum_ = nameAttrs.getAll(); Attribute nameAttr; while (enum_.hasMore()) { ! nameAttr = (Attribute) enum_.next(); // If attrs already has the attribute, don't change or add to it if (attrs.get(nameAttr.getID()) == null) { /** --- 918,938 ---- if (dn.equals("")) { return attrs; } // Parse string name into list of RDNs ! List<Rdn> rdnList = (new LdapName(dn)).getRdns(); // Get leaf RDN ! Rdn rdn = rdnList.get(rdnList.size() - 1); Attributes nameAttrs = rdn.toAttributes(); // Add attributes of RDN to attrs if not already there ! NamingEnumeration<? extends Attribute> enum_ = nameAttrs.getAll(); Attribute nameAttr; while (enum_.hasMore()) { ! nameAttr = enum_.next(); // If attrs already has the attribute, don't change or add to it if (attrs.get(nameAttr.getID()) == null) { /**
*** 959,974 **** return attrs; } ! private static boolean containsIgnoreCase(NamingEnumeration enumStr, String str) throws NamingException { String strEntry; while (enumStr.hasMore()) { ! strEntry = (String) enumStr.next(); if (strEntry.equalsIgnoreCase(str)) { return true; } } return false; --- 959,974 ---- return attrs; } ! private static boolean containsIgnoreCase(NamingEnumeration<String> enumStr, String str) throws NamingException { String strEntry; while (enumStr.hasMore()) { ! strEntry = enumStr.next(); if (strEntry.equalsIgnoreCase(str)) { return true; } } return false;
*** 991,1001 **** /* * Append the the second Vector onto the first Vector * (v2 must be non-null) */ ! private static Vector appendVector(Vector v1, Vector v2) { if (v1 == null) { v1 = v2; } else { for (int i = 0; i < v2.size(); i++) { v1.addElement(v2.elementAt(i)); --- 991,1001 ---- /* * Append the the second Vector onto the first Vector * (v2 must be non-null) */ ! private static <T> Vector<T> appendVector(Vector<T> v1, Vector<T> v2) { if (v1 == null) { v1 = v2; } else { for (int i = 0; i < v2.size(); i++) { v1.addElement(v2.elementAt(i));
*** 1036,1049 **** if (answer.entries == null || answer.entries.size() != 1) { // found it but got no attributes attrs = new BasicAttributes(LdapClient.caseIgnore); } else { ! LdapEntry entry = (LdapEntry)answer.entries.elementAt(0); attrs = entry.attributes; ! Vector entryCtls = entry.respCtls; // retrieve entry controls if (entryCtls != null) { appendVector(respCtls, entryCtls); // concatenate controls } } --- 1036,1049 ---- if (answer.entries == null || answer.entries.size() != 1) { // found it but got no attributes attrs = new BasicAttributes(LdapClient.caseIgnore); } else { ! LdapEntry entry = answer.entries.elementAt(0); attrs = entry.attributes; ! Vector<Control> entryCtls = entry.respCtls; // retrieve entry controls if (entryCtls != null) { appendVector(respCtls, entryCtls); // concatenate controls } }
*** 1095,1105 **** e2.setRootCause(e); throw cont.fillInException(e2); } } ! protected NamingEnumeration c_list(Name name, Continuation cont) throws NamingException { SearchControls cons = new SearchControls(); String[] classAttrs = new String[2]; classAttrs[0] = Obj.JAVA_ATTRIBUTES[Obj.OBJECT_CLASS]; --- 1095,1105 ---- e2.setRootCause(e); throw cont.fillInException(e2); } } ! protected NamingEnumeration<NameClassPair> c_list(Name name, Continuation cont) throws NamingException { SearchControls cons = new SearchControls(); String[] classAttrs = new String[2]; classAttrs[0] = Obj.JAVA_ATTRIBUTES[Obj.OBJECT_CLASS];
*** 1168,1178 **** } catch (NamingException e) { throw cont.fillInException(e); } } ! protected NamingEnumeration c_listBindings(Name name, Continuation cont) throws NamingException { SearchControls cons = new SearchControls(); cons.setReturningAttributes(null); // ask for all attributes cons.setReturningObjFlag(true); // need values to construct obj --- 1168,1179 ---- } catch (NamingException e) { throw cont.fillInException(e); } } ! @SuppressWarnings("unchecked") ! protected NamingEnumeration<Binding> c_listBindings(Name name, Continuation cont) throws NamingException { SearchControls cons = new SearchControls(); cons.setReturningAttributes(null); // ask for all attributes cons.setReturningObjFlag(true); // need values to construct obj
*** 1188,1198 **** if ((answer.status != LdapClient.LDAP_SUCCESS) || (answer.referrals != null)) { processReturnCode(answer, name); } ! return new LdapBindingEnumeration(this, answer, name, cont); } catch (LdapReferralException e) { if (handleReferrals == LdapClient.LDAP_REF_THROW) throw cont.fillInException(e); --- 1189,1200 ---- if ((answer.status != LdapClient.LDAP_SUCCESS) || (answer.referrals != null)) { processReturnCode(answer, name); } ! return (NamingEnumeration) ! new LdapBindingEnumeration(this, answer, name, cont); } catch (LdapReferralException e) { if (handleReferrals == LdapClient.LDAP_REF_THROW) throw cont.fillInException(e);
*** 1220,1238 **** LdapBindingEnumeration res = new LdapBindingEnumeration(this, answer, name, cont); res.setNamingException( (LimitExceededException)cont.fillInException(e)); ! return res; } catch (PartialResultException e) { LdapBindingEnumeration res = new LdapBindingEnumeration(this, answer, name, cont); res.setNamingException( (PartialResultException)cont.fillInException(e)); ! return res; } catch (NamingException e) { throw cont.fillInException(e); } } --- 1222,1240 ---- LdapBindingEnumeration res = new LdapBindingEnumeration(this, answer, name, cont); res.setNamingException( (LimitExceededException)cont.fillInException(e)); ! return (NamingEnumeration)res; } catch (PartialResultException e) { LdapBindingEnumeration res = new LdapBindingEnumeration(this, answer, name, cont); res.setNamingException( (PartialResultException)cont.fillInException(e)); ! return (NamingEnumeration)res; } catch (NamingException e) { throw cont.fillInException(e); } }
*** 1335,1347 **** if (answer.entries == null || answer.entries.size() != 1) { return new BasicAttributes(LdapClient.caseIgnore); } // get attributes from result ! LdapEntry entry = (LdapEntry) answer.entries.elementAt(0); ! Vector entryCtls = entry.respCtls; // retrieve entry controls if (entryCtls != null) { appendVector(respCtls, entryCtls); // concatenate controls } // do this so attributes can find their schema --- 1337,1349 ---- if (answer.entries == null || answer.entries.size() != 1) { return new BasicAttributes(LdapClient.caseIgnore); } // get attributes from result ! LdapEntry entry = answer.entries.elementAt(0); ! Vector<Control> entryCtls = entry.respCtls; // retrieve entry controls if (entryCtls != null) { appendVector(respCtls, entryCtls); // concatenate controls } // do this so attributes can find their schema
*** 1396,1409 **** // construct mod list int[] jmods = new int[attrs.size()]; Attribute[] jattrs = new Attribute[attrs.size()]; ! NamingEnumeration ae = attrs.getAll(); for(int i = 0; i < jmods.length && ae.hasMore(); i++) { jmods[i] = jmod_op; ! jattrs[i] = (Attribute)ae.next(); } LdapResult answer = clnt.modify(newDN, jmods, jattrs, reqCtls); respCtls = answer.resControls; // retrieve response controls --- 1398,1411 ---- // construct mod list int[] jmods = new int[attrs.size()]; Attribute[] jattrs = new Attribute[attrs.size()]; ! NamingEnumeration<? extends Attribute> ae = attrs.getAll(); for(int i = 0; i < jmods.length && ae.hasMore(); i++) { jmods[i] = jmod_op; ! jattrs[i] = ae.next(); } LdapResult answer = clnt.modify(newDN, jmods, jattrs, reqCtls); respCtls = answer.resControls; // retrieve response controls
*** 1563,1573 **** // create a context to hold the schema objects representing the object // classes HierMemDirCtx objectClassCtx = new HierMemDirCtx(); DirContext objectClassDef; String objectClassName; ! for (Enumeration objectClasses = objectClassAttr.getAll(); objectClasses.hasMoreElements(); ) { objectClassName = (String)objectClasses.nextElement(); // %%% Should we fail if not found, or just continue? objectClassDef = (DirContext)ocSchema.lookup(objectClassName); objectClassCtx.bind(objectClassName, objectClassDef); --- 1565,1575 ---- // create a context to hold the schema objects representing the object // classes HierMemDirCtx objectClassCtx = new HierMemDirCtx(); DirContext objectClassDef; String objectClassName; ! for (Enumeration<?> objectClasses = objectClassAttr.getAll(); objectClasses.hasMoreElements(); ) { objectClassName = (String)objectClasses.nextElement(); // %%% Should we fail if not found, or just continue? objectClassDef = (DirContext)ocSchema.lookup(objectClassName); objectClassCtx.bind(objectClassName, objectClassDef);
*** 1589,1599 **** * stores it in our private hash table */ private DirContext getSchemaTree(Name name) throws NamingException { String subschemasubentry = getSchemaEntry(name, true); ! DirContext schemaTree = (DirContext)schemaTrees.get(subschemasubentry); if(schemaTree==null) { if(debug){System.err.println("LdapCtx: building new schema tree " + this);} schemaTree = buildSchemaTree(subschemasubentry); schemaTrees.put(subschemasubentry, schemaTree); --- 1591,1601 ---- * stores it in our private hash table */ private DirContext getSchemaTree(Name name) throws NamingException { String subschemasubentry = getSchemaEntry(name, true); ! DirContext schemaTree = schemaTrees.get(subschemasubentry); if(schemaTree==null) { if(debug){System.err.println("LdapCtx: building new schema tree " + this);} schemaTree = buildSchemaTree(subschemasubentry); schemaTrees.put(subschemasubentry, schemaTree);
*** 1619,1637 **** SCHEMA_ATTRIBUTES /* return schema attrs */, true /* return obj */, false /*deref link */ ); Name sse = (new CompositeName()).add(subschemasubentry); ! NamingEnumeration results = searchAux(sse, "(objectClass=subschema)", constraints, false, true, new Continuation()); if(!results.hasMore()) { throw new OperationNotSupportedException( "Cannot get read subschemasubentry: " + subschemasubentry); } ! SearchResult result = (SearchResult)results.next(); results.close(); Object obj = result.getObject(); if(!(obj instanceof LdapCtx)) { throw new NamingException( --- 1621,1639 ---- SCHEMA_ATTRIBUTES /* return schema attrs */, true /* return obj */, false /*deref link */ ); Name sse = (new CompositeName()).add(subschemasubentry); ! NamingEnumeration<SearchResult> results = searchAux(sse, "(objectClass=subschema)", constraints, false, true, new Continuation()); if(!results.hasMore()) { throw new OperationNotSupportedException( "Cannot get read subschemasubentry: " + subschemasubentry); } ! SearchResult result = results.next(); results.close(); Object obj = result.getObject(); if(!(obj instanceof LdapCtx)) { throw new NamingException(
*** 1672,1682 **** 0, 0, /* count and time limits */ new String[]{"subschemasubentry"} /* attr to return */, false /* returning obj */, false /* deref link */); ! NamingEnumeration results; try { results = searchAux(name, "objectclass=*", constraints, relative, true, new Continuation()); } catch (NamingException ne) { --- 1674,1684 ---- 0, 0, /* count and time limits */ new String[]{"subschemasubentry"} /* attr to return */, false /* returning obj */, false /* deref link */); ! NamingEnumeration<SearchResult> results; try { results = searchAux(name, "objectclass=*", constraints, relative, true, new Continuation()); } catch (NamingException ne) {
*** 1693,1703 **** if (!results.hasMoreElements()) { throw new ConfigurationException( "Requesting schema of nonexistent entry: " + name); } ! SearchResult result = (SearchResult) results.next(); results.close(); Attribute schemaEntryAttr = result.getAttributes().get("subschemasubentry"); //System.err.println("schema entry attrs: " + schemaEntryAttr); --- 1695,1705 ---- if (!results.hasMoreElements()) { throw new ConfigurationException( "Requesting schema of nonexistent entry: " + name); } ! SearchResult result = results.next(); results.close(); Attribute schemaEntryAttr = result.getAttributes().get("subschemasubentry"); //System.err.println("schema entry attrs: " + schemaEntryAttr);
*** 1718,1728 **** // package-private; used by search enum. // Set attributes to point to this context in case some one // asked for their schema void setParents(Attributes attrs, Name name) throws NamingException { ! NamingEnumeration ae = attrs.getAll(); while(ae.hasMore()) { ((LdapAttribute) ae.next()).setParent(this, name); } } --- 1720,1730 ---- // package-private; used by search enum. // Set attributes to point to this context in case some one // asked for their schema void setParents(Attributes attrs, Name name) throws NamingException { ! NamingEnumeration<? extends Attribute> ae = attrs.getAll(); while(ae.hasMore()) { ((LdapAttribute) ae.next()).setParent(this, name); } }
*** 1738,1755 **** return url; } // --------------------- Searches ----------------------------- ! protected NamingEnumeration c_search(Name name, Attributes matchingAttributes, Continuation cont) throws NamingException { return c_search(name, matchingAttributes, null, cont); } ! protected NamingEnumeration c_search(Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont) throws NamingException { SearchControls cons = new SearchControls(); --- 1740,1757 ---- return url; } // --------------------- Searches ----------------------------- ! protected NamingEnumeration<SearchResult> c_search(Name name, Attributes matchingAttributes, Continuation cont) throws NamingException { return c_search(name, matchingAttributes, null, cont); } ! protected NamingEnumeration<SearchResult> c_search(Name name, Attributes matchingAttributes, String[] attributesToReturn, Continuation cont) throws NamingException { SearchControls cons = new SearchControls();
*** 1762,1781 **** throw cont.fillInException(e); } return c_search(name, filter, cons, cont); } ! protected NamingEnumeration c_search(Name name, String filter, SearchControls cons, Continuation cont) throws NamingException { return searchAux(name, filter, cloneSearchControls(cons), true, waitForReply, cont); } ! protected NamingEnumeration c_search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons, Continuation cont) throws NamingException { --- 1764,1783 ---- throw cont.fillInException(e); } return c_search(name, filter, cons, cont); } ! protected NamingEnumeration<SearchResult> c_search(Name name, String filter, SearchControls cons, Continuation cont) throws NamingException { return searchAux(name, filter, cloneSearchControls(cons), true, waitForReply, cont); } ! protected NamingEnumeration<SearchResult> c_search(Name name, String filterExpr, Object[] filterArgs, SearchControls cons, Continuation cont) throws NamingException {
*** 1788,1798 **** } return c_search(name, strfilter, cons, cont); } // Used by NamingNotifier ! NamingEnumeration searchAux(Name name, String filter, SearchControls cons, boolean relative, boolean waitForReply, Continuation cont) throws NamingException { --- 1790,1801 ---- } return c_search(name, strfilter, cons, cont); } // Used by NamingNotifier ! @SuppressWarnings("unchecked") ! NamingEnumeration<SearchResult> searchAux(Name name, String filter, SearchControls cons, boolean relative, boolean waitForReply, Continuation cont) throws NamingException {
*** 1846,1856 **** } else { answer = doSearch(name, filter, cons, relative, waitForReply); // search result may contain referrals processReturnCode(answer, name); } ! return new LdapSearchEnumeration(this, answer, fullyQualifiedName(name), args, cont); } catch (LdapReferralException e) { if (handleReferrals == LdapClient.LDAP_REF_THROW) throw cont.fillInException(e); --- 1849,1860 ---- } else { answer = doSearch(name, filter, cons, relative, waitForReply); // search result may contain referrals processReturnCode(answer, name); } ! return (NamingEnumeration) ! new LdapSearchEnumeration(this, answer, fullyQualifiedName(name), args, cont); } catch (LdapReferralException e) { if (handleReferrals == LdapClient.LDAP_REF_THROW) throw cont.fillInException(e);
*** 1879,1897 **** } catch (LimitExceededException e) { LdapSearchEnumeration res = new LdapSearchEnumeration(this, answer, fullyQualifiedName(name), args, cont); res.setNamingException(e); ! return res; } catch (PartialResultException e) { LdapSearchEnumeration res = new LdapSearchEnumeration(this, answer, fullyQualifiedName(name), args, cont); res.setNamingException(e); ! return res; } catch (IOException e) { NamingException e2 = new CommunicationException(e.getMessage()); e2.setRootCause(e); throw cont.fillInException(e2); --- 1883,1901 ---- } catch (LimitExceededException e) { LdapSearchEnumeration res = new LdapSearchEnumeration(this, answer, fullyQualifiedName(name), args, cont); res.setNamingException(e); ! return (NamingEnumeration)res; } catch (PartialResultException e) { LdapSearchEnumeration res = new LdapSearchEnumeration(this, answer, fullyQualifiedName(name), args, cont); res.setNamingException(e); ! return (NamingEnumeration)res; } catch (IOException e) { NamingException e2 = new CommunicationException(e.getMessage()); e2.setRootCause(e); throw cont.fillInException(e2);
*** 2141,2277 **** // -------------- Environment Properties ------------------ /** * Override with noncloning version. */ ! protected Hashtable p_getEnvironment() { return envprops; } ! public Hashtable getEnvironment() throws NamingException { return (envprops == null ! ? new Hashtable(5, 0.75f) ! : (Hashtable)envprops.clone()); } public Object removeFromEnvironment(String propName) throws NamingException { // not there; just return if (envprops == null || envprops.get(propName) == null) { return null; } ! ! if (propName.equals(REF_SEPARATOR)) { addrEncodingSeparator = DEFAULT_REF_SEPARATOR; ! } else if (propName.equals(TYPES_ONLY)) { typesOnly = DEFAULT_TYPES_ONLY; ! } else if (propName.equals(DELETE_RDN)) { deleteRDN = DEFAULT_DELETE_RDN; ! } else if (propName.equals(DEREF_ALIASES)) { derefAliases = DEFAULT_DEREF_ALIASES; ! } else if (propName.equals(Context.BATCHSIZE)) { batchSize = DEFAULT_BATCH_SIZE; ! } else if (propName.equals(REFERRAL_LIMIT)) { referralHopLimit = DEFAULT_REFERRAL_LIMIT; ! } else if (propName.equals(Context.REFERRAL)) { setReferralMode(null, true); ! } else if (propName.equals(BINARY_ATTRIBUTES)) { setBinaryAttributes(null); ! } else if (propName.equals(CONNECT_TIMEOUT)) { connectTimeout = -1; ! } else if (propName.equals(READ_TIMEOUT)) { readTimeout = -1; ! } else if (propName.equals(WAIT_FOR_REPLY)) { waitForReply = true; ! } else if (propName.equals(REPLY_QUEUE_SIZE)) { replyQueueSize = -1; ! // The following properties affect the connection ! } else if (propName.equals(Context.SECURITY_PROTOCOL)) { closeConnection(SOFT_CLOSE); // De-activate SSL and reset the context's url and port number if (useSsl && !hasLdapsScheme) { useSsl = false; url = null; if (useDefaultPortNumber) { port_number = DEFAULT_PORT; } } ! } else if (propName.equals(VERSION) || ! propName.equals(SOCKET_FACTORY)) { closeConnection(SOFT_CLOSE); ! } else if(propName.equals(Context.SECURITY_AUTHENTICATION) || ! propName.equals(Context.SECURITY_PRINCIPAL) || ! propName.equals(Context.SECURITY_CREDENTIALS)) { sharable = false; } // Update environment; reconnection will use new props ! envprops = (Hashtable)envprops.clone(); return envprops.remove(propName); } public Object addToEnvironment(String propName, Object propVal) throws NamingException { // If adding null, call remove if (propVal == null) { return removeFromEnvironment(propName); } ! ! if (propName.equals(REF_SEPARATOR)) { setRefSeparator((String)propVal); ! } else if (propName.equals(TYPES_ONLY)) { setTypesOnly((String)propVal); ! } else if (propName.equals(DELETE_RDN)) { setDeleteRDN((String)propVal); ! } else if (propName.equals(DEREF_ALIASES)) { setDerefAliases((String)propVal); ! } else if (propName.equals(Context.BATCHSIZE)) { setBatchSize((String)propVal); ! } else if (propName.equals(REFERRAL_LIMIT)) { setReferralLimit((String)propVal); ! } else if (propName.equals(Context.REFERRAL)) { setReferralMode((String)propVal, true); ! } else if (propName.equals(BINARY_ATTRIBUTES)) { setBinaryAttributes((String)propVal); ! } else if (propName.equals(CONNECT_TIMEOUT)) { setConnectTimeout((String)propVal); ! } else if (propName.equals(READ_TIMEOUT)) { setReadTimeout((String)propVal); ! } else if (propName.equals(WAIT_FOR_REPLY)) { setWaitForReply((String)propVal); ! } else if (propName.equals(REPLY_QUEUE_SIZE)) { setReplyQueueSize((String)propVal); // The following properties affect the connection ! } else if (propName.equals(Context.SECURITY_PROTOCOL)) { closeConnection(SOFT_CLOSE); // Activate SSL and reset the context's url and port number if ("ssl".equals(propVal)) { useSsl = true; url = null; if (useDefaultPortNumber) { port_number = DEFAULT_SSL_PORT; } } ! } else if (propName.equals(VERSION) || ! propName.equals(SOCKET_FACTORY)) { closeConnection(SOFT_CLOSE); ! } else if (propName.equals(Context.SECURITY_AUTHENTICATION) || ! propName.equals(Context.SECURITY_PRINCIPAL) || ! propName.equals(Context.SECURITY_CREDENTIALS)) { sharable = false; } // Update environment; reconnection will use new props envprops = (envprops == null ! ? new Hashtable(5, 0.75f) ! : (Hashtable)envprops.clone()); return envprops.put(propName, propVal); } /** * Sets the URL that created the context in the java.naming.provider.url --- 2145,2314 ---- // -------------- Environment Properties ------------------ /** * Override with noncloning version. */ ! protected Hashtable<String, Object> p_getEnvironment() { return envprops; } ! @SuppressWarnings("unchecked") ! public Hashtable<String, Object> getEnvironment() throws NamingException { return (envprops == null ! ? new Hashtable<String, Object>(5, 0.75f) ! : (Hashtable<String, Object>)envprops.clone()); } + @SuppressWarnings("unchecked") public Object removeFromEnvironment(String propName) throws NamingException { // not there; just return if (envprops == null || envprops.get(propName) == null) { return null; } ! switch (propName) { ! case REF_SEPARATOR: addrEncodingSeparator = DEFAULT_REF_SEPARATOR; ! break; ! case TYPES_ONLY: typesOnly = DEFAULT_TYPES_ONLY; ! break; ! case DELETE_RDN: deleteRDN = DEFAULT_DELETE_RDN; ! break; ! case DEREF_ALIASES: derefAliases = DEFAULT_DEREF_ALIASES; ! break; ! case Context.BATCHSIZE: batchSize = DEFAULT_BATCH_SIZE; ! break; ! case REFERRAL_LIMIT: referralHopLimit = DEFAULT_REFERRAL_LIMIT; ! break; ! case Context.REFERRAL: setReferralMode(null, true); ! break; ! case BINARY_ATTRIBUTES: setBinaryAttributes(null); ! break; ! case CONNECT_TIMEOUT: connectTimeout = -1; ! break; ! case READ_TIMEOUT: readTimeout = -1; ! break; ! case WAIT_FOR_REPLY: waitForReply = true; ! break; ! case REPLY_QUEUE_SIZE: replyQueueSize = -1; + break; ! // The following properties affect the connection ! case Context.SECURITY_PROTOCOL: closeConnection(SOFT_CLOSE); // De-activate SSL and reset the context's url and port number if (useSsl && !hasLdapsScheme) { useSsl = false; url = null; if (useDefaultPortNumber) { port_number = DEFAULT_PORT; } } ! break; ! case VERSION: ! case SOCKET_FACTORY: closeConnection(SOFT_CLOSE); ! break; ! case Context.SECURITY_AUTHENTICATION: ! case Context.SECURITY_PRINCIPAL: ! case Context.SECURITY_CREDENTIALS: sharable = false; + break; } // Update environment; reconnection will use new props ! envprops = (Hashtable<String, Object>)envprops.clone(); return envprops.remove(propName); } + @SuppressWarnings("unchecked") public Object addToEnvironment(String propName, Object propVal) throws NamingException { // If adding null, call remove if (propVal == null) { return removeFromEnvironment(propName); } ! switch (propName) { ! case REF_SEPARATOR: setRefSeparator((String)propVal); ! break; ! case TYPES_ONLY: setTypesOnly((String)propVal); ! break; ! case DELETE_RDN: setDeleteRDN((String)propVal); ! break; ! case DEREF_ALIASES: setDerefAliases((String)propVal); ! break; ! case Context.BATCHSIZE: setBatchSize((String)propVal); ! break; ! case REFERRAL_LIMIT: setReferralLimit((String)propVal); ! break; ! case Context.REFERRAL: setReferralMode((String)propVal, true); ! break; ! case BINARY_ATTRIBUTES: setBinaryAttributes((String)propVal); ! break; ! case CONNECT_TIMEOUT: setConnectTimeout((String)propVal); ! break; ! case READ_TIMEOUT: setReadTimeout((String)propVal); ! break; ! case WAIT_FOR_REPLY: setWaitForReply((String)propVal); ! break; ! case REPLY_QUEUE_SIZE: setReplyQueueSize((String)propVal); + break; // The following properties affect the connection ! case Context.SECURITY_PROTOCOL: closeConnection(SOFT_CLOSE); // Activate SSL and reset the context's url and port number if ("ssl".equals(propVal)) { useSsl = true; url = null; if (useDefaultPortNumber) { port_number = DEFAULT_SSL_PORT; } } ! break; ! case VERSION: ! case SOCKET_FACTORY: closeConnection(SOFT_CLOSE); ! break; ! case Context.SECURITY_AUTHENTICATION: ! case Context.SECURITY_PRINCIPAL: ! case Context.SECURITY_CREDENTIALS: sharable = false; + break; } // Update environment; reconnection will use new props envprops = (envprops == null ! ? new Hashtable<String, Object>(5, 0.75f) ! : (Hashtable<String, Object>)envprops.clone()); return envprops.put(propName, propVal); } /** * Sets the URL that created the context in the java.naming.provider.url
*** 2378,2394 **** * If referral mode is 'ignore' then activate the manageReferral control. */ private void setReferralMode(String ref, boolean update) { // First determine the referral mode if (ref != null) { ! if (ref.equals("follow")) { handleReferrals = LdapClient.LDAP_REF_FOLLOW; ! } else if (ref.equals("throw")) { handleReferrals = LdapClient.LDAP_REF_THROW; ! } else if (ref.equals("ignore")) { handleReferrals = LdapClient.LDAP_REF_IGNORE; ! } else { throw new IllegalArgumentException( "Illegal value for " + Context.REFERRAL + " property."); } } else { handleReferrals = DEFAULT_REFERRAL_MODE; --- 2415,2435 ---- * If referral mode is 'ignore' then activate the manageReferral control. */ private void setReferralMode(String ref, boolean update) { // First determine the referral mode if (ref != null) { ! switch (ref) { ! case "follow": handleReferrals = LdapClient.LDAP_REF_FOLLOW; ! break; ! case "throw": handleReferrals = LdapClient.LDAP_REF_THROW; ! break; ! case "ignore": handleReferrals = LdapClient.LDAP_REF_IGNORE; ! break; ! default: throw new IllegalArgumentException( "Illegal value for " + Context.REFERRAL + " property."); } } else { handleReferrals = DEFAULT_REFERRAL_MODE;
*** 2409,2427 **** /** * Set whether aliases are derefereced during resolution and searches. */ private void setDerefAliases(String deref) { if (deref != null) { ! if (deref.equals("never")) { derefAliases = 0; // never de-reference aliases ! } else if (deref.equals("searching")) { derefAliases = 1; // de-reference aliases during searching ! } else if (deref.equals("finding")) { derefAliases = 2; // de-reference during name resolution ! } else if (deref.equals("always")) { derefAliases = 3; // always de-reference aliases ! } else { throw new IllegalArgumentException("Illegal value for " + DEREF_ALIASES + " property."); } } else { derefAliases = DEFAULT_DEREF_ALIASES; --- 2450,2473 ---- /** * Set whether aliases are derefereced during resolution and searches. */ private void setDerefAliases(String deref) { if (deref != null) { ! switch (deref) { ! case "never": derefAliases = 0; // never de-reference aliases ! break; ! case "searching": derefAliases = 1; // de-reference aliases during searching ! break; ! case "finding": derefAliases = 2; // de-reference during name resolution ! break; ! case "always": derefAliases = 3; // always de-reference aliases ! break; ! default: throw new IllegalArgumentException("Illegal value for " + DEREF_ALIASES + " property."); } } else { derefAliases = DEFAULT_DEREF_ALIASES;
*** 2513,2534 **** * <urlstring > ::= "Referral:" <ldapurls> * <ldapurls> ::= <separator> <ldapurl> | <ldapurls> * <separator> ::= ASCII linefeed character (0x0a) * <ldapurl> ::= LDAP URL format (RFC 1959) */ ! private static Vector extractURLs(String refString) { int separator = 0; int urlCount = 0; // count the number of URLs while ((separator = refString.indexOf('\n', separator)) >= 0) { separator++; urlCount++; } ! Vector referrals = new Vector(urlCount); int iURL; int i = 0; separator = refString.indexOf('\n'); iURL = separator + 1; --- 2559,2580 ---- * <urlstring > ::= "Referral:" <ldapurls> * <ldapurls> ::= <separator> <ldapurl> | <ldapurls> * <separator> ::= ASCII linefeed character (0x0a) * <ldapurl> ::= LDAP URL format (RFC 1959) */ ! private static Vector<String> extractURLs(String refString) { int separator = 0; int urlCount = 0; // count the number of URLs while ((separator = refString.indexOf('\n', separator)) >= 0) { separator++; urlCount++; } ! Vector<String> referrals = new Vector<>(urlCount); int iURL; int i = 0; separator = refString.indexOf('\n'); iURL = separator + 1;
*** 2547,2557 **** */ private void setBinaryAttributes(String attrIds) { if (attrIds == null) { binaryAttrs = null; } else { ! binaryAttrs = new Hashtable(11, 0.75f); StringTokenizer tokens = new StringTokenizer(attrIds.toLowerCase(), " "); while (tokens.hasMoreTokens()) { binaryAttrs.put(tokens.nextToken(), Boolean.TRUE); --- 2593,2603 ---- */ private void setBinaryAttributes(String attrIds) { if (attrIds == null) { binaryAttrs = null; } else { ! binaryAttrs = new Hashtable<>(11, 0.75f); StringTokenizer tokens = new StringTokenizer(attrIds.toLowerCase(), " "); while (tokens.hasMoreTokens()) { binaryAttrs.put(tokens.nextToken(), Boolean.TRUE);
*** 2599,2613 **** schemaTrees = null; envprops = null; */ } public void reconnect(Control[] connCtls) throws NamingException { // Update environment envprops = (envprops == null ! ? new Hashtable(5, 0.75f) ! : (Hashtable)envprops.clone()); if (connCtls == null) { envprops.remove(BIND_CONTROLS); bindCtls = null; } else { --- 2645,2660 ---- schemaTrees = null; envprops = null; */ } + @SuppressWarnings("unchecked") public void reconnect(Control[] connCtls) throws NamingException { // Update environment envprops = (envprops == null ! ? new Hashtable<String, Object>(5, 0.75f) ! : (Hashtable<String, Object>)envprops.clone()); if (connCtls == null) { envprops.remove(BIND_CONTROLS); bindCtls = null; } else {
*** 2629,2639 **** if (debug) { System.err.println("LdapCtx: Reconnecting " + this); } // reset the cache before a new connection is established ! schemaTrees = new Hashtable(11, 0.75f); connect(startTLS); } else if (!sharable || startTLS) { synchronized (clnt) { --- 2676,2686 ---- if (debug) { System.err.println("LdapCtx: Reconnecting " + this); } // reset the cache before a new connection is established ! schemaTrees = new Hashtable<>(11, 0.75f); connect(startTLS); } else if (!sharable || startTLS) { synchronized (clnt) {
*** 2642,2652 **** || clnt.usingSaslStreams()) { closeConnection(SOFT_CLOSE); } } // reset the cache before a new connection is established ! schemaTrees = new Hashtable(11, 0.75f); connect(startTLS); } } finally { sharable = true; // connection is now either new or single-use --- 2689,2699 ---- || clnt.usingSaslStreams()) { closeConnection(SOFT_CLOSE); } } // reset the cache before a new connection is established ! schemaTrees = new Hashtable<>(11, 0.75f); connect(startTLS); } } finally { sharable = true; // connection is now either new or single-use
*** 2844,2854 **** envprops, fullyQualifiedName(remainName)); } protected void processReturnCode(LdapResult res, Name resolvedName, ! Object resolvedObj, Name remainName, Hashtable envprops, String fullDN) throws NamingException { String msg = LdapClient.getErrorMessage(res.status, res.errorMessage); NamingException e; LdapReferralException r = null; --- 2891,2901 ---- envprops, fullyQualifiedName(remainName)); } protected void processReturnCode(LdapResult res, Name resolvedName, ! Object resolvedObj, Name remainName, Hashtable<?,?> envprops, String fullDN) throws NamingException { String msg = LdapClient.getErrorMessage(res.status, res.errorMessage); NamingException e; LdapReferralException r = null;
*** 2964,2974 **** break; } // extract SLAPD-style referrals from errorMessage if ((res.errorMessage != null) && (!res.errorMessage.equals(""))) { ! res.referrals = extractURLs(res.errorMessage); } else { e = new PartialResultException(msg); break; } --- 3011,3023 ---- break; } // extract SLAPD-style referrals from errorMessage if ((res.errorMessage != null) && (!res.errorMessage.equals(""))) { ! @SuppressWarnings("unchecked") ! Vector<Object> temp = (Vector)extractURLs(res.errorMessage); ! res.referrals = temp; } else { e = new PartialResultException(msg); break; }
*** 2996,3006 **** * assume name resolution has not yet completed. */ if (((res.entries == null) || (res.entries.size() == 0)) && (res.referrals.size() == 1)) { ! r.setReferralInfo((Vector)res.referrals, false); // check the hop limit if (hopCount > referralHopLimit) { NamingException lee = new LimitExceededException("Referral limit exceeded"); --- 3045,3055 ---- * assume name resolution has not yet completed. */ if (((res.entries == null) || (res.entries.size() == 0)) && (res.referrals.size() == 1)) { ! r.setReferralInfo(res.referrals, false); // check the hop limit if (hopCount > referralHopLimit) { NamingException lee = new LimitExceededException("Referral limit exceeded");
*** 3282,3294 **** return (respCtls != null)? convertControls(respCtls) : null; } /** * Narrow controls using own default factory and ControlFactory. ! * @param ctls A non-null Vector */ ! Control[] convertControls(Vector ctls) throws NamingException { int count = ctls.size(); if (count == 0) { return null; } --- 3331,3343 ---- return (respCtls != null)? convertControls(respCtls) : null; } /** * Narrow controls using own default factory and ControlFactory. ! * @param ctls A non-null Vector<Control> */ ! Control[] convertControls(Vector<Control> ctls) throws NamingException { int count = ctls.size(); if (count == 0) { return null; }
*** 3296,3311 **** Control[] controls = new Control[count]; for (int i = 0; i < count; i++) { // Try own factory first controls[i] = myResponseControlFactory.getControlInstance( ! (Control)ctls.elementAt(i)); // Try assigned factories if own produced null if (controls[i] == null) { controls[i] = ControlFactory.getControlInstance( ! (Control)ctls.elementAt(i), this, envprops); } } return controls; } --- 3345,3360 ---- Control[] controls = new Control[count]; for (int i = 0; i < count; i++) { // Try own factory first controls[i] = myResponseControlFactory.getControlInstance( ! ctls.elementAt(i)); // Try assigned factories if own produced null if (controls[i] == null) { controls[i] = ControlFactory.getControlInstance( ! ctls.elementAt(i), this, envprops); } } return controls; }