Path: blob/master/src/java.naming/share/classes/javax/naming/ldap/ExtendedRequest.java
41159 views
/*1* Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.naming.ldap;2627import javax.naming.NamingException;2829/**30* This interface represents an LDAPv3 extended operation request as defined in31* <A HREF="http://www.ietf.org/rfc/rfc2251.txt">RFC 2251</A>.32* <pre>33* ExtendedRequest ::= [APPLICATION 23] SEQUENCE {34* requestName [0] LDAPOID,35* requestValue [1] OCTET STRING OPTIONAL }36* </pre>37* It comprises an object identifier string and an optional ASN.1 BER38* encoded value.39*<p>40* The methods in this class are used by the service provider to construct41* the bits to send to the LDAP server. Applications typically only deal with42* the classes that implement this interface, supplying them with43* any information required for a particular extended operation request.44* It would then pass such a class as an argument to the45* {@code LdapContext.extendedOperation()} method for performing the46* LDAPv3 extended operation.47*<p>48* For example, suppose the LDAP server supported a 'get time' extended operation.49* It would supply GetTimeRequest and GetTimeResponse classes:50*<blockquote><pre>51* public class GetTimeRequest implements ExtendedRequest {52* public GetTimeRequest() {... };53* public ExtendedResponse createExtendedResponse(String id,54* byte[] berValue, int offset, int length)55* throws NamingException {56* return new GetTimeResponse(id, berValue, offset, length);57* }58* ...59* }60* public class GetTimeResponse implements ExtendedResponse {61* long time;62* public GetTimeResponse(String id, byte[] berValue, int offset,63* int length) throws NamingException {64* time = ... // decode berValue to get time65* }66* public java.util.Date getDate() { return new java.util.Date(time) };67* public long getTime() { return time };68* ...69* }70*</pre></blockquote>71* A program would use then these classes as follows:72*<blockquote><pre>73* GetTimeResponse resp =74* (GetTimeResponse) ectx.extendedOperation(new GetTimeRequest());75* long time = resp.getTime();76*</pre></blockquote>77*78* @author Rosanna Lee79* @author Scott Seligman80* @author Vincent Ryan81*82* @see ExtendedResponse83* @see LdapContext#extendedOperation84* @since 1.385*/86public interface ExtendedRequest extends java.io.Serializable {8788/**89* Retrieves the object identifier of the request.90*91* @return The non-null object identifier string representing the LDAP92* {@code ExtendedRequest.requestName} component.93*/94public String getID();9596/**97* Retrieves the ASN.1 BER encoded value of the LDAP extended operation98* request. Null is returned if the value is absent.99*100* The result is the raw BER bytes including the tag and length of101* the request value. It does not include the request OID.102* This method is called by the service provider to get the bits to103* put into the extended operation to be sent to the LDAP server.104*105* @return A possibly null byte array representing the ASN.1 BER encoded106* contents of the LDAP {@code ExtendedRequest.requestValue}107* component.108* @throws IllegalStateException If the encoded value cannot be retrieved109* because the request contains insufficient or invalid data/state.110*/111public byte[] getEncodedValue();112113/**114* Creates the response object that corresponds to this request.115*<p>116* After the service provider has sent the extended operation request117* to the LDAP server, it will receive a response from the server.118* If the operation failed, the provider will throw a NamingException.119* If the operation succeeded, the provider will invoke this method120* using the data that it got back in the response.121* It is the job of this method to return a class that implements122* the ExtendedResponse interface that is appropriate for the123* extended operation request.124*<p>125* For example, a Start TLS extended request class would need to know126* how to process a Start TLS extended response. It does this by creating127* a class that implements ExtendedResponse.128*129* @param id The possibly null object identifier of the response130* control.131* @param berValue The possibly null ASN.1 BER encoded value of the132* response control.133* This is the raw BER bytes including the tag and length of134* the response value. It does not include the response OID.135* @param offset The starting position in berValue of the bytes to use.136* @param length The number of bytes in berValue to use.137*138* @return A non-null object.139* @throws NamingException if cannot create extended response140* due to an error.141* @see ExtendedResponse142*/143public ExtendedResponse createExtendedResponse(String id,144byte[] berValue, int offset, int length) throws NamingException;145146// static final long serialVersionUID = -7560110759229059814L;147}148149150