Path: blob/master/src/java.naming/share/classes/com/sun/jndi/ldap/LdapReferralContext.java
41161 views
/*1* Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jndi.ldap;2627import javax.naming.*;28import javax.naming.directory.*;29import javax.naming.spi.*;30import javax.naming.ldap.*;3132import java.util.Hashtable;33import java.util.StringTokenizer;34import com.sun.jndi.toolkit.dir.SearchFilter;3536/**37* A context for handling referrals.38*39* @author Vincent Ryan40*/41final class LdapReferralContext implements DirContext, LdapContext {4243private DirContext refCtx = null;44private Name urlName = null; // override the supplied name45private String urlAttrs = null; // override attributes46private String urlScope = null; // override scope47private String urlFilter = null; // override filter4849private LdapReferralException refEx = null;50private boolean skipThisReferral = false;51private int hopCount = 1;52private NamingException previousEx = null;5354@SuppressWarnings("unchecked") // clone()55LdapReferralContext(LdapReferralException ex,56Hashtable<?,?> env,57Control[] connCtls,58Control[] reqCtls,59String nextName,60boolean skipThisReferral,61int handleReferrals) throws NamingException {6263refEx = ex;6465if (this.skipThisReferral = skipThisReferral) {66return; // don't create a DirContext for this referral67}6869String referral;7071// Make copies of environment and connect controls for our own use.72if (env != null) {73env = (Hashtable<?,?>) env.clone();74// Remove old connect controls from environment, unless we have new75// ones that will override them anyway.76if (connCtls == null) {77env.remove(LdapCtx.BIND_CONTROLS);78}79} else if (connCtls != null) {80env = new Hashtable<String, Control[]>(5);81}82if (connCtls != null) {83Control[] copiedCtls = new Control[connCtls.length];84System.arraycopy(connCtls, 0, copiedCtls, 0, connCtls.length);85// Add copied controls to environment, replacing any old ones.86((Hashtable<? super String, ? super Control[]>)env)87.put(LdapCtx.BIND_CONTROLS, copiedCtls);88}8990while (true) {91try {92referral = refEx.getNextReferral();93if (referral == null) {94if (previousEx != null) {95throw (NamingException)(previousEx.fillInStackTrace());96} else {97throw new NamingException(98"Illegal encoding: referral is empty");99}100}101102} catch (LdapReferralException e) {103104if (handleReferrals == LdapClient.LDAP_REF_THROW) {105throw e;106} else {107refEx = e;108continue;109}110}111112// Create a Reference containing the referral URL.113Reference ref = new Reference("javax.naming.directory.DirContext",114new StringRefAddr("URL", referral));115116Object obj;117try {118obj = NamingManager.getObjectInstance(ref, null, null, env);119120} catch (NamingException e) {121122if (handleReferrals == LdapClient.LDAP_REF_THROW) {123throw e;124}125126// mask the exception and save it for later127previousEx = e;128129// follow another referral130continue;131132} catch (Exception e) {133NamingException e2 =134new NamingException(135"problem generating object using object factory");136e2.setRootCause(e);137throw e2;138}139if (obj instanceof DirContext) {140refCtx = (DirContext)obj;141if (refCtx instanceof LdapContext && reqCtls != null) {142((LdapContext)refCtx).setRequestControls(reqCtls);143}144initDefaults(referral, nextName);145146break;147} else {148NamingException ne = new NotContextException(149"Cannot create context for: " + referral);150ne.setRemainingName((new CompositeName()).add(nextName));151throw ne;152}153}154}155156private void initDefaults(String referral, String nextName)157throws NamingException {158String urlString;159try {160// parse URL161LdapURL url = new LdapURL(referral);162urlString = url.getDN();163urlAttrs = url.getAttributes();164urlScope = url.getScope();165urlFilter = url.getFilter();166167} catch (NamingException e) {168// Not an LDAP URL; use original URL169urlString = referral;170urlAttrs = urlScope = urlFilter = null;171}172173// reuse original name if URL DN is absent174if (urlString == null) {175urlString = nextName;176} else {177// concatenate with remaining name if URL DN is present178urlString = "";179}180181if (urlString == null) {182urlName = null;183} else {184urlName = urlString.isEmpty() ? new CompositeName() :185new CompositeName().add(urlString);186}187}188189190public void close() throws NamingException {191if (refCtx != null) {192refCtx.close();193refCtx = null;194}195refEx = null;196}197198void setHopCount(int hopCount) {199this.hopCount = hopCount;200if ((refCtx != null) && (refCtx instanceof LdapCtx)) {201((LdapCtx)refCtx).setHopCount(hopCount);202}203}204205public Object lookup(String name) throws NamingException {206return lookup(toName(name));207}208209public Object lookup(Name name) throws NamingException {210if (skipThisReferral) {211throw (NamingException)212((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());213}214215return refCtx.lookup(overrideName(name));216}217218public void bind(String name, Object obj) throws NamingException {219bind(toName(name), obj);220}221222public void bind(Name name, Object obj) throws NamingException {223if (skipThisReferral) {224throw (NamingException)225((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());226}227228refCtx.bind(overrideName(name), obj);229}230231public void rebind(String name, Object obj) throws NamingException {232rebind(toName(name), obj);233}234235public void rebind(Name name, Object obj) throws NamingException {236if (skipThisReferral) {237throw (NamingException)238((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());239}240241refCtx.rebind(overrideName(name), obj);242}243244public void unbind(String name) throws NamingException {245unbind(toName(name));246}247248public void unbind(Name name) throws NamingException {249if (skipThisReferral) {250throw (NamingException)251((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());252}253254refCtx.unbind(overrideName(name));255}256257public void rename(String oldName, String newName) throws NamingException {258rename(toName(oldName), toName(newName));259}260261public void rename(Name oldName, Name newName) throws NamingException {262if (skipThisReferral) {263throw (NamingException)264((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());265}266267refCtx.rename(overrideName(oldName), toName(refEx.getNewRdn()));268}269270public NamingEnumeration<NameClassPair> list(String name) throws NamingException {271return list(toName(name));272}273274@SuppressWarnings("unchecked")275public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {276if (skipThisReferral) {277throw (NamingException)278((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());279}280try {281NamingEnumeration<NameClassPair> ne = null;282283if (urlScope != null && urlScope.equals("base")) {284SearchControls cons = new SearchControls();285cons.setReturningObjFlag(true);286cons.setSearchScope(SearchControls.OBJECT_SCOPE);287288ne = (NamingEnumeration)289refCtx.search(overrideName(name), "(objectclass=*)", cons);290291} else {292ne = refCtx.list(overrideName(name));293}294295refEx.setNameResolved(true);296297// append (referrals from) the exception that generated this298// context to the new search results, so that referral processing299// can continue300((ReferralEnumeration)ne).appendUnprocessedReferrals(refEx);301302return (ne);303304} catch (LdapReferralException e) {305306// append (referrals from) the exception that generated this307// context to the new exception, so that referral processing308// can continue309310e.appendUnprocessedReferrals(refEx);311throw (NamingException)(e.fillInStackTrace());312313} catch (NamingException e) {314315// record the exception if there are no remaining referrals316if ((refEx != null) && (! refEx.hasMoreReferrals())) {317refEx.setNamingException(e);318}319if ((refEx != null) &&320(refEx.hasMoreReferrals() ||321refEx.hasMoreReferralExceptions())) {322throw (NamingException)323((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());324} else {325throw e;326}327}328}329330public NamingEnumeration<Binding> listBindings(String name) throws331NamingException {332return listBindings(toName(name));333}334335@SuppressWarnings("unchecked")336public NamingEnumeration<Binding> listBindings(Name name) throws337NamingException {338if (skipThisReferral) {339throw (NamingException)340((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());341}342343try {344NamingEnumeration<Binding> be = null;345346if (urlScope != null && urlScope.equals("base")) {347SearchControls cons = new SearchControls();348cons.setReturningObjFlag(true);349cons.setSearchScope(SearchControls.OBJECT_SCOPE);350351be = (NamingEnumeration)refCtx.search(overrideName(name),352"(objectclass=*)", cons);353354} else {355be = refCtx.listBindings(overrideName(name));356}357358refEx.setNameResolved(true);359360// append (referrals from) the exception that generated this361// context to the new search results, so that referral processing362// can continue363((ReferralEnumeration<Binding>)be).appendUnprocessedReferrals(refEx);364365return (be);366367} catch (LdapReferralException e) {368369// append (referrals from) the exception that generated this370// context to the new exception, so that referral processing371// can continue372373e.appendUnprocessedReferrals(refEx);374throw (NamingException)(e.fillInStackTrace());375376} catch (NamingException e) {377378// record the exception if there are no remaining referrals379if ((refEx != null) && (! refEx.hasMoreReferrals())) {380refEx.setNamingException(e);381}382if ((refEx != null) &&383(refEx.hasMoreReferrals() ||384refEx.hasMoreReferralExceptions())) {385throw (NamingException)386((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());387} else {388throw e;389}390}391}392393public void destroySubcontext(String name) throws NamingException {394destroySubcontext(toName(name));395}396397public void destroySubcontext(Name name) throws NamingException {398if (skipThisReferral) {399throw (NamingException)400((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());401}402403refCtx.destroySubcontext(overrideName(name));404}405406public Context createSubcontext(String name) throws NamingException {407return createSubcontext(toName(name));408}409410public Context createSubcontext(Name name) throws NamingException {411if (skipThisReferral) {412throw (NamingException)413((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());414}415416return refCtx.createSubcontext(overrideName(name));417}418419public Object lookupLink(String name) throws NamingException {420return lookupLink(toName(name));421}422423public Object lookupLink(Name name) throws NamingException {424if (skipThisReferral) {425throw (NamingException)426((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());427}428429return refCtx.lookupLink(overrideName(name));430}431432public NameParser getNameParser(String name) throws NamingException {433return getNameParser(toName(name));434}435436public NameParser getNameParser(Name name) throws NamingException {437if (skipThisReferral) {438throw (NamingException)439((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());440}441442return refCtx.getNameParser(overrideName(name));443}444445public String composeName(String name, String prefix)446throws NamingException {447return composeName(toName(name), toName(prefix)).toString();448}449450public Name composeName(Name name, Name prefix) throws NamingException {451if (skipThisReferral) {452throw (NamingException)453((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());454}455return refCtx.composeName(name, prefix);456}457458public Object addToEnvironment(String propName, Object propVal)459throws NamingException {460if (skipThisReferral) {461throw (NamingException)462((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());463}464465return refCtx.addToEnvironment(propName, propVal);466}467468public Object removeFromEnvironment(String propName)469throws NamingException {470if (skipThisReferral) {471throw (NamingException)472((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());473}474475return refCtx.removeFromEnvironment(propName);476}477478public Hashtable<?,?> getEnvironment() throws NamingException {479if (skipThisReferral) {480throw (NamingException)481((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());482}483484return refCtx.getEnvironment();485}486487public Attributes getAttributes(String name) throws NamingException {488return getAttributes(toName(name));489}490491public Attributes getAttributes(Name name) throws NamingException {492if (skipThisReferral) {493throw (NamingException)494((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());495}496497return refCtx.getAttributes(overrideName(name));498}499500public Attributes getAttributes(String name, String[] attrIds)501throws NamingException {502return getAttributes(toName(name), attrIds);503}504505public Attributes getAttributes(Name name, String[] attrIds)506throws NamingException {507if (skipThisReferral) {508throw (NamingException)509((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());510}511512return refCtx.getAttributes(overrideName(name), attrIds);513}514515public void modifyAttributes(String name, int mod_op, Attributes attrs)516throws NamingException {517modifyAttributes(toName(name), mod_op, attrs);518}519520public void modifyAttributes(Name name, int mod_op, Attributes attrs)521throws NamingException {522if (skipThisReferral) {523throw (NamingException)524((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());525}526527refCtx.modifyAttributes(overrideName(name), mod_op, attrs);528}529530public void modifyAttributes(String name, ModificationItem[] mods)531throws NamingException {532modifyAttributes(toName(name), mods);533}534535public void modifyAttributes(Name name, ModificationItem[] mods)536throws NamingException {537if (skipThisReferral) {538throw (NamingException)539((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());540}541542refCtx.modifyAttributes(overrideName(name), mods);543}544545public void bind(String name, Object obj, Attributes attrs)546throws NamingException {547bind(toName(name), obj, attrs);548}549550public void bind(Name name, Object obj, Attributes attrs)551throws NamingException {552if (skipThisReferral) {553throw (NamingException)554((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());555}556557refCtx.bind(overrideName(name), obj, attrs);558}559560public void rebind(String name, Object obj, Attributes attrs)561throws NamingException {562rebind(toName(name), obj, attrs);563}564565public void rebind(Name name, Object obj, Attributes attrs)566throws NamingException {567if (skipThisReferral) {568throw (NamingException)569((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());570}571572refCtx.rebind(overrideName(name), obj, attrs);573}574575public DirContext createSubcontext(String name, Attributes attrs)576throws NamingException {577return createSubcontext(toName(name), attrs);578}579580public DirContext createSubcontext(Name name, Attributes attrs)581throws NamingException {582if (skipThisReferral) {583throw (NamingException)584((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());585}586587return refCtx.createSubcontext(overrideName(name), attrs);588}589590public DirContext getSchema(String name) throws NamingException {591return getSchema(toName(name));592}593594public DirContext getSchema(Name name) throws NamingException {595if (skipThisReferral) {596throw (NamingException)597((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());598}599600return refCtx.getSchema(overrideName(name));601}602603public DirContext getSchemaClassDefinition(String name)604throws NamingException {605return getSchemaClassDefinition(toName(name));606}607608public DirContext getSchemaClassDefinition(Name name)609throws NamingException {610if (skipThisReferral) {611throw (NamingException)612((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());613}614615return refCtx.getSchemaClassDefinition(overrideName(name));616}617618public NamingEnumeration<SearchResult> search(String name,619Attributes matchingAttributes)620throws NamingException {621return search(toName(name), SearchFilter.format(matchingAttributes),622new SearchControls());623}624625public NamingEnumeration<SearchResult> search(Name name,626Attributes matchingAttributes)627throws NamingException {628return search(name, SearchFilter.format(matchingAttributes),629new SearchControls());630}631632public NamingEnumeration<SearchResult> search(String name,633Attributes matchingAttributes,634String[] attributesToReturn)635throws NamingException {636SearchControls cons = new SearchControls();637cons.setReturningAttributes(attributesToReturn);638639return search(toName(name), SearchFilter.format(matchingAttributes),640cons);641}642643public NamingEnumeration<SearchResult> search(Name name,644Attributes matchingAttributes,645String[] attributesToReturn)646throws NamingException {647SearchControls cons = new SearchControls();648cons.setReturningAttributes(attributesToReturn);649650return search(name, SearchFilter.format(matchingAttributes), cons);651}652653public NamingEnumeration<SearchResult> search(String name,654String filter,655SearchControls cons)656throws NamingException {657return search(toName(name), filter, cons);658}659660public NamingEnumeration<SearchResult> search(Name name,661String filter,662SearchControls cons) throws NamingException {663664if (skipThisReferral) {665throw (NamingException)666((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());667}668669try {670NamingEnumeration<SearchResult> se =671refCtx.search(overrideName(name),672overrideFilter(filter),673overrideAttributesAndScope(cons));674675refEx.setNameResolved(true);676677// append (referrals from) the exception that generated this678// context to the new search results, so that referral processing679// can continue680((ReferralEnumeration)se).appendUnprocessedReferrals(refEx);681682return (se);683684} catch (LdapReferralException e) {685686// %%% setNameResolved(true);687688// append (referrals from) the exception that generated this689// context to the new exception, so that referral processing690// can continue691692e.appendUnprocessedReferrals(refEx);693throw (NamingException)(e.fillInStackTrace());694695} catch (NamingException e) {696697// record the exception if there are no remaining referrals698if ((refEx != null) && (! refEx.hasMoreReferrals())) {699refEx.setNamingException(e);700}701if ((refEx != null) &&702(refEx.hasMoreReferrals() ||703refEx.hasMoreReferralExceptions())) {704throw (NamingException)705((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());706} else {707throw e;708}709}710}711712public NamingEnumeration<SearchResult> search(String name,713String filterExpr,714Object[] filterArgs,715SearchControls cons)716throws NamingException {717return search(toName(name), filterExpr, filterArgs, cons);718}719720public NamingEnumeration<SearchResult> search(Name name,721String filterExpr,722Object[] filterArgs,723SearchControls cons) throws NamingException {724725if (skipThisReferral) {726throw (NamingException)727((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());728}729730try {731NamingEnumeration<SearchResult> se;732733if (urlFilter != null) {734se = refCtx.search(overrideName(name), urlFilter,735overrideAttributesAndScope(cons));736} else {737se = refCtx.search(overrideName(name), filterExpr,738filterArgs, overrideAttributesAndScope(cons));739}740741refEx.setNameResolved(true);742743// append (referrals from) the exception that generated this744// context to the new search results, so that referral processing745// can continue746((ReferralEnumeration)se).appendUnprocessedReferrals(refEx);747748return (se);749750} catch (LdapReferralException e) {751752// append (referrals from) the exception that generated this753// context to the new exception, so that referral processing754// can continue755756e.appendUnprocessedReferrals(refEx);757throw (NamingException)(e.fillInStackTrace());758759} catch (NamingException e) {760761// record the exception if there are no remaining referrals762if ((refEx != null) && (! refEx.hasMoreReferrals())) {763refEx.setNamingException(e);764}765if ((refEx != null) &&766(refEx.hasMoreReferrals() ||767refEx.hasMoreReferralExceptions())) {768throw (NamingException)769((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());770} else {771throw e;772}773}774}775776public String getNameInNamespace() throws NamingException {777if (skipThisReferral) {778throw (NamingException)779((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());780}781return urlName != null && !urlName.isEmpty() ? urlName.get(0) : "";782}783784// ---------------------- LdapContext ---------------------785786public ExtendedResponse extendedOperation(ExtendedRequest request)787throws NamingException {788789if (skipThisReferral) {790throw (NamingException)791((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());792}793794if (!(refCtx instanceof LdapContext)) {795throw new NotContextException(796"Referral context not an instance of LdapContext");797}798799return ((LdapContext)refCtx).extendedOperation(request);800}801802public LdapContext newInstance(Control[] requestControls)803throws NamingException {804805if (skipThisReferral) {806throw (NamingException)807((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());808}809810if (!(refCtx instanceof LdapContext)) {811throw new NotContextException(812"Referral context not an instance of LdapContext");813}814815return ((LdapContext)refCtx).newInstance(requestControls);816}817818public void reconnect(Control[] connCtls) throws NamingException {819if (skipThisReferral) {820throw (NamingException)821((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());822}823824if (!(refCtx instanceof LdapContext)) {825throw new NotContextException(826"Referral context not an instance of LdapContext");827}828829((LdapContext)refCtx).reconnect(connCtls);830}831832public Control[] getConnectControls() throws NamingException {833if (skipThisReferral) {834throw (NamingException)835((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());836}837838if (!(refCtx instanceof LdapContext)) {839throw new NotContextException(840"Referral context not an instance of LdapContext");841}842843return ((LdapContext)refCtx).getConnectControls();844}845846public void setRequestControls(Control[] requestControls)847throws NamingException {848849if (skipThisReferral) {850throw (NamingException)851((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());852}853854if (!(refCtx instanceof LdapContext)) {855throw new NotContextException(856"Referral context not an instance of LdapContext");857}858859((LdapContext)refCtx).setRequestControls(requestControls);860}861862public Control[] getRequestControls() throws NamingException {863if (skipThisReferral) {864throw (NamingException)865((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());866}867868if (!(refCtx instanceof LdapContext)) {869throw new NotContextException(870"Referral context not an instance of LdapContext");871}872return ((LdapContext)refCtx).getRequestControls();873}874875public Control[] getResponseControls() throws NamingException {876if (skipThisReferral) {877throw (NamingException)878((refEx.appendUnprocessedReferrals(null)).fillInStackTrace());879}880881if (!(refCtx instanceof LdapContext)) {882throw new NotContextException(883"Referral context not an instance of LdapContext");884}885return ((LdapContext)refCtx).getResponseControls();886}887888// ---------------------- Private methods ---------------------889private Name toName(String name) throws InvalidNameException {890return name.isEmpty() ? new CompositeName() :891new CompositeName().add(name);892}893894/*895* Use the DN component from the LDAP URL (if present) to override the896* supplied DN.897*/898private Name overrideName(Name name) throws InvalidNameException {899return (urlName == null ? name : urlName);900}901902/*903* Use the attributes and scope components from the LDAP URL (if present)904* to override the corresponding components supplied in SearchControls.905*/906private SearchControls overrideAttributesAndScope(SearchControls cons) {907SearchControls urlCons;908909if ((urlScope != null) || (urlAttrs != null)) {910urlCons = new SearchControls(cons.getSearchScope(),911cons.getCountLimit(),912cons.getTimeLimit(),913cons.getReturningAttributes(),914cons.getReturningObjFlag(),915cons.getDerefLinkFlag());916917if (urlScope != null) {918if (urlScope.equals("base")) {919urlCons.setSearchScope(SearchControls.OBJECT_SCOPE);920} else if (urlScope.equals("one")) {921urlCons.setSearchScope(SearchControls.ONELEVEL_SCOPE);922} else if (urlScope.equals("sub")) {923urlCons.setSearchScope(SearchControls.SUBTREE_SCOPE);924}925}926927if (urlAttrs != null) {928StringTokenizer tokens = new StringTokenizer(urlAttrs, ",");929int count = tokens.countTokens();930String[] attrs = new String[count];931for (int i = 0; i < count; i ++) {932attrs[i] = tokens.nextToken();933}934urlCons.setReturningAttributes(attrs);935}936937return urlCons;938939} else {940return cons;941}942}943944/*945* Use the filter component from the LDAP URL (if present) to override the946* supplied filter.947*/948private String overrideFilter(String filter) {949return (urlFilter == null ? filter : urlFilter);950}951952}953954955