001/* 002 * Copyright 2011-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2011-2024 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-2024 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 @NotNull private final String description; 070 071 // The name for this SASL option. 072 @NotNull 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(@NotNull final String name, 087 @NotNull final String description, 088 final boolean isRequired, final boolean isMultiValued) 089 { 090 this.name = name; 091 this.description = description; 092 this.isRequired = isRequired; 093 this.isMultiValued = isMultiValued; 094 } 095 096 097 098 /** 099 * Retrieves the name for this SASL option. 100 * 101 * @return The name for this SASL option. 102 */ 103 @NotNull() 104 public String getName() 105 { 106 return name; 107 } 108 109 110 111 /** 112 * Retrieves a description for this SASL option. 113 * 114 * @return A description for this SASL option. 115 */ 116 @NotNull() 117 public String getDescription() 118 { 119 return description; 120 } 121 122 123 124 /** 125 * Indicates whether this SASL option must be provided when attempting to bind 126 * with the associated mechanism. 127 * 128 * @return {@code true} if this SASL option must be specified when trying to 129 * bind with the associated mechanism, or {@code false} if not. 130 */ 131 public boolean isRequired() 132 { 133 return isRequired; 134 } 135 136 137 138 /** 139 * Indicates whether this SASL option may be provided multiple times when 140 * trying to bind with the associated mechanism. 141 * 142 * @return {@code true} if this SASL option may be provided multiple times 143 * when trying to bind with the associated mechanism, or 144 * {@code false} if not. 145 */ 146 public boolean isMultiValued() 147 { 148 return isMultiValued; 149 } 150 151 152 153 /** 154 * Retrieves a string representation for this SASL option. 155 * 156 * @return A string representation for this SASL option. 157 */ 158 @Override() 159 @NotNull() 160 public String toString() 161 { 162 final StringBuilder buffer = new StringBuilder(); 163 toString(buffer); 164 return buffer.toString(); 165 } 166 167 168 169 /** 170 * Appends a string representation of this SASL option to the provided buffer. 171 * 172 * @param buffer The buffer to which the information should be appended. 173 */ 174 public void toString(@NotNull final StringBuilder buffer) 175 { 176 buffer.append("SASLOption(name='"); 177 buffer.append(name); 178 buffer.append("', description='"); 179 buffer.append(description); 180 buffer.append("', isRequired="); 181 buffer.append(isRequired); 182 buffer.append(", isMultiValued="); 183 buffer.append(isMultiValued); 184 buffer.append(')'); 185 } 186}