src/java.naming/share/classes/com/sun/jndi/ldap/LdapURL.java
author rriggs
Fri, 07 Dec 2018 11:51:17 -0500
changeset 52902 e3398b2e1ab0
parent 47216 71c04702a3d5
permissions -rw-r--r--
8214971: Replace use of string.equals("") with isEmpty() Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2002, 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.ldap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.UnsupportedEncodingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.jndi.toolkit.url.Uri;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.jndi.toolkit.url.UrlUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Extract components of an LDAP URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * The format of an LDAP URL is defined in RFC 2255 as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *     ldapurl    = scheme "://" [hostport] ["/"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *                  [dn ["?" [attributes] ["?" [scope]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *                  ["?" [filter] ["?" extensions]]]]]]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *     scheme     = "ldap"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *     attributes = attrdesc *("," attrdesc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *     scope      = "base" / "one" / "sub"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *     dn         = distinguishedName from Section 3 of [1]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *     hostport   = hostport from Section 5 of RFC 1738 [5]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *     attrdesc   = AttributeDescription from Section 4.1.5 of [2]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *     filter     = filter from Section 4 of [4]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *     extensions = extension *("," extension)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *     extension  = ["!"] extype ["=" exvalue]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *     extype     = token / xtoken
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *     exvalue    = LDAPString from section 4.1.2 of [2]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *     token      = oid from section 4.1 of [3]
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *     xtoken     = ("X-" / "x-") token
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * For example,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *     ldap://ldap.itd.umich.edu/o=University%20of%20Michigan,c=US
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *     ldap://host.com:6666/o=IMC,c=US??sub?(cn=Babs%20Jensen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * This class also supports ldaps URLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
final public class LdapURL extends Uri {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private boolean useSsl = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private String DN = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private String attributes = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    private String scope = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    private String filter = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    private String extensions = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * Creates an LdapURL object from an LDAP URL string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public LdapURL(String url) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            init(url); // scheme, host, port, path, query
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            useSsl = scheme.equalsIgnoreCase("ldaps");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            if (! (scheme.equalsIgnoreCase("ldap") || useSsl)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                throw new MalformedURLException("Not an LDAP URL: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            parsePathAndQuery(); // DN, attributes, scope, filter, extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            NamingException ne = new NamingException("Cannot parse url: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        } catch (UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            NamingException ne = new NamingException("Cannot parse url: " + url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
            ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
            throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Returns true if the URL is an LDAPS URL.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    public boolean useSsl() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return useSsl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Returns the LDAP URL's distinguished name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public String getDN() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        return DN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * Returns the LDAP URL's attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public String getAttributes() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        return attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * Returns the LDAP URL's scope.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public String getScope() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        return scope;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Returns the LDAP URL's filter.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    public String getFilter() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        return filter;
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
     * Returns the LDAP URL's extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public String getExtensions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        return extensions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * Given a space-separated list of LDAP URLs, returns an array of strings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    public static String[] fromList(String urlList) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        String[] urls = new String[(urlList.length() + 1) / 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        int i = 0;              // next available index in urls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        StringTokenizer st = new StringTokenizer(urlList, " ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            urls[i++] = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        String[] trimmed = new String[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        System.arraycopy(urls, 0, trimmed, 0, i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        return trimmed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    /**
25808
e113d0a0fde0 8054158: Fix typos in JNDI-related packages
prappo
parents: 5506
diff changeset
   162
     * Determines whether an LDAP URL has query components.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public static boolean hasQueryComponents(String url) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return (url.lastIndexOf('?') != -1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Assembles an LDAP or LDAPS URL string from its components.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * If "host" is an IPv6 literal, it may optionally include delimiting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * brackets.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    static String toUrlString(String host, int port, String dn, boolean useSsl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            String h = (host != null) ? host : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            if ((h.indexOf(':') != -1) && (h.charAt(0) != '[')) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                h = "[" + h + "]";          // IPv6 literal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            String p = (port != -1) ? (":" + port) : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            String d = (dn != null) ? ("/" + UrlUtil.encode(dn, "UTF8")) : "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            return useSsl ? "ldaps://" + h + p + d : "ldap://" + h + p + d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        } catch (UnsupportedEncodingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            // UTF8 should always be supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            throw new IllegalStateException("UTF-8 encoding unavailable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Parses the path and query components of an URL and sets this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * object's fields accordingly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    private void parsePathAndQuery() throws MalformedURLException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        UnsupportedEncodingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // path begins with a '/' or is empty
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   200
        if (path.isEmpty()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        DN = path.startsWith("/") ? path.substring(1) : path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (DN.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            DN = UrlUtil.decode(DN, "UTF8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        // query begins with a '?' or is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
29987
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   211
        if (query == null || query.length() < 2) {
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   212
            return;
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   213
        }
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   214
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   215
        int currentIndex = 1;
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   216
        int nextQmark;
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   217
        int endIndex;
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   218
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   219
        // attributes:
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   220
        nextQmark = query.indexOf('?', currentIndex);
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   221
        endIndex = nextQmark == -1 ? query.length() : nextQmark;
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   222
        if (endIndex - currentIndex > 0) {
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   223
            attributes = query.substring(currentIndex, endIndex);
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   224
        }
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   225
        currentIndex = endIndex + 1;
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   226
        if (currentIndex >= query.length()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
29987
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   230
        // scope:
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   231
        nextQmark = query.indexOf('?', currentIndex);
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   232
        endIndex = nextQmark == -1 ? query.length() : nextQmark;
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   233
        if (endIndex - currentIndex > 0) {
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   234
            scope = query.substring(currentIndex, endIndex);
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   235
        }
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   236
        currentIndex = endIndex + 1;
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   237
        if (currentIndex >= query.length()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
29987
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   241
        // filter:
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   242
        nextQmark = query.indexOf('?', currentIndex);
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   243
        endIndex = nextQmark == -1 ? query.length() : nextQmark;
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   244
        if (endIndex - currentIndex > 0) {
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   245
            filter = query.substring(currentIndex, endIndex);
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   246
            filter = UrlUtil.decode(filter, "UTF8");
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   247
        }
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   248
        currentIndex = endIndex + 1;
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   249
        if (currentIndex >= query.length()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
29987
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   253
        // extensions:
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   254
        if (query.length() - currentIndex > 0) {
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   255
            extensions = query.substring(currentIndex);
e4436690c5e6 8074761: Empty optional parameters of LDAP query are not interpreted as empty
omajid
parents: 25859
diff changeset
   256
            extensions = UrlUtil.decode(extensions, "UTF8");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        LdapURL url = new LdapURL(args[0]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        System.out.println("Example LDAP URL: " + url.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        System.out.println("  scheme: " + url.getScheme());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        System.out.println("    host: " + url.getHost());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        System.out.println("    port: " + url.getPort());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        System.out.println("      DN: " + url.getDN());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        System.out.println("   attrs: " + url.getAttributes());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        System.out.println("   scope: " + url.getScope());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        System.out.println("  filter: " + url.getFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        System.out.println("  extens: " + url.getExtensions());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        System.out.println("");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
*/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
}