001/* 002 * Copyright 2012-2024 Ping Identity Corporation 003 * All Rights Reserved. 004 */ 005/* 006 * Copyright 2012-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) 2012-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.ldap.sdk.unboundidds.extensions; 037 038 039 040import com.unboundid.util.NotNull; 041import com.unboundid.util.Nullable; 042import com.unboundid.util.StaticUtils; 043 044 045 046/** 047 * This enum defines the set of allowed accessibility states that may be used 048 * with the {@link SetSubtreeAccessibilityExtendedRequest}. 049 * <BR> 050 * <BLOCKQUOTE> 051 * <B>NOTE:</B> This class, and other classes within the 052 * {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only 053 * supported for use against Ping Identity, UnboundID, and 054 * Nokia/Alcatel-Lucent 8661 server products. These classes provide support 055 * for proprietary functionality or for external specifications that are not 056 * considered stable or mature enough to be guaranteed to work in an 057 * interoperable way with other types of LDAP servers. 058 * </BLOCKQUOTE> 059 */ 060public enum SubtreeAccessibilityState 061{ 062 /** 063 * Indicates that the subtree should return to normal accessibility so that 064 * all appropriately-authorized users will be able to perform all kinds of 065 * operations in the target subtree. 066 */ 067 ACCESSIBLE(0, "accessible"), 068 069 070 071 /** 072 * Indicates that the subtree should be made read-only so that search and 073 * compare operations targeting those entries will be allowed, but add, 074 * delete, modify, and modify DN operations will only be allowed for one 075 * specified user (as indicated in the set subtree accessibility request). 076 * Bind operations will be allowed, but any changes intended to update 077 * password policy or other account state (e.g., to record failed 078 * authentication attempts or update last login time) will not be applied. 079 */ 080 READ_ONLY_BIND_ALLOWED(1, "read-only-bind-allowed"), 081 082 083 084 /** 085 * Indicates that the subtree should be made read-only so that search and 086 * compare operations targeting those entries will be allowed, but add, 087 * delete, modify, and modify DN operations will only be allowed for one 088 * specified user (as indicated in the set subtree accessibility request). 089 * Bind operations will not be allowed for any user in the specified subtree. 090 */ 091 READ_ONLY_BIND_DENIED(2, "read-only-bind-denied"), 092 093 094 095 /** 096 * Indicates that the subtree should be made hidden so that it is not 097 * accessible to most clients for any kinds of operations. The subtree will 098 * be available to one specified user (as indicated in the set subtree 099 * accessibility request) for add, compare, delete, modify, modify DN, and 100 * search operations. Bind operations will not be allowed for any user in a 101 * hidden subtree. 102 */ 103 HIDDEN(3, "hidden"), 104 105 106 107 /** 108 * Indicates that the subtree is intended to be deleted. It will behave in 109 * the same way as the {@link #HIDDEN} state, with the exception that the 110 * server will not allow any further changes to the subtree accessibility 111 * state. That accessibility state will persist until the entry at the base 112 * of the subtree has been removed. 113 */ 114 TO_BE_DELETED(4, "to-be-deleted"); 115 116 117 118 // The integer value for this subtree accessibility state. 119 private final int intValue; 120 121 // The name for this subtree accessibility state. 122 @NotNull private final String stateName; 123 124 125 126 /** 127 * Creates a new subtree accessibility state with the provided integer value. 128 * 129 * @param intValue The integer value for this subtree accessibility state. 130 * @param stateName The name for this subtree accessibility state. 131 */ 132 SubtreeAccessibilityState(final int intValue, @NotNull final String stateName) 133 { 134 this.intValue = intValue; 135 this.stateName = stateName; 136 } 137 138 139 140 /** 141 * Retrieves the integer value for this subtree accessibility state. 142 * 143 * @return The integer value for this subtree accessibility state. 144 */ 145 public int intValue() 146 { 147 return intValue; 148 } 149 150 151 152 /** 153 * Retrieves the name for this subtree accessibility state. 154 * 155 * @return The name for this subtree accessibility state. 156 */ 157 @NotNull() 158 public String getStateName() 159 { 160 return stateName; 161 } 162 163 164 165 /** 166 * Indicates whether this state object represents the ACCESSIBLE state. 167 * 168 * @return {@code true} if this state object represents the ACCESSIBLE state, 169 * or {@code false} if not. 170 */ 171 public boolean isAccessible() 172 { 173 return (this == ACCESSIBLE); 174 } 175 176 177 178 /** 179 * Indicates whether this state object represents the HIDDEN state. For the 180 * purpose of this method, TO_BE_DELETED will also be considered to be HIDDEN, 181 * since the server will treat the two states as equivalent with the exception 182 * that the accessibility state of TO_BE_DELETED subtrees cannot be changed. 183 * 184 * @return {@code true} if this state object represents the HIDDEN or 185 * TO_BE_DELETED state, or {@code false} if not. 186 */ 187 public boolean isHidden() 188 { 189 return ((this == HIDDEN) || 190 (this == TO_BE_DELETED)); 191 } 192 193 194 195 /** 196 * Indicates whether this state object represents one of the read-only states. 197 * 198 * @return {@code true} if this state object represents one of the read-only 199 * states, or {@code false} if not. 200 */ 201 public boolean isReadOnly() 202 { 203 return ((this == READ_ONLY_BIND_ALLOWED) || 204 (this == READ_ONLY_BIND_DENIED)); 205 } 206 207 208 209 /** 210 * Indicates whether this state object represents one of the read-only states. 211 * 212 * @return {@code true} if this state object represents one of the read-only 213 * states, or {@code false} if not. 214 */ 215 public boolean isToBeDeleted() 216 { 217 return (this == TO_BE_DELETED); 218 } 219 220 221 222 /** 223 * Indicates whether this subtree accessibility state is considered more 224 * restrictive than the provided state. States will be considered in the 225 * following descending order of restrictiveness: 226 * <OL> 227 * <LI>{@code TO_BE_DELETED}</LI> 228 * <LI>{@code HIDDEN}</LI> 229 * <LI>{@code READ_ONLY_BIND_DENIED}</LI> 230 * <LI>{@code READ_ONLY_BIND_ALLOWED}</LI> 231 * <LI>{@code ACCESSIBLE}</LI> 232 * </OL> 233 * 234 * @param state The accessibility state to compare against this one. It 235 * must not be {@code null}. 236 * 237 * @return {@code true} if this state is more restrictive than the provided 238 * state, or {@code false} if this state is the same as or less 239 * restrictive than the provided state. 240 */ 241 public boolean isMoreRestrictiveThan( 242 @NotNull final SubtreeAccessibilityState state) 243 { 244 switch (this) 245 { 246 case TO_BE_DELETED: 247 return (state != SubtreeAccessibilityState.TO_BE_DELETED); 248 249 case HIDDEN: 250 return ((state != SubtreeAccessibilityState.TO_BE_DELETED) && 251 (state != SubtreeAccessibilityState.HIDDEN)); 252 253 case READ_ONLY_BIND_DENIED: 254 return ((state != SubtreeAccessibilityState.TO_BE_DELETED) && 255 (state != SubtreeAccessibilityState.HIDDEN) && 256 (state != SubtreeAccessibilityState.READ_ONLY_BIND_DENIED)); 257 258 case READ_ONLY_BIND_ALLOWED: 259 return ((state != SubtreeAccessibilityState.TO_BE_DELETED) && 260 (state != SubtreeAccessibilityState.HIDDEN) && 261 (state != SubtreeAccessibilityState.READ_ONLY_BIND_DENIED) && 262 (state != SubtreeAccessibilityState.READ_ONLY_BIND_ALLOWED)); 263 264 case ACCESSIBLE: 265 default: 266 return false; 267 } 268 } 269 270 271 272 /** 273 * Retrieves the subtree accessibility state with the specified integer value. 274 * 275 * @param intValue The integer value for the state to retrieve. 276 * 277 * @return The subtree accessibility state with the specified integer value, 278 * or {@code null} if there is no accessibility state with the 279 * specified integer value. 280 */ 281 @Nullable() 282 public static SubtreeAccessibilityState valueOf(final int intValue) 283 { 284 switch (intValue) 285 { 286 case 0: 287 return ACCESSIBLE; 288 case 1: 289 return READ_ONLY_BIND_ALLOWED; 290 case 2: 291 return READ_ONLY_BIND_DENIED; 292 case 3: 293 return HIDDEN; 294 case 4: 295 return TO_BE_DELETED; 296 default: 297 return null; 298 } 299 } 300 301 302 303 /** 304 * Retrieves the subtree accessibility state with the provided name. 305 * 306 * @param name The name for the subtree accessibility state to retrieve. It 307 * must not be {@code null}. 308 * 309 * @return The subtree accessibility state with the specified name, or 310 * {@code null} if no state has the provided name. 311 */ 312 @Nullable() 313 public static SubtreeAccessibilityState forName(@NotNull final String name) 314 { 315 switch (StaticUtils.toLowerCase(name)) 316 { 317 case "accessible": 318 return ACCESSIBLE; 319 case "readonlybindallowed": 320 case "read-only-bind-allowed": 321 case "read_only_bind_allowed": 322 return READ_ONLY_BIND_ALLOWED; 323 case "readonlybinddenied": 324 case "read-only-bind-denied": 325 case "read_only_bind_denied": 326 return READ_ONLY_BIND_DENIED; 327 case "hidden": 328 return HIDDEN; 329 case "tobedeleted": 330 case "to-be-deleted": 331 case "to_be_deleted": 332 return TO_BE_DELETED; 333 default: 334 return null; 335 } 336 } 337 338 339 340 /** 341 * Retrieves a string representation of this subtree accessibility state. 342 * 343 * @return A string representation of this subtree accessibility state. 344 */ 345 @Override() 346 @NotNull() 347 public String toString() 348 { 349 return stateName; 350 } 351}