jdk/src/share/classes/com/sun/jndi/url/ldap/ldapURLContext.java
author prappo
Fri, 01 Aug 2014 22:32:51 +0100
changeset 25808 e113d0a0fde0
parent 10324 e28265130e4f
permissions -rw-r--r--
8054158: Fix typos in JNDI-related packages Reviewed-by: rriggs, vinnie
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package com.sun.jndi.url.ldap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.naming.spi.ResolveResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.naming.directory.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.jndi.ldap.LdapURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * An LDAP URL context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
final public class ldapURLContext
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        extends com.sun.jndi.toolkit.url.GenericURLDirContext {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    45
    ldapURLContext(Hashtable<?,?> env) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        super(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
      * Resolves 'name' into a target context with remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
      * It only resolves the hostname/port number. The remaining name
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
      * contains the root DN.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
      * For example, with a LDAP URL "ldap://localhost:389/o=widget,c=us",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
      * this method resolves "ldap://localhost:389/" to the root LDAP
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
      * context on the server 'localhost' on port 389,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
      * and returns as the remaining name "o=widget, c=us".
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
      */
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    59
    protected ResolveResult getRootURLContext(String name, Hashtable<?,?> env)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        return ldapURLContextFactory.getUsingURLIgnoreRootDN(name, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Return the suffix of an ldap url.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * prefix parameter is ignored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    protected Name getURLSuffix(String prefix, String url)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        LdapURL ldapUrl = new LdapURL(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        String dn = (ldapUrl.getDN() != null? ldapUrl.getDN() : "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        // Represent DN as empty or single-component composite name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        CompositeName remaining = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        if (!"".equals(dn)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            // if nonempty, add component
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            remaining.add(dn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return remaining;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * Override context operations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * Test for presence of LDAP URL query components in the name argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * Query components are permitted only for search operations and only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * when the name has a single component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    public Object lookup(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            return super.lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    public Object lookup(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            return super.lookup(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
    public void bind(String name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            super.bind(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void bind(Name name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            super.bind(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public void rebind(String name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            super.rebind(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    public void rebind(Name name, Object obj) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            super.rebind(name, obj);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    public void unbind(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            super.unbind(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public void unbind(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            super.unbind(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public void rename(String oldName, String newName) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        if (LdapURL.hasQueryComponents(oldName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            throw new InvalidNameException(oldName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        } else if (LdapURL.hasQueryComponents(newName)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            throw new InvalidNameException(newName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            super.rename(oldName, newName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public void rename(Name oldName, Name newName) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (LdapURL.hasQueryComponents(oldName.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            throw new InvalidNameException(oldName.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        } else if (LdapURL.hasQueryComponents(newName.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            throw new InvalidNameException(newName.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            super.rename(oldName, newName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   174
    public NamingEnumeration<NameClassPair> list(String name)
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   175
            throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return super.list(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   183
    public NamingEnumeration<NameClassPair> list(Name name)
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   184
            throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return super.list(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   192
    public NamingEnumeration<Binding> listBindings(String name)
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   193
            throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            return super.listBindings(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   201
    public NamingEnumeration<Binding> listBindings(Name name)
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   202
            throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            return super.listBindings(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    public void destroySubcontext(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            super.destroySubcontext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public void destroySubcontext(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            super.destroySubcontext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public Context createSubcontext(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            return super.createSubcontext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public Context createSubcontext(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return super.createSubcontext(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public Object lookupLink(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            return super.lookupLink(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    public Object lookupLink(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            return super.lookupLink(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    public NameParser getNameParser(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            return super.getNameParser(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    public NameParser getNameParser(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            return super.getNameParser(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    public String composeName(String name, String prefix)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        } else if (LdapURL.hasQueryComponents(prefix)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            throw new InvalidNameException(prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            return super.composeName(name, prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public Name composeName(Name name, Name prefix) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        } else if (LdapURL.hasQueryComponents(prefix.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            throw new InvalidNameException(prefix.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return super.composeName(name, prefix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
    public Attributes getAttributes(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            return super.getAttributes(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    public Attributes getAttributes(Name name) throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            return super.getAttributes(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public Attributes getAttributes(String name, String[] attrIds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            return super.getAttributes(name, attrIds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
    public Attributes getAttributes(Name name, String[] attrIds)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            return super.getAttributes(name, attrIds);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    public void modifyAttributes(String name, int mod_op, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            super.modifyAttributes(name, mod_op, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    public void modifyAttributes(Name name, int mod_op, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            super.modifyAttributes(name, mod_op, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
    public void modifyAttributes(String name, ModificationItem[] mods)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            super.modifyAttributes(name, mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    public void modifyAttributes(Name name, ModificationItem[] mods)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        throws NamingException  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            super.modifyAttributes(name, mods);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
    public void bind(String name, Object obj, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            super.bind(name, obj, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public void bind(Name name, Object obj, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            super.bind(name, obj, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public void rebind(String name, Object obj, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
            super.rebind(name, obj, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public void rebind(Name name, Object obj, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            super.rebind(name, obj, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    public DirContext createSubcontext(String name, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            return super.createSubcontext(name, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    public DirContext createSubcontext(Name name, Attributes attrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            return super.createSubcontext(name, attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    public DirContext getSchema(String name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            return super.getSchema(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    public DirContext getSchema(Name name) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            return super.getSchema(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    public DirContext getSchemaClassDefinition(String name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            throw new InvalidNameException(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
            return super.getSchemaClassDefinition(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public DirContext getSchemaClassDefinition(Name name)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
            return super.getSchemaClassDefinition(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    // divert the search operation when the LDAP URL has query components
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   454
    public NamingEnumeration<SearchResult> search(String name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        Attributes matchingAttributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            return searchUsingURL(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            return super.search(name, matchingAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    // divert the search operation when name has a single component
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   466
    public NamingEnumeration<SearchResult> search(Name name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        Attributes matchingAttributes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            return search(name.get(0), matchingAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
        } else if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            return super.search(name, matchingAttributes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    // divert the search operation when the LDAP URL has query components
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   479
    public NamingEnumeration<SearchResult> search(String name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        Attributes matchingAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        String[] attributesToReturn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            return searchUsingURL(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            return super.search(name, matchingAttributes, attributesToReturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    // divert the search operation when name has a single component
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   492
    public NamingEnumeration<SearchResult> search(Name name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        Attributes matchingAttributes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        String[] attributesToReturn)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            return search(name.get(0), matchingAttributes, attributesToReturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        } else if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            return super.search(name, matchingAttributes, attributesToReturn);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    // divert the search operation when the LDAP URL has query components
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   507
    public NamingEnumeration<SearchResult> search(String name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        String filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        SearchControls cons)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            return searchUsingURL(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            return super.search(name, filter, cons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    // divert the search operation when name has a single component
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   520
    public NamingEnumeration<SearchResult> search(Name name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        String filter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        SearchControls cons)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            return search(name.get(0), filter, cons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
        } else if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            return super.search(name, filter, cons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    // divert the search operation when the LDAP URL has query components
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   535
    public NamingEnumeration<SearchResult> search(String name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        String filterExpr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        Object[] filterArgs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        SearchControls cons)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
        if (LdapURL.hasQueryComponents(name)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
            return searchUsingURL(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            return super.search(name, filterExpr, filterArgs, cons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    // divert the search operation when name has a single component
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   549
    public NamingEnumeration<SearchResult> search(Name name,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
        String filterExpr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        Object[] filterArgs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        SearchControls cons)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        if (name.size() == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            return search(name.get(0), filterExpr, filterArgs, cons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        } else if (LdapURL.hasQueryComponents(name.get(0))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
            throw new InvalidNameException(name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            return super.search(name, filterExpr, filterArgs, cons);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
    // Search using the LDAP URL in name.
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 10324
diff changeset
   565
    // LDAP URL query components override the search arguments.
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   566
    private NamingEnumeration<SearchResult> searchUsingURL(String name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
        LdapURL url = new LdapURL(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        ResolveResult res = getRootURLContext(name, myEnv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        DirContext ctx = (DirContext)res.getResolvedObj();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
            return ctx.search(res.getRemainingName(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                              setFilterUsingURL(url),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
                              setSearchControlsUsingURL(url));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
            ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
     * Initialize a String filter using the LDAP URL filter component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
     * If filter is not present in the URL it is initialized to its default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     * value as specified in RFC-2255.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    private static String setFilterUsingURL(LdapURL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
        String filter = url.getFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        if (filter == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            filter = "(objectClass=*)"; //default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        return filter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * Initialize a SearchControls object using LDAP URL query components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * Components not present in the URL are initialized to their default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * values as specified in RFC-2255.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    private static SearchControls setSearchControlsUsingURL(LdapURL url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
        SearchControls cons = new SearchControls();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        String scope = url.getScope();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
        String attributes = url.getAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        if (scope == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            cons.setSearchScope(SearchControls.OBJECT_SCOPE); //default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            if (scope.equals("sub")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                cons.setSearchScope(SearchControls.SUBTREE_SCOPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            } else if (scope.equals("one")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
                cons.setSearchScope(SearchControls.ONELEVEL_SCOPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
            } else if (scope.equals("base")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
                cons.setSearchScope(SearchControls.OBJECT_SCOPE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        if (attributes == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            cons.setReturningAttributes(null); //default value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            StringTokenizer tokens = new StringTokenizer(attributes, ",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            int count = tokens.countTokens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            String[] attrs = new String[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
            for (int i = 0; i < count; i ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                attrs[i] = tokens.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            cons.setReturningAttributes(attrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
        return cons;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
}