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 is 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  // The integer value for this subtree accessibility state.
108  private final int intValue;
109
110  // The name for this subtree accessibility state.
111  @NotNull private final String stateName;
112
113
114
115  /**
116   * Creates a new subtree accessibility state with the provided integer value.
117   *
118   * @param  intValue   The integer value for this subtree accessibility state.
119   * @param  stateName  The name for this subtree accessibility state.
120   */
121  SubtreeAccessibilityState(final int intValue, @NotNull final String stateName)
122  {
123    this.intValue  = intValue;
124    this.stateName = stateName;
125  }
126
127
128
129  /**
130   * Retrieves the integer value for this subtree accessibility state.
131   *
132   * @return  The integer value for this subtree accessibility state.
133   */
134  public int intValue()
135  {
136    return intValue;
137  }
138
139
140
141  /**
142   * Retrieves the name for this subtree accessibility state.
143   *
144   * @return  The name for this subtree accessibility state.
145   */
146  @NotNull()
147  public String getStateName()
148  {
149    return stateName;
150  }
151
152
153
154  /**
155   * Indicates whether this state object represents the ACCESSIBLE state.
156   *
157   * @return  {@code true} if this state object represents the ACCESSIBLE state,
158   *          or {@code false} if not.
159   */
160  public boolean isAccessible()
161  {
162    return (this == ACCESSIBLE);
163  }
164
165
166
167  /**
168   * Indicates whether this state object represents the HIDDEN state.
169   *
170   * @return  {@code true} if this state object represents the HIDDEN state,
171   *          or {@code false} if not.
172   */
173  public boolean isHidden()
174  {
175    return (this == HIDDEN);
176  }
177
178
179
180  /**
181   * Indicates whether this state object represents one of the read-only states.
182   *
183   * @return  {@code true} if this state object represents one of the read-only
184   *          states, or {@code false} if not.
185   */
186  public boolean isReadOnly()
187  {
188    return ((this == READ_ONLY_BIND_ALLOWED) ||
189            (this == READ_ONLY_BIND_DENIED));
190  }
191
192
193
194  /**
195   * Retrieves the subtree accessibility state with the specified integer value.
196   *
197   * @param  intValue  The integer value for the state to retrieve.
198   *
199   * @return  The subtree accessibility state with the specified integer value,
200   *          or {@code null} if there is no accessibility state with the
201   *          specified integer value.
202   */
203  @Nullable()
204  public static SubtreeAccessibilityState valueOf(final int intValue)
205  {
206    switch (intValue)
207    {
208      case 0:
209        return ACCESSIBLE;
210      case 1:
211        return READ_ONLY_BIND_ALLOWED;
212      case 2:
213        return READ_ONLY_BIND_DENIED;
214      case 3:
215        return HIDDEN;
216      default:
217        return null;
218    }
219  }
220
221
222
223  /**
224   * Retrieves the subtree accessibility state with the provided name.
225   *
226   * @param  name  The name for the subtree accessibility state to retrieve.  It
227   *               must not be {@code null}.
228   *
229   * @return  The subtree accessibility state with the specified name, or
230   *          {@code null} if no state has the provided name.
231   */
232  @Nullable()
233  public static SubtreeAccessibilityState forName(@NotNull final String name)
234  {
235    switch (StaticUtils.toLowerCase(name))
236    {
237      case "accessible":
238        return ACCESSIBLE;
239      case "readonlybindallowed":
240      case "read-only-bind-allowed":
241      case "read_only_bind_allowed":
242        return READ_ONLY_BIND_ALLOWED;
243      case "readonlybinddenied":
244      case "read-only-bind-denied":
245      case "read_only_bind_denied":
246        return READ_ONLY_BIND_DENIED;
247      case "hidden":
248        return HIDDEN;
249      default:
250        return null;
251    }
252  }
253
254
255
256  /**
257   * Retrieves a string representation of this subtree accessibility state.
258   *
259   * @return  A string representation of this subtree accessibility state.
260   */
261  @Override()
262  @NotNull()
263  public String toString()
264  {
265    return stateName;
266  }
267}