001/*
002 * Copyright 2011-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2011-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) 2011-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.util;
037
038
039
040import java.io.Serializable;
041
042
043
044/**
045 * This class provides a data structure that holds information about an option
046 * that can be used in the course of SASL authentication.
047 */
048@NotMutable()
049@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
050public final class SASLOption
051       implements Serializable
052{
053  /**
054   * The serial version UID for this serializable class.
055   */
056  private static final long serialVersionUID = -683675804002105357L;
057
058
059
060  // Indicates whether this option is allowed to be specified multiple times for
061  // a single bind request.
062  private final boolean isMultiValued;
063
064  // Indicates whether this SASL option is required for use in conjunction with
065  // the associated SASL mechanism.
066  private final boolean isRequired;
067
068  // A description for this SASL option.
069  private final String description;
070
071  // The name for this SASL option.
072  private final String name;
073
074
075
076  /**
077   * Creates a new SASL option with the provided information.
078   *
079   * @param  name           The name for this SASL option.
080   * @param  description    A description for this SASL option.
081   * @param  isRequired     Indicates whether this option is required for use in
082   *                        conjunction with the associated SASL mechanism.
083   * @param  isMultiValued  Indicates whether this option is allowed to be
084   *                        specified multiple times for a single bind request.
085   */
086  public SASLOption(final String name, final String description,
087                    final boolean isRequired, final boolean isMultiValued)
088  {
089    this.name          = name;
090    this.description   = description;
091    this.isRequired    = isRequired;
092    this.isMultiValued = isMultiValued;
093  }
094
095
096
097  /**
098   * Retrieves the name for this SASL option.
099   *
100   * @return  The name for this SASL option.
101   */
102  public String getName()
103  {
104    return name;
105  }
106
107
108
109  /**
110   * Retrieves a description for this SASL option.
111   *
112   * @return  A description for this SASL option.
113   */
114  public String getDescription()
115  {
116    return description;
117  }
118
119
120
121  /**
122   * Indicates whether this SASL option must be provided when attempting to bind
123   * with the associated mechanism.
124   *
125   * @return  {@code true} if this SASL option must be specified when trying to
126   *          bind with the associated mechanism, or {@code false} if not.
127   */
128  public boolean isRequired()
129  {
130    return isRequired;
131  }
132
133
134
135  /**
136   * Indicates whether this SASL option may be provided multiple times when
137   * trying to bind with the associated mechanism.
138   *
139   * @return  {@code true} if this SASL option may be provided multiple times
140   *          when trying to bind with the associated mechanism, or
141   *          {@code false} if not.
142   */
143  public boolean isMultiValued()
144  {
145    return isMultiValued;
146  }
147
148
149
150  /**
151   * Retrieves a string representation for this SASL option.
152   *
153   * @return  A string representation for this SASL option.
154   */
155  @Override()
156  public String toString()
157  {
158    final StringBuilder buffer = new StringBuilder();
159    toString(buffer);
160    return buffer.toString();
161  }
162
163
164
165  /**
166   * Appends a string representation of this SASL option to the provided buffer.
167   *
168   * @param  buffer  The buffer to which the information should be appended.
169   */
170  public void toString(final StringBuilder buffer)
171  {
172    buffer.append("SASLOption(name='");
173    buffer.append(name);
174    buffer.append("', description='");
175    buffer.append(description);
176    buffer.append("', isRequired=");
177    buffer.append(isRequired);
178    buffer.append(", isMultiValued=");
179    buffer.append(isMultiValued);
180    buffer.append(')');
181  }
182}