001/* 002 * Copyright 2014-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2014-2020 Ping Identity Corporation 007 * 008 * Licensed under the Apache License, Version 2.0 (the "License"); 009 * you may not use this file except in compliance with the License. 010 * You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, software 015 * distributed under the License is distributed on an "AS IS" BASIS, 016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 017 * See the License for the specific language governing permissions and 018 * limitations under the License. 019 */ 020/* 021 * Copyright (C) 2015-2020 Ping Identity Corporation 022 * 023 * This program is free software; you can redistribute it and/or modify 024 * it under the terms of the GNU General Public License (GPLv2 only) 025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only) 026 * as published by the Free Software Foundation. 027 * 028 * This program is distributed in the hope that it will be useful, 029 * but WITHOUT ANY WARRANTY; without even the implied warranty of 030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 031 * GNU General Public License for more details. 032 * 033 * You should have received a copy of the GNU General Public License 034 * along with this program; if not, see <http://www.gnu.org/licenses>. 035 */ 036package com.unboundid.ldap.sdk.unboundidds.extensions; 037 038 039 040import java.util.ArrayList; 041import java.util.Collection; 042import java.util.Collections; 043import java.util.List; 044 045import com.unboundid.asn1.ASN1Element; 046import com.unboundid.asn1.ASN1OctetString; 047import com.unboundid.asn1.ASN1Sequence; 048import com.unboundid.ldap.sdk.Control; 049import com.unboundid.ldap.sdk.ExtendedRequest; 050import com.unboundid.ldap.sdk.LDAPException; 051import com.unboundid.ldap.sdk.ResultCode; 052import com.unboundid.util.Debug; 053import com.unboundid.util.NotMutable; 054import com.unboundid.util.StaticUtils; 055import com.unboundid.util.ThreadSafety; 056import com.unboundid.util.ThreadSafetyLevel; 057import com.unboundid.util.Validator; 058 059import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 060 061 062 063/** 064 * This class provides an extended request that may be used to create or update 065 * a notification subscription. 066 * <BR> 067 * <BLOCKQUOTE> 068 * <B>NOTE:</B> This class, and other classes within the 069 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 070 * supported for use against Ping Identity, UnboundID, and 071 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 072 * for proprietary functionality or for external specifications that are not 073 * considered stable or mature enough to be guaranteed to work in an 074 * interoperable way with other types of LDAP servers. 075 * </BLOCKQUOTE> 076 * <BR> 077 * The request has an OID of 1.3.6.1.4.1.30221.2.6.38 and a value with the 078 * following encoding: 079 * <BR><BR> 080 * <PRE> 081 * SetNotificationSubscriptionRequest ::= SEQUENCE { 082 * notificationManagerID OCTET STRING, 083 * notificationDestinationID OCTET STRING, 084 * notificationSubscriptionID OCTET STRING, 085 * subscriptionDetails SEQUENCE OF OCTET STRING } 086 * </PRE> 087 */ 088@NotMutable() 089@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 090public final class SetNotificationSubscriptionExtendedRequest 091 extends ExtendedRequest 092{ 093 /** 094 * The OID (1.3.6.1.4.1.30221.2.6.38) for the set notification subscription 095 * extended request. 096 */ 097 public static final String SET_NOTIFICATION_SUBSCRIPTION_REQUEST_OID = 098 "1.3.6.1.4.1.30221.2.6.38"; 099 100 101 102 /** 103 * The serial version UID for this serializable class. 104 */ 105 private static final long serialVersionUID = -5822283773149091097L; 106 107 108 109 // The implementation-specific details for the notification subscription. 110 private final List<ASN1OctetString> subscriptionDetails; 111 112 // The notification destination ID. 113 private final String destinationID; 114 115 // The notification manager ID. 116 private final String managerID; 117 118 // The notification subscription ID. 119 private final String subscriptionID; 120 121 122 123 /** 124 * Creates a new set notification subscription extended request with the 125 * provided information. 126 * 127 * @param managerID The notification manager ID. It must not be 128 * {@code null}. 129 * @param destinationID The notification destination ID. It must not 130 * be {@code null}. 131 * @param subscriptionID The notification subscription ID. It must not 132 * be {@code null}. 133 * @param subscriptionDetails The implementation-specific details for the 134 * notification subscription. At least one 135 * detail value must be provided. 136 */ 137 public SetNotificationSubscriptionExtendedRequest(final String managerID, 138 final String destinationID, final String subscriptionID, 139 final ASN1OctetString... subscriptionDetails) 140 { 141 this(managerID, destinationID, subscriptionID, 142 StaticUtils.toList(subscriptionDetails)); 143 } 144 145 146 147 /** 148 * Creates a new set notification subscription extended request with the 149 * provided information. 150 * 151 * Creates a new set notification subscription extended request with the 152 * provided information. 153 * 154 * @param managerID The notification manager ID. It must not be 155 * {@code null}. 156 * @param destinationID The notification destination ID. It must not 157 * be {@code null}. 158 * @param subscriptionID The notification subscription ID. It must not 159 * be {@code null}. 160 * @param subscriptionDetails The implementation-specific details for the 161 * notification subscription. At least one 162 * detail value must be provided. 163 * @param controls The set of controls to include in the request. 164 * It may be {@code null} or empty if no controls 165 * are needed. 166 */ 167 public SetNotificationSubscriptionExtendedRequest(final String managerID, 168 final String destinationID, final String subscriptionID, 169 final Collection<ASN1OctetString> subscriptionDetails, 170 final Control... controls) 171 { 172 super(SET_NOTIFICATION_SUBSCRIPTION_REQUEST_OID, 173 encodeValue(managerID, destinationID, subscriptionID, 174 subscriptionDetails), 175 controls); 176 177 this.managerID = managerID; 178 this.destinationID = destinationID; 179 this.subscriptionID = subscriptionID; 180 this.subscriptionDetails = 181 Collections.unmodifiableList(new ArrayList<>(subscriptionDetails)); 182 } 183 184 185 186 /** 187 * Creates a new set notification subscription extended request from the 188 * provided generic extended request. 189 * 190 * @param extendedRequest The generic extended request to use to create this 191 * set notification subscription extended request. 192 * 193 * @throws LDAPException If a problem occurs while decoding the request. 194 */ 195 public SetNotificationSubscriptionExtendedRequest( 196 final ExtendedRequest extendedRequest) 197 throws LDAPException 198 { 199 super(extendedRequest); 200 201 final ASN1OctetString value = extendedRequest.getValue(); 202 if (value == null) 203 { 204 throw new LDAPException(ResultCode.DECODING_ERROR, 205 ERR_SET_NOTIFICATION_SUB_REQ_DECODE_NO_VALUE.get()); 206 } 207 208 try 209 { 210 final ASN1Element[] elements = 211 ASN1Sequence.decodeAsSequence(value.getValue()).elements(); 212 managerID = 213 ASN1OctetString.decodeAsOctetString(elements[0]).stringValue(); 214 destinationID = 215 ASN1OctetString.decodeAsOctetString(elements[1]).stringValue(); 216 subscriptionID = 217 ASN1OctetString.decodeAsOctetString(elements[2]).stringValue(); 218 219 final ASN1Element[] detailElements = 220 ASN1Sequence.decodeAsSequence(elements[3]).elements(); 221 final ArrayList<ASN1OctetString> detailList = 222 new ArrayList<>(detailElements.length); 223 for (final ASN1Element e : detailElements) 224 { 225 detailList.add(ASN1OctetString.decodeAsOctetString(e)); 226 } 227 subscriptionDetails = Collections.unmodifiableList(detailList); 228 } 229 catch (final Exception e) 230 { 231 Debug.debugException(e); 232 throw new LDAPException(ResultCode.DECODING_ERROR, 233 ERR_SET_NOTIFICATION_SUB_REQ_ERROR_DECODING_VALUE.get( 234 StaticUtils.getExceptionMessage(e)), 235 e); 236 } 237 } 238 239 240 241 /** 242 * Encodes the provided information into an ASN.1 octet string suitable for 243 * use as the value of this extended request. 244 * 245 * @param managerID The notification manager ID. It must not be 246 * {@code null}. 247 * @param destinationID The notification destination ID. It must not 248 * be {@code null}. 249 * @param subscriptionID The notification subscription ID. It must not 250 * be {@code null}. 251 * @param subscriptionDetails The implementation-specific details for the 252 * notification subscription. At least one 253 * detail value must be provided. 254 * 255 * @return The ASN.1 octet string containing the encoded value. 256 */ 257 private static ASN1OctetString encodeValue(final String managerID, 258 final String destinationID, final String subscriptionID, 259 final Collection<ASN1OctetString> subscriptionDetails) 260 { 261 Validator.ensureNotNull(managerID); 262 Validator.ensureNotNull(destinationID); 263 Validator.ensureNotNull(subscriptionID); 264 Validator.ensureNotNull(subscriptionDetails); 265 Validator.ensureFalse(subscriptionDetails.isEmpty()); 266 267 final ASN1Sequence valueSequence = new ASN1Sequence( 268 new ASN1OctetString(managerID), 269 new ASN1OctetString(destinationID), 270 new ASN1OctetString(subscriptionID), 271 new ASN1Sequence(new ArrayList<ASN1Element>(subscriptionDetails))); 272 return new ASN1OctetString(valueSequence.encode()); 273 } 274 275 276 277 /** 278 * Retrieves the notification manager ID. 279 * 280 * @return The notification manager ID. 281 */ 282 public String getManagerID() 283 { 284 return managerID; 285 } 286 287 288 289 /** 290 * Retrieves the notification destination ID. 291 * 292 * @return The notification destination ID. 293 */ 294 public String getDestinationID() 295 { 296 return destinationID; 297 } 298 299 300 301 /** 302 * Retrieves the notification subscription ID. 303 * 304 * @return The notification subscription ID. 305 */ 306 public String getSubscriptionID() 307 { 308 return subscriptionID; 309 } 310 311 312 313 /** 314 * Retrieves the implementation-specific details for the notification 315 * subscription. 316 * 317 * @return The implementation-specific details for the notification 318 * subscription. 319 */ 320 public List<ASN1OctetString> getSubscriptionDetails() 321 { 322 return subscriptionDetails; 323 } 324 325 326 327 /** 328 * {@inheritDoc} 329 */ 330 @Override() 331 public SetNotificationSubscriptionExtendedRequest duplicate() 332 { 333 return duplicate(getControls()); 334 } 335 336 337 338 /** 339 * {@inheritDoc} 340 */ 341 @Override() 342 public SetNotificationSubscriptionExtendedRequest 343 duplicate(final Control[] controls) 344 { 345 final SetNotificationSubscriptionExtendedRequest r = 346 new SetNotificationSubscriptionExtendedRequest(managerID, 347 destinationID, subscriptionID, subscriptionDetails, controls); 348 r.setResponseTimeoutMillis(getResponseTimeoutMillis(null)); 349 return r; 350 } 351 352 353 354 /** 355 * {@inheritDoc} 356 */ 357 @Override() 358 public String getExtendedRequestName() 359 { 360 return INFO_EXTENDED_REQUEST_NAME_SET_NOTIFICATION_SUB.get(); 361 } 362 363 364 365 /** 366 * {@inheritDoc} 367 */ 368 @Override() 369 public void toString(final StringBuilder buffer) 370 { 371 buffer.append("SetNotificationSubscriptionExtendedRequest(managerID='"); 372 buffer.append(managerID); 373 buffer.append("', destinationID='"); 374 buffer.append(destinationID); 375 buffer.append("', subscriptionID='"); 376 buffer.append(subscriptionID); 377 buffer.append("', subscriptionDetails=ASN1OctetString["); 378 buffer.append(subscriptionDetails.size()); 379 buffer.append(']'); 380 381 final Control[] controls = getControls(); 382 if (controls.length > 0) 383 { 384 buffer.append(", controls={"); 385 for (int i=0; i < controls.length; i++) 386 { 387 if (i > 0) 388 { 389 buffer.append(", "); 390 } 391 392 buffer.append(controls[i]); 393 } 394 buffer.append('}'); 395 } 396 397 buffer.append(')'); 398 } 399}