src/java.naming/share/classes/javax/naming/ldap/SortResponseControl.java
author stefank
Mon, 25 Nov 2019 15:00:32 +0100
changeset 59255 a74627659f96
parent 47216 71c04702a3d5
permissions -rw-r--r--
8234602: ZGC: Windows compile error in ZHeuristic Reviewed-by: pliden, eosterlund
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) 2003, 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 javax.naming.ldap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
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 com.sun.jndi.ldap.Ber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.jndi.ldap.BerDecoder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import com.sun.jndi.ldap.LdapCtx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * Indicates whether the requested sort of search results was successful or not.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * When the result code indicates success then the results have been sorted as
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * requested. Otherwise the sort was unsuccessful and additional details
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * regarding the cause of the error may have been provided by the server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * The code sample in {@link SortControl} shows how this class may be used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This class implements the LDAPv3 Response Control for server-side sorting
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * as defined in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <a href="http://www.ietf.org/rfc/rfc2891.txt">RFC 2891</a>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * The control's value has the following ASN.1 definition:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *     SortResult ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *        sortResult  ENUMERATED {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *            success                   (0), -- results are sorted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *            operationsError           (1), -- server internal failure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 *            timeLimitExceeded         (3), -- timelimit reached before
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 *                                           -- sorting was completed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *            strongAuthRequired        (8), -- refused to return sorted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *                                           -- results via insecure
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *                                           -- protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *            adminLimitExceeded       (11), -- too many matching entries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *                                           -- for the server to sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *            noSuchAttribute          (16), -- unrecognized attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *                                           -- type in sort key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *            inappropriateMatching    (18), -- unrecognized or inappro-
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *                                           -- priate matching rule in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *                                           -- sort key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *            insufficientAccessRights (50), -- refused to return sorted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *                                           -- results to this client
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *            busy                     (51), -- too busy to process
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *            unwillingToPerform       (53), -- unable to sort
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *            other                    (80)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *            },
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *      attributeType [0] AttributeType OPTIONAL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * @see SortControl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * @author Vincent Ryan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
final public class SortResponseControl extends BasicControl {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * The server-side sort response control's assigned object identifier
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * is 1.2.840.113556.1.4.474.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static final String OID = "1.2.840.113556.1.4.474";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    private static final long serialVersionUID = 5142939176006310877L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * The sort result code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    private int resultCode = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * The ID of the attribute that caused the sort to fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    private String badAttrId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * Constructs a control to indicate the outcome of a sort request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @param   id              The control's object identifier string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @param   criticality     The control's criticality.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @param   value           The control's ASN.1 BER encoded value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     *                          It is not cloned - any changes to value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     *                          will affect the contents of the control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * @exception               IOException if an error is encountered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     *                          while decoding the control's value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    public SortResponseControl(String id, boolean criticality, byte[] value)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        super(id, criticality, value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // decode value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        BerDecoder ber = new BerDecoder(value, 0, value.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        ber.parseSeq(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        resultCode = ber.parseEnumeration();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        if ((ber.bytesLeft() > 0) && (ber.peekByte() == Ber.ASN_CONTEXT)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            badAttrId = ber.parseStringWithTag(Ber.ASN_CONTEXT, true, null);
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Determines if the search results have been successfully sorted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * If an error occurred during sorting a NamingException is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @return    true if the search results have been sorted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    public boolean isSorted() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        return (resultCode == 0); // a result code of zero indicates success
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * Retrieves the LDAP result code of the sort operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @return    The result code. A zero value indicates success.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public int getResultCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        return resultCode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * Retrieves the ID of the attribute that caused the sort to fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Returns null if no ID was returned by the server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return The possibly null ID of the bad attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    public String getAttributeID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        return badAttrId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Retrieves the NamingException appropriate for the result code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return A NamingException or null if the result code indicates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *         success.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    public NamingException getException() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        return LdapCtx.mapErrorCode(resultCode, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
}