001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2008 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027package org.opends.server.protocols.ldap; 028 029 030import java.io.IOException; 031 032import org.forgerock.opendj.io.*; 033import org.forgerock.opendj.ldap.ByteString; 034 035import org.forgerock.i18n.slf4j.LocalizedLogger; 036import static org.opends.server.protocols.ldap.LDAPConstants.*; 037import static org.opends.server.util.ServerConstants.*; 038 039 040/** 041 * This class defines the structures and methods for an LDAP extended request 042 * protocol op, which is used to request some special type of processing defined 043 * in an extension to the LDAP protocol. 044 */ 045public class ExtendedRequestProtocolOp 046 extends ProtocolOp 047{ 048 private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); 049 050 /** The value for this extended request. */ 051 private ByteString value; 052 053 /** The OID for this extended request. */ 054 private String oid; 055 056 057 058 /** 059 * Creates a new extended request protocol op with the specified OID and no 060 * value. 061 * 062 * @param oid The OID for this extended request. 063 */ 064 public ExtendedRequestProtocolOp(String oid) 065 { 066 this.oid = oid; 067 this.value = null; 068 } 069 070 071 072 /** 073 * Creates a new extended request protocol op with the specified OID and 074 * value. 075 * 076 * @param oid The OID for this extended request. 077 * @param value The value for this extended request. 078 */ 079 public ExtendedRequestProtocolOp(String oid, ByteString value) 080 { 081 this.oid = oid; 082 this.value = value; 083 } 084 085 086 087 /** 088 * Retrieves the OID for this extended request. 089 * 090 * @return The OID for this extended request. 091 */ 092 public String getOID() 093 { 094 return oid; 095 } 096 097 098 /** 099 * Retrieves the value for this extended request. 100 * 101 * @return The value for this extended request, or <CODE>null</CODE> if there 102 * is no value. 103 */ 104 public ByteString getValue() 105 { 106 return value; 107 } 108 109 110 111 /** 112 * Retrieves the BER type for this protocol op. 113 * 114 * @return The BER type for this protocol op. 115 */ 116 public byte getType() 117 { 118 return OP_TYPE_EXTENDED_REQUEST; 119 } 120 121 122 123 /** 124 * Retrieves the name for this protocol op type. 125 * 126 * @return The name for this protocol op type. 127 */ 128 public String getProtocolOpName() 129 { 130 return "Extended Request"; 131 } 132 133 /** 134 * Writes this protocol op to an ASN.1 output stream. 135 * 136 * @param stream The ASN.1 output stream to write to. 137 * @throws IOException If a problem occurs while writing to the stream. 138 */ 139 public void write(ASN1Writer stream) throws IOException 140 { 141 stream.writeStartSequence(OP_TYPE_EXTENDED_REQUEST); 142 stream.writeOctetString(TYPE_EXTENDED_REQUEST_OID, oid); 143 144 if(value != null) 145 { 146 stream.writeOctetString(TYPE_EXTENDED_REQUEST_VALUE, value); 147 } 148 149 stream.writeEndSequence(); 150 } 151 152 153 154 /** 155 * Appends a string representation of this LDAP protocol op to the provided 156 * buffer. 157 * 158 * @param buffer The buffer to which the string should be appended. 159 */ 160 public void toString(StringBuilder buffer) 161 { 162 buffer.append("ExtendedRequest(oid="); 163 buffer.append(oid); 164 165 if (value != null) 166 { 167 buffer.append(", value="); 168 buffer.append(value); 169 } 170 171 buffer.append(")"); 172 } 173 174 175 176 /** 177 * Appends a multi-line string representation of this LDAP protocol op to the 178 * provided buffer. 179 * 180 * @param buffer The buffer to which the information should be appended. 181 * @param indent The number of spaces from the margin that the lines should 182 * be indented. 183 */ 184 public void toString(StringBuilder buffer, int indent) 185 { 186 StringBuilder indentBuf = new StringBuilder(indent); 187 for (int i=0 ; i < indent; i++) 188 { 189 indentBuf.append(' '); 190 } 191 192 buffer.append(indentBuf); 193 buffer.append("Extended Request"); 194 buffer.append(EOL); 195 196 buffer.append(indentBuf); 197 buffer.append(" OID: "); 198 buffer.append(oid); 199 buffer.append(EOL); 200 201 if (value != null) 202 { 203 buffer.append(indentBuf); 204 buffer.append(" Value:"); 205 buffer.append(EOL); 206 buffer.append(value.toHexPlusAsciiString(indent+4)); 207 } 208 } 209} 210