ExtendedRequestProtocolOp.java revision 998747bfaaa3c6b28bbfaf0e282e6c0ccbf46bc0
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/*
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * CDDL HEADER START
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * The contents of this file are subject to the terms of the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Common Development and Distribution License, Version 1.0 only
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * (the "License"). You may not use this file except in compliance
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * with the License.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * or http://forgerock.org/license/CDDLv1.0.html.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * See the License for the specific language governing permissions
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * and limitations under the License.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * When distributing Covered Code, include this CDDL HEADER in each
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * file and include the License file at legal-notices/CDDLv1_0.txt.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * If applicable, add the following below this CDDL HEADER, with the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * fields enclosed by brackets "[]" replaced with your own identifying
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * information:
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Portions Copyright [yyyy] [name of copyright owner]
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * CDDL HEADER END
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Copyright 2006-2008 Sun Microsystems, Inc.
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk * Portions Copyright 2014-2015 ForgeRock AS
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkpackage org.opends.server.protocols.ldap;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport java.io.IOException;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.forgerock.opendj.io.*;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.forgerock.opendj.ldap.ByteString;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport org.forgerock.i18n.slf4j.LocalizedLogger;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport static org.opends.server.protocols.ldap.LDAPConstants.*;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkimport static org.opends.server.util.ServerConstants.*;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk/**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * This class defines the structures and methods for an LDAP extended request
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * protocol op, which is used to request some special type of processing defined
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * in an extension to the LDAP protocol.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenkpublic class ExtendedRequestProtocolOp
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk extends ProtocolOp
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk{
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // The value for this extended request.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private ByteString value;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk // The OID for this extended request.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk private String oid;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Creates a new extended request protocol op with the specified OID and no
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * value.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param oid The OID for this extended request.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public ExtendedRequestProtocolOp(String oid)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk this.oid = oid;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk this.value = null;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Creates a new extended request protocol op with the specified OID and
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * value.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param oid The OID for this extended request.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param value The value for this extended request.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public ExtendedRequestProtocolOp(String oid, ByteString value)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk this.oid = oid;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk this.value = value;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Retrieves the OID for this extended request.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @return The OID for this extended request.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public String getOID()
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return oid;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Retrieves the value for this extended request.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @return The value for this extended request, or <CODE>null</CODE> if there
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * is no value.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public ByteString getValue()
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return value;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Retrieves the BER type for this protocol op.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @return The BER type for this protocol op.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public byte getType()
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return OP_TYPE_EXTENDED_REQUEST;
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk * Retrieves the name for this protocol op type.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @return The name for this protocol op type.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public String getProtocolOpName()
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk return "Extended Request";
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Writes this protocol op to an ASN.1 output stream.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param stream The ASN.1 output stream to write to.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @throws IOException If a problem occurs while writing to the stream.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public void write(ASN1Writer stream) throws IOException
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk stream.writeStartSequence(OP_TYPE_EXTENDED_REQUEST);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk stream.writeOctetString(TYPE_EXTENDED_REQUEST_OID, oid);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if(value != null)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk stream.writeOctetString(TYPE_EXTENDED_REQUEST_VALUE, value);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk stream.writeEndSequence();
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Appends a string representation of this LDAP protocol op to the provided
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * buffer.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param buffer The buffer to which the string should be appended.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public void toString(StringBuilder buffer)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append("ExtendedRequest(oid=");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(oid);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (value != null)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(", value=");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(value);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(")");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk /**
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * Appends a multi-line string representation of this LDAP protocol op to the
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * provided buffer.
dff2cc5646d4437ab9e0cb1dcb59da65462a5938jeff.schenk *
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param buffer The buffer to which the information should be appended.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * @param indent The number of spaces from the margin that the lines should
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk * be indented.
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk */
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk public void toString(StringBuilder buffer, int indent)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk StringBuilder indentBuf = new StringBuilder(indent);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk for (int i=0 ; i < indent; i++)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk indentBuf.append(' ');
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(indentBuf);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append("Extended Request");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(EOL);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(indentBuf);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(" OID: ");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(oid);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(EOL);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk if (value != null)
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk {
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(indentBuf);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(" Value:");
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(EOL);
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk buffer.append(value.toHexPlusAsciiString(indent+4));
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk }
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk}
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk
5b64d5d44892834ba97f003080f3467299b7c5c5jeff.schenk