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