| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
| 2 | * |
| 3 | * ***** BEGIN LICENSE BLOCK ***** |
| 4 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 |
| 5 | * |
| 6 | * The contents of this file are subject to the Mozilla Public License Version |
| 7 | * 1.1 (the "License"); you may not use this file except in compliance with |
| 8 | * the License. You may obtain a copy of the License at |
| 9 | * http://www.mozilla.org/MPL/ |
| 10 | * |
| 11 | * Software distributed under the License is distributed on an "AS IS" basis, |
| 12 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 | * for the specific language governing rights and limitations under the |
| 14 | * License. |
| 15 | * |
| 16 | * The Original Code is mozilla.org code. |
| 17 | * |
| 18 | * The Initial Developer of the Original Code is |
| 19 | * Netscape Communications Corporation. |
| 20 | * Portions created by the Initial Developer are Copyright (C) 1999 |
| 21 | * the Initial Developer. All Rights Reserved. |
| 22 | * |
| 23 | * Contributor(s): |
| 24 | * |
| 25 | * Alternatively, the contents of this file may be used under the terms of |
| 26 | * either the GNU General Public License Version 2 or later (the "GPL"), or |
| 27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), |
| 28 | * in which case the provisions of the GPL or the LGPL are applicable instead |
| 29 | * of those above. If you wish to allow use of your version of this file only |
| 30 | * under the terms of either the GPL or the LGPL, and not to allow others to |
| 31 | * use your version of this file under the terms of the MPL, indicate your |
| 32 | * decision by deleting the provisions above and replace them with the notice |
| 33 | * and other provisions required by the GPL or the LGPL. If you do not delete |
| 34 | * the provisions above, a recipient may use your version of this file under |
| 35 | * the terms of any one of the MPL, the GPL or the LGPL. |
| 36 | * |
| 37 | * ***** END LICENSE BLOCK ***** */ |
| 38 | package org.ietf.ldap; |
| 39 | |
| 40 | import java.io.Serializable; |
| 41 | |
| 42 | /** |
| 43 | * Version 3 of the LDAP protocol include the means to define additional |
| 44 | * operations ("extended operations") beyond the standard LDAP |
| 45 | * operations. An LDAP v3 client can send an extended operation request, |
| 46 | * identifying the operation by its unique object ID (OID). The server |
| 47 | * receives the request and if OID corresponds to an operation supported |
| 48 | * by the server, the server procoess the request and sends an extended |
| 49 | * operation response back to the client. |
| 50 | * <P> |
| 51 | * |
| 52 | * Objects of this class can be used to represent extended operation |
| 53 | * requests (sent by your client) or extended operation responses |
| 54 | * (returned by an LDAP v3 server). |
| 55 | * <P> |
| 56 | * |
| 57 | * To determine which extended operations are supported by a server, |
| 58 | * you need to search for the root DSE (DSA-specific entry, where DSA is |
| 59 | * another term for "LDAP server") and find the values of the |
| 60 | * <CODE>supportedExtension</CODE> attribute. This attribute contains the |
| 61 | * object IDs (OIDs) of the extended operations supported by this server. |
| 62 | * <P> |
| 63 | * |
| 64 | * The following section of code demonstrates how to get the list |
| 65 | * of the extended operations supported by an LDAP server. |
| 66 | * <P> |
| 67 | * |
| 68 | * <PRE> |
| 69 | * public static void main( String[] args ) |
| 70 | * { |
| 71 | * LDAPConnection ld = new LDAPConnection(); |
| 72 | * try { |
| 73 | * String MY_HOST = "localhost"; |
| 74 | * int MY_PORT = 389; |
| 75 | * ld.connect( MY_HOST, MY_PORT ); |
| 76 | * try { |
| 77 | * ld.authenticate( 3, "cn=Directory Manager", "23skidoo" ); |
| 78 | * } catch( LDAPException e ) { |
| 79 | * System.out.println( "LDAP server does not support v3." ); |
| 80 | * ld.disconnect(); |
| 81 | * System.exit(1); |
| 82 | * } |
| 83 | * |
| 84 | * String MY_FILT = "(objectclass=*)"; |
| 85 | * String MY_BASE = ""; |
| 86 | * String getAttrs[] = { "supportedExtension" }; |
| 87 | * LDAPSearchResults res = ld.search( MY_BASE, |
| 88 | * LDAPConnection.SCOPE_BASE, MY_FILT, getAttrs, false ); |
| 89 | * |
| 90 | * while ( res.hasMoreElements() ) { |
| 91 | * LDAPEntry findEntry = (LDAPEntry)res.nextElement(); |
| 92 | * LDAPAttributeSet findAttrs = findEntry.getAttributeSet(); |
| 93 | * Enumeration enumAttrs = findAttrs.getAttributes(); |
| 94 | * |
| 95 | * while ( enumAttrs.hasMoreElements() ) { |
| 96 | * LDAPAttribute anAttr = (LDAPAttribute)enumAttrs.nextElement(); |
| 97 | * String attrName = anAttr.getName(); |
| 98 | * System.out.println( attrName ); |
| 99 | * Enumeration enumVals = anAttr.getStringValues(); |
| 100 | * |
| 101 | * while ( enumVals.hasMoreElements() ) { |
| 102 | * String aVal = ( String )enumVals.nextElement(); |
| 103 | * System.out.println( "\t" + aVal ); |
| 104 | * } |
| 105 | * } |
| 106 | * } |
| 107 | * } |
| 108 | * catch( LDAPException e ) { |
| 109 | * System.out.println( "Error: " + e.toString() ); |
| 110 | * } |
| 111 | * try { |
| 112 | * ld.disconnect(); |
| 113 | * } |
| 114 | * catch( LDAPException e ) { |
| 115 | * System.exit(1); |
| 116 | * } |
| 117 | * System.exit(0); |
| 118 | * } |
| 119 | * </PRE> |
| 120 | * <P> |
| 121 | * |
| 122 | * If you compile and run this example against an LDAP server that |
| 123 | * supports v3 of the protocol, you might receive the following results: |
| 124 | * <P> |
| 125 | * |
| 126 | * <PRE> |
| 127 | * supportedextension |
| 128 | * 1.2.3.4 |
| 129 | * </PRE> |
| 130 | * <P> |
| 131 | * |
| 132 | * For more information on LDAP controls, see the Internet-Draft on |
| 133 | * the LDAP v3 protocol. (Note that this internet draft is still a |
| 134 | * work in progress. You can find the latest draft at the <A |
| 135 | * HREF="http://www.ietf.cnri.reston.va.us/html.charters/asid-charter.html" |
| 136 | * TARGET="_blank">ASID home page</A>. |
| 137 | * <P> |
| 138 | * |
| 139 | * @version 1.0 |
| 140 | * @see org.ietf.ldap.LDAPConnection#extendedOperation(org.ietf.ldap.LDAPExtendedOperation) |
| 141 | * @see org.ietf.ldap.LDAPConnection#search(java.lang.String, int, java.lang.String, java.lang.String[], boolean) |
| 142 | * |
| 143 | */ |
| 144 | public class LDAPExtendedOperation implements Serializable { |
| 145 | |
| 146 | static final long serialVersionUID = 4010382829133611945L; |
| 147 | |
| 148 | /** |
| 149 | * Construct an object |
| 150 | * @param oid identifier for the particular operation |
| 151 | * @param vals operation-specific data |
| 152 | */ |
| 153 | public LDAPExtendedOperation( String oid, byte[] vals ) { |
| 154 | _oid = oid; |
| 155 | _vals = vals; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Gets the identifier for this operation |
| 160 | * |
| 161 | * @return identifier for the operation |
| 162 | */ |
| 163 | public String getID() { |
| 164 | return _oid; |
| 165 | } |
| 166 | |
| 167 | /** |
| 168 | * Gets the data for this operation |
| 169 | * |
| 170 | * @return operation-specific data |
| 171 | */ |
| 172 | public byte[] getValue() { |
| 173 | return _vals; |
| 174 | } |
| 175 | |
| 176 | /** |
| 177 | * Sets the data for this operation |
| 178 | * |
| 179 | * @param vals operation-specific data |
| 180 | */ |
| 181 | public void setValue( byte[] vals ) { |
| 182 | _vals = vals; |
| 183 | } |
| 184 | |
| 185 | private String _oid; |
| 186 | private byte[] _vals; |
| 187 | } |