001/* 002 * Copyright 2016-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2016-2020 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-2020 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.StaticUtils; 049import com.unboundid.util.ThreadSafety; 050import com.unboundid.util.ThreadSafetyLevel; 051 052import static com.unboundid.ldap.sdk.experimental.ExperimentalMessages.*; 053 054 055 056/** 057 * This class represents an entry that holds information about an extended 058 * operation processed by an LDAP server, as per the specification described in 059 * draft-chu-ldap-logschema-00. 060 */ 061@NotMutable() 062@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 063public final class DraftChuLDAPLogSchema00ExtendedEntry 064 extends DraftChuLDAPLogSchema00Entry 065{ 066 /** 067 * The name of the attribute used to hold the extended request value. 068 */ 069 public static final String ATTR_REQUEST_VALUE = "reqData"; 070 071 072 073 /** 074 * The serial version UID for this serializable class. 075 */ 076 private static final long serialVersionUID = 3767074068423424660L; 077 078 079 080 // The request value, if available. 081 private final ASN1OctetString requestValue; 082 083 // The request OID. 084 private final String requestOID; 085 086 087 088 /** 089 * Creates a new instance of this extended operation access log entry from the 090 * provided entry. 091 * 092 * @param entry The entry used to create this extended operation access log 093 * entry. 094 * 095 * @throws LDAPException If the provided entry cannot be decoded as a valid 096 * extended operation access log entry as per the 097 * specification contained in 098 * draft-chu-ldap-logschema-00. 099 */ 100 public DraftChuLDAPLogSchema00ExtendedEntry(final Entry entry) 101 throws LDAPException 102 { 103 super(entry, OperationType.EXTENDED); 104 105 106 // The request OID is encoded in the request type. 107 final String requestType = entry.getAttributeValue(ATTR_OPERATION_TYPE); 108 final String lowerRequestType = StaticUtils.toLowerCase(requestType); 109 if (lowerRequestType.startsWith("extended") && 110 (lowerRequestType.length() > 8)) 111 { 112 requestOID = requestType.substring(8); 113 } 114 else 115 { 116 throw new LDAPException(ResultCode.DECODING_ERROR, 117 ERR_LOGSCHEMA_DECODE_EXTENDED_MALFORMED_REQ_TYPE.get(entry.getDN(), 118 ATTR_OPERATION_TYPE, requestType)); 119 } 120 121 122 // Get the request value, if present. 123 final byte[] requestValueBytes = 124 entry.getAttributeValueBytes(ATTR_REQUEST_VALUE); 125 if (requestValueBytes == null) 126 { 127 requestValue = null; 128 } 129 else 130 { 131 requestValue = new ASN1OctetString( 132 ExtendedResponseProtocolOp.TYPE_RESPONSE_VALUE, requestValueBytes); 133 } 134 } 135 136 137 138 /** 139 * Retrieves the request OID for the extended request described by this 140 * extended operation access log entry. 141 * 142 * @return The request OID for the extended request described by this 143 * extended operation access log entry. 144 */ 145 public String getRequestOID() 146 { 147 return requestOID; 148 } 149 150 151 152 /** 153 * Retrieves the request value for the extended request described by this 154 * extended operation access log entry, if any. 155 * 156 * @return The request value for the extended request described by this 157 * extended operation access log entry, or {@code null} if no request 158 * value was included in the access log entry. 159 */ 160 public ASN1OctetString getRequestValue() 161 { 162 return requestValue; 163 } 164 165 166 167 /** 168 * Retrieves an {@code ExtendedRequest} created from this extended operation 169 * access log entry. 170 * 171 * @return The {@code ExtendedRequest} created from this extended operation 172 * access log entry. 173 */ 174 public ExtendedRequest toExtendedRequest() 175 { 176 return new ExtendedRequest(requestOID, requestValue, 177 getRequestControlArray()); 178 } 179}