001/* 002 * Copyright 2009-2017 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright (C) 2015-2017 Ping Identity Corporation 007 * 008 * This program is free software; you can redistribute it and/or modify 009 * it under the terms of the GNU General Public License (GPLv2 only) 010 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 011 * as published by the Free Software Foundation. 012 * 013 * This program is distributed in the hope that it will be useful, 014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 016 * GNU General Public License for more details. 017 * 018 * You should have received a copy of the GNU General Public License 019 * along with this program; if not, see <http://www.gnu.org/licenses>. 020 */ 021package com.unboundid.ldap.sdk.unboundidds.controls; 022 023 024 025import com.unboundid.asn1.ASN1OctetString; 026import com.unboundid.ldap.sdk.Control; 027import com.unboundid.util.NotMutable; 028import com.unboundid.util.ThreadSafety; 029import com.unboundid.util.ThreadSafetyLevel; 030 031import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 032 033 034 035/** 036 * This class provides an implementation of a Directory Server control that may 037 * be used to indicate that the associated operation is used for performing some 038 * administrative operation within the server rather than one that was requested 039 * by a "normal" client. The server can use this indication to treat the 040 * operation differently (e.g., exclude it from the processing time histogram, 041 * or to include additional information about the purpose of the operation in 042 * the access log). 043 * <BR> 044 * <BLOCKQUOTE> 045 * <B>NOTE:</B> This class, and other classes within the 046 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 047 * supported for use against Ping Identity, UnboundID, and Alcatel-Lucent 8661 048 * server products. These classes provide support for proprietary 049 * functionality or for external specifications that are not considered stable 050 * or mature enough to be guaranteed to work in an interoperable way with 051 * other types of LDAP servers. 052 * </BLOCKQUOTE> 053 */ 054@NotMutable() 055@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 056public final class AdministrativeOperationRequestControl 057 extends Control 058{ 059 /** 060 * The OID (1.3.6.1.4.1.30221.2.5.11) for the administrative operation request 061 * control. 062 */ 063 public static final String ADMINISTRATIVE_OPERATION_REQUEST_OID = 064 "1.3.6.1.4.1.30221.2.5.11"; 065 066 067 068 /** 069 * The serial version UID for this serializable class. 070 */ 071 private static final long serialVersionUID = 4958642483402677725L; 072 073 074 075 // The informational message to include in the control, if defined. 076 private final String message; 077 078 079 080 /** 081 * Creates a new administrative operation request control with no message. 082 */ 083 public AdministrativeOperationRequestControl() 084 { 085 this((String) null); 086 } 087 088 089 090 /** 091 * Creates a new administrative operation request control with the provided 092 * informational message. 093 * 094 * @param message A message with additional information about the purpose of 095 * the associated operation. It may be {@code null} if no 096 * additional message should be provided. 097 */ 098 public AdministrativeOperationRequestControl(final String message) 099 { 100 super(ADMINISTRATIVE_OPERATION_REQUEST_OID, false, encodeValue(message)); 101 102 this.message = message; 103 } 104 105 106 107 /** 108 * Creates a new administrative operation request control decoded from the 109 * provided generic control. 110 * 111 * @param control The generic control to be decoded as an administrative 112 * operation request control. 113 */ 114 public AdministrativeOperationRequestControl(final Control control) 115 { 116 super(control); 117 118 if (control.hasValue()) 119 { 120 message = control.getValue().stringValue(); 121 } 122 else 123 { 124 message = null; 125 } 126 } 127 128 129 130 /** 131 * Generates an appropriately-encoded value for this control with the provided 132 * message. 133 * 134 * @param message A message with additional information about the purpose of 135 * the associated operation. It may be {@code null} if no 136 * additional message should be provided. 137 * 138 * @return An appropriately-encoded value for this control, or {@code null} 139 * if no value is needed. 140 */ 141 private static ASN1OctetString encodeValue(final String message) 142 { 143 if (message == null) 144 { 145 return null; 146 } 147 else 148 { 149 return new ASN1OctetString(message); 150 } 151 } 152 153 154 155 /** 156 * Retrieves the informational message for this control, if defined. 157 * 158 * @return The informational message for this control, or {@code null} if 159 * none was provided. 160 */ 161 public String getMessage() 162 { 163 return message; 164 } 165 166 167 168 /** 169 * {@inheritDoc} 170 */ 171 @Override() 172 public String getControlName() 173 { 174 return INFO_CONTROL_NAME_ADMINISTRATIVE_OPERATION_REQUEST.get(); 175 } 176 177 178 179 /** 180 * {@inheritDoc} 181 */ 182 @Override() 183 public void toString(final StringBuilder buffer) 184 { 185 buffer.append("AdministrativeOperationRequestControl("); 186 187 if (message != null) 188 { 189 buffer.append("message='"); 190 buffer.append(message); 191 buffer.append('\''); 192 } 193 194 buffer.append(')'); 195 } 196}