001/* 002 * Copyright 2008-2022 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2008-2022 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) 2008-2022 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.controls; 037 038 039 040import com.unboundid.ldap.sdk.Control; 041import com.unboundid.ldap.sdk.LDAPException; 042import com.unboundid.ldap.sdk.ResultCode; 043import com.unboundid.util.NotMutable; 044import com.unboundid.util.NotNull; 045import com.unboundid.util.ThreadSafety; 046import com.unboundid.util.ThreadSafetyLevel; 047 048import static com.unboundid.ldap.sdk.unboundidds.controls.ControlMessages.*; 049 050 051 052/** 053 * This class provides an implementation of the account usable request control. 054 * It may be included in search requests, in which case each search result entry 055 * matching that request should include the corresponding response control to 056 * obtain information about the usability of the user account associated with 057 * that entry. In particular, it indicates whether a bind with valid 058 * credentials would likely succeed and the resulting connection would be 059 * usable, and if not the reason for the potential failure. See the 060 * {@link AccountUsableResponseControl} for information about the information 061 * that is taken into account. 062 * <BR> 063 * <BLOCKQUOTE> 064 * <B>NOTE:</B> This class, and other classes within the 065 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 066 * supported for use against Ping Identity, UnboundID, and 067 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 068 * for proprietary functionality or for external specifications that are not 069 * considered stable or mature enough to be guaranteed to work in an 070 * interoperable way with other types of LDAP servers. 071 * </BLOCKQUOTE> 072 * <BR> 073 * This control was designed by Sun Microsystems and is not based on any RFC or 074 * Internet draft. It does not include a value. 075 * <BR><BR> 076 * <H2>Example</H2> 077 * The following example demonstrates the use of the account usable controls to 078 * determine whether the account for user with uid "john.doe" is usable: 079 * <PRE> 080 * SearchRequest searchRequest = 081 * new SearchRequest("dc=example,dc=com", SearchScope.SUB, 082 * Filter.createEqualityFilter("uid", "john.doe")); 083 * searchRequest.addControl(new AccountUsableRequestControl()); 084 * SearchResult searchResult = connection.search(searchRequest); 085 * 086 * boolean isUsable = false; 087 * for (SearchResultEntry entry : searchResult.getSearchEntries()) 088 * { 089 * AccountUsableResponseControl c = 090 * AccountUsableResponseControl.get(entry); 091 * isUsable = c.isUsable(); 092 * if (isUsable) 093 * { 094 * // The account is usable. 095 * } 096 * else 097 * { 098 * // The account is not usable. 099 * List<String> unusableReasons = c.getUnusableReasons(); 100 * } 101 * } 102 * </PRE> 103 */ 104@NotMutable() 105@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 106public final class AccountUsableRequestControl 107 extends Control 108{ 109 /** 110 * The OID (1.3.6.1.4.1.42.2.27.9.5.8) for the account usable request control. 111 */ 112 @NotNull public static final String ACCOUNT_USABLE_REQUEST_OID = 113 "1.3.6.1.4.1.42.2.27.9.5.8"; 114 115 116 117 /** 118 * The serial version UID for this serializable class. 119 */ 120 private static final long serialVersionUID = 2776055961624360982L; 121 122 123 124 /** 125 * Creates a new account usable request control. It will not be marked 126 * critical. 127 */ 128 public AccountUsableRequestControl() 129 { 130 this(false); 131 } 132 133 134 135 /** 136 * Creates a new account usable request control with the specified 137 * criticality. 138 * 139 * @param isCritical Indicates whether this control should be marked 140 * critical. 141 */ 142 public AccountUsableRequestControl(final boolean isCritical) 143 { 144 super(ACCOUNT_USABLE_REQUEST_OID, isCritical, null); 145 } 146 147 148 149 /** 150 * Creates a new account usable request control which is decoded from the 151 * provided generic control. 152 * 153 * @param control The generic control to be decoded as an account usable 154 * request control. 155 * 156 * @throws LDAPException If the provided control cannot be decoded as an 157 * account usable request control. 158 */ 159 public AccountUsableRequestControl(@NotNull final Control control) 160 throws LDAPException 161 { 162 super(control); 163 164 if (control.hasValue()) 165 { 166 throw new LDAPException(ResultCode.DECODING_ERROR, 167 ERR_ACCOUNT_USABLE_REQUEST_HAS_VALUE.get()); 168 } 169 } 170 171 172 173 /** 174 * {@inheritDoc} 175 */ 176 @Override() 177 @NotNull() 178 public String getControlName() 179 { 180 return INFO_CONTROL_NAME_ACCOUNT_USABLE_REQUEST.get(); 181 } 182 183 184 185 /** 186 * {@inheritDoc} 187 */ 188 @Override() 189 public void toString(@NotNull final StringBuilder buffer) 190 { 191 buffer.append("AccountUsableRequestControl(isCritical="); 192 buffer.append(isCritical()); 193 buffer.append(')'); 194 } 195}