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