001/*
002 * Copyright 2016-2024 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2016-2024 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2016-2024 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.experimental;
037
038
039
040import com.unboundid.asn1.ASN1OctetString;
041import com.unboundid.ldap.protocol.ExtendedResponseProtocolOp;
042import com.unboundid.ldap.sdk.ExtendedRequest;
043import com.unboundid.ldap.sdk.Entry;
044import com.unboundid.ldap.sdk.LDAPException;
045import com.unboundid.ldap.sdk.OperationType;
046import com.unboundid.ldap.sdk.ResultCode;
047import com.unboundid.util.NotMutable;
048import com.unboundid.util.NotNull;
049import com.unboundid.util.Nullable;
050import com.unboundid.util.StaticUtils;
051import com.unboundid.util.ThreadSafety;
052import com.unboundid.util.ThreadSafetyLevel;
053
054import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*;
055
056
057
058/**
059 * This class represents an entry that holds information about an extended
060 * operation processed by an LDAP server, as per the specification described in
061 * draft-chu-ldap-logschema-00.
062 */
063@NotMutable()
064@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
065public final class DraftChuLDAPLogSchema00ExtendedEntry
066       extends DraftChuLDAPLogSchema00Entry
067{
068  /**
069   * The name of the attribute used to hold the extended request value.
070   */
071  @NotNull public static final String ATTR_REQUEST_VALUE = "reqData";
072
073
074
075  /**
076   * The serial version UID for this serializable class.
077   */
078  private static final long serialVersionUID = 3767074068423424660L;
079
080
081
082  // The request value, if available.
083  @Nullable private final ASN1OctetString requestValue;
084
085  // The request OID.
086  @NotNull private final String requestOID;
087
088
089
090  /**
091   * Creates a new instance of this extended operation access log entry from the
092   * provided entry.
093   *
094   * @param  entry  The entry used to create this extended operation access log
095   *                entry.
096   *
097   * @throws  LDAPException  If the provided entry cannot be decoded as a valid
098   *                         extended operation access log entry as per the
099   *                         specification contained in
100   *                         draft-chu-ldap-logschema-00.
101   */
102  public DraftChuLDAPLogSchema00ExtendedEntry(@NotNull final Entry entry)
103         throws LDAPException
104  {
105    super(entry, OperationType.EXTENDED);
106
107
108    // The request OID is encoded in the request type.
109    final String requestType = entry.getAttributeValue(ATTR_OPERATION_TYPE);
110    final String lowerRequestType = StaticUtils.toLowerCase(requestType);
111    if (lowerRequestType.startsWith("extended") &&
112        (lowerRequestType.length() > 8))
113    {
114      requestOID = requestType.substring(8);
115    }
116    else
117    {
118      throw new LDAPException(ResultCode.DECODING_ERROR,
119           ERR_LOGSCHEMA_DECODE_EXTENDED_MALFORMED_REQ_TYPE.get(entry.getDN(),
120                ATTR_OPERATION_TYPE, requestType));
121    }
122
123
124    // Get the request value, if present.
125    final byte[] requestValueBytes =
126         entry.getAttributeValueBytes(ATTR_REQUEST_VALUE);
127    if (requestValueBytes == null)
128    {
129      requestValue = null;
130    }
131    else
132    {
133      requestValue = new ASN1OctetString(
134           ExtendedResponseProtocolOp.TYPE_RESPONSE_VALUE, requestValueBytes);
135    }
136  }
137
138
139
140  /**
141   * Retrieves the request OID for the extended request described by this
142   * extended operation access log entry.
143   *
144   * @return  The request OID for the extended request described by this
145   *          extended operation access log entry.
146   */
147  @NotNull()
148  public String getRequestOID()
149  {
150    return requestOID;
151  }
152
153
154
155  /**
156   * Retrieves the request value for the extended request described by this
157   * extended operation access log entry, if any.
158   *
159   * @return  The request value for the extended request described by this
160   *          extended operation access log entry, or {@code null} if no request
161   *          value was included in the access log entry.
162   */
163  @Nullable()
164  public ASN1OctetString getRequestValue()
165  {
166    return requestValue;
167  }
168
169
170
171  /**
172   * Retrieves an {@code ExtendedRequest} created from this extended operation
173   * access log entry.
174   *
175   * @return  The {@code ExtendedRequest} created from this extended operation
176   *          access log entry.
177   */
178  @NotNull()
179  public ExtendedRequest toExtendedRequest()
180  {
181    return new ExtendedRequest(requestOID, requestValue,
182         getRequestControlArray());
183  }
184}