001/* 002 * Copyright 2015-2020 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2015-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 com.unboundid.asn1.ASN1Element; 041import com.unboundid.asn1.ASN1OctetString; 042import com.unboundid.asn1.ASN1Sequence; 043import com.unboundid.ldap.sdk.Control; 044import com.unboundid.ldap.sdk.ExtendedRequest; 045import com.unboundid.ldap.sdk.ExtendedResult; 046import com.unboundid.ldap.sdk.LDAPConnection; 047import com.unboundid.ldap.sdk.LDAPException; 048import com.unboundid.ldap.sdk.ResultCode; 049import com.unboundid.util.Debug; 050import com.unboundid.util.NotMutable; 051import com.unboundid.util.StaticUtils; 052import com.unboundid.util.ThreadSafety; 053import com.unboundid.util.ThreadSafetyLevel; 054 055import static com.unboundid.ldap.sdk.unboundidds.extensions.ExtOpMessages.*; 056 057 058 059/** 060 * This class provides an implementation of an extended request that can be used 061 * to retrieve information about which one-time password delivery mechanisms are 062 * supported for a user. 063 * <BR> 064 * <BLOCKQUOTE> 065 * <B>NOTE:</B> This class, and other classes within the 066 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 067 * supported for use against Ping Identity, UnboundID, and 068 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 069 * for proprietary functionality or for external specifications that are not 070 * considered stable or mature enough to be guaranteed to work in an 071 * interoperable way with other types of LDAP servers. 072 * </BLOCKQUOTE> 073 * <BR> 074 * The OID for this extended request is "1.3.6.1.4.1.30221.2.6.47". It must 075 * have a value with the following encoding: 076 * <BR><BR> 077 * <PRE> 078 * GetSupportedOTPDeliveryMechanismsRequest ::= SEQUENCE { 079 * userDN [0] LDAPDN, 080 * ... } 081 * </PRE> 082 * 083 * @see GetSupportedOTPDeliveryMechanismsExtendedResult 084 */ 085@NotMutable() 086@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 087public final class GetSupportedOTPDeliveryMechanismsExtendedRequest 088 extends ExtendedRequest 089{ 090 /** 091 * The OID (1.3.6.1.4.1.30221.2.6.47) for the get supported one-time password 092 * delivery mechanisms extended request. 093 */ 094 public static final String GET_SUPPORTED_OTP_DELIVERY_MECHANISMS_REQUEST_OID = 095 "1.3.6.1.4.1.30221.2.6.47"; 096 097 098 099 /** 100 * The BER type for the userDN element. 101 */ 102 private static final byte TYPE_USER_DN = (byte) 0x80; 103 104 105 106 /** 107 * The serial version UID for this serializable class. 108 */ 109 private static final long serialVersionUID = -1670631089524097883L; 110 111 112 113 // THe DN of the user for whom to retrieve the supported delivery mechanisms. 114 private final String userDN; 115 116 117 118 /** 119 * Creates a new instance of this get supported OTP delivery mechanisms 120 * extended request with the provided information. 121 * 122 * @param userDN The DN of the user for whom to retrieve the list of 123 * supported OTP delivery mechanisms. It must not be 124 * {@code null}. 125 * @param controls The set of controls to include in the request. It may be 126 * {@code null} or empty if no controls should be included. 127 */ 128 public GetSupportedOTPDeliveryMechanismsExtendedRequest(final String userDN, 129 final Control... controls) 130 { 131 super(GET_SUPPORTED_OTP_DELIVERY_MECHANISMS_REQUEST_OID, 132 encodeValue(userDN), controls); 133 134 this.userDN = userDN; 135 } 136 137 138 139 /** 140 * Decodes the provided extended request as a get supported OTP delivery 141 * mechanisms request. 142 * 143 * @param request The extended request to be decoded as a get supported OTP 144 * delivery mechanisms request. 145 * 146 * @throws LDAPException If the provided request cannot be decoded as a get 147 * supported OTP delivery mechanisms request. 148 */ 149 public GetSupportedOTPDeliveryMechanismsExtendedRequest( 150 final ExtendedRequest request) 151 throws LDAPException 152 { 153 super(request); 154 155 final ASN1OctetString value = request.getValue(); 156 if (value == null) 157 { 158 throw new LDAPException(ResultCode.DECODING_ERROR, 159 ERR_GET_SUPPORTED_OTP_MECH_REQUEST_NO_VALUE.get()); 160 } 161 162 try 163 { 164 final ASN1Element[] elements = 165 ASN1Sequence.decodeAsSequence(value.getValue()).elements(); 166 userDN = ASN1OctetString.decodeAsOctetString(elements[0]).stringValue(); 167 } 168 catch (final Exception e) 169 { 170 Debug.debugException(e); 171 throw new LDAPException(ResultCode.DECODING_ERROR, 172 ERR_GET_SUPPORTED_OTP_MECH_REQUEST_CANNOT_DECODE.get( 173 StaticUtils.getExceptionMessage(e)), 174 e); 175 } 176 } 177 178 179 180 /** 181 * Encodes the provided information into an ASN.1 octet string suitable for 182 * use as the value for this extended operation. 183 * 184 * @param userDN The DN of the user for whom to retrieve the list of 185 * supported OTP delivery mechanisms. It must not be 186 * {@code null}. 187 * 188 * @return The ASN.1 octet string containing the encoded control value. 189 */ 190 private static ASN1OctetString encodeValue(final String userDN) 191 { 192 return new ASN1OctetString(new ASN1Sequence( 193 new ASN1OctetString(TYPE_USER_DN, userDN)).encode()); 194 } 195 196 197 198 /** 199 * Retrieves the DN of the user for whom to retrieve the list of supported OTP 200 * delivery mechanisms. 201 * 202 * @return The DN of the user for whom to retrieve the list of supported OTP 203 * delivery mechanisms. 204 */ 205 public String getUserDN() 206 { 207 return userDN; 208 } 209 210 211 212 /** 213 * {@inheritDoc} 214 */ 215 @Override() 216 public GetSupportedOTPDeliveryMechanismsExtendedResult process( 217 final LDAPConnection connection, final int depth) 218 throws LDAPException 219 { 220 final ExtendedResult extendedResponse = super.process(connection, depth); 221 return new GetSupportedOTPDeliveryMechanismsExtendedResult( 222 extendedResponse); 223 } 224 225 226 227 /** 228 * {@inheritDoc}. 229 */ 230 @Override() 231 public GetSupportedOTPDeliveryMechanismsExtendedRequest duplicate() 232 { 233 return duplicate(getControls()); 234 } 235 236 237 238 /** 239 * {@inheritDoc}. 240 */ 241 @Override() 242 public GetSupportedOTPDeliveryMechanismsExtendedRequest duplicate( 243 final Control[] controls) 244 { 245 final GetSupportedOTPDeliveryMechanismsExtendedRequest r = 246 new GetSupportedOTPDeliveryMechanismsExtendedRequest(userDN, 247 controls); 248 r.setResponseTimeoutMillis(getResponseTimeoutMillis(null)); 249 return r; 250 } 251 252 253 254 /** 255 * {@inheritDoc} 256 */ 257 @Override() 258 public String getExtendedRequestName() 259 { 260 return INFO_GET_SUPPORTED_OTP_MECH_REQ_NAME.get(); 261 } 262 263 264 265 /** 266 * {@inheritDoc} 267 */ 268 @Override() 269 public void toString(final StringBuilder buffer) 270 { 271 buffer.append("GetSupportedOTPDeliveryMechanismsExtendedRequest(userDN='"); 272 buffer.append(userDN); 273 buffer.append('\''); 274 275 final Control[] controls = getControls(); 276 if (controls.length > 0) 277 { 278 buffer.append(", controls={"); 279 for (int i=0; i < controls.length; i++) 280 { 281 if (i > 0) 282 { 283 buffer.append(", "); 284 } 285 286 buffer.append(controls[i]); 287 } 288 buffer.append('}'); 289 } 290 291 buffer.append(')'); 292 } 293}