001/*
002 * Copyright 2012-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2012-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) 2015-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.ldap.sdk.unboundidds.extensions;
037
038
039
040import com.unboundid.util.StaticUtils;
041
042
043
044/**
045 * This enum defines the set of allowed accessibility states that may be used
046 * with the {@link SetSubtreeAccessibilityExtendedRequest}.
047 * <BR>
048 * <BLOCKQUOTE>
049 *   <B>NOTE:</B>  This class, and other classes within the
050 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
051 *   supported for use against Ping Identity, UnboundID, and
052 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
053 *   for proprietary functionality or for external specifications that are not
054 *   considered stable or mature enough to be guaranteed to work in an
055 *   interoperable way with other types of LDAP servers.
056 * </BLOCKQUOTE>
057 */
058public enum SubtreeAccessibilityState
059{
060  /**
061   * Indicates that the subtree should return to normal accessibility so that
062   * all appropriately-authorized users will be able to perform all kinds of
063   * operations in the target subtree.
064   */
065  ACCESSIBLE(0, "accessible"),
066
067
068
069  /**
070   * Indicates that the subtree should be made read-only so that search and
071   * compare operations targeting those entries will be allowed, but add,
072   * delete, modify, and modify DN operations will only be allowed for one
073   * specified user (as indicated in the set subtree accessibility request).
074   * Bind operations will be allowed, but any changes intended to update
075   * password policy or other account state (e.g., to record failed
076   * authentication attempts or update last login time) will not be applied.
077   */
078  READ_ONLY_BIND_ALLOWED(1, "read-only-bind-allowed"),
079
080
081
082  /**
083   * Indicates that the subtree should be made read-only so that search and
084   * compare operations targeting those entries will be allowed, but add,
085   * delete, modify, and modify DN operations will only be allowed for one
086   * specified user (as indicated in the set subtree accessibility request).
087   * Bind operations will not be allowed for any user in the specified subtree.
088   */
089  READ_ONLY_BIND_DENIED(2, "read-only-bind-denied"),
090
091
092
093  /**
094   * Indicates that the subtree should be made hidden so that is is not
095   * accessible to most clients for any kinds of operations.  The subtree will
096   * be available to one specified user (as indicated in the set subtree
097   * accessibility request) for add, compare, delete, modify, modify DN, and
098   * search operations.  Bind operations will not be allowed for any user in a
099   * hidden subtree.
100   */
101  HIDDEN(3, "hidden");
102
103
104
105  // The integer value for this subtree accessibility state.
106  private final int intValue;
107
108  // The name for this subtree accessibility state.
109  private final String stateName;
110
111
112
113  /**
114   * Creates a new subtree accessibility state with the provided integer value.
115   *
116   * @param  intValue   The integer value for this subtree accessibility state.
117   * @param  stateName  The name for this subtree accessibility state.
118   */
119  SubtreeAccessibilityState(final int intValue, final String stateName)
120  {
121    this.intValue  = intValue;
122    this.stateName = stateName;
123  }
124
125
126
127  /**
128   * Retrieves the integer value for this subtree accessibility state.
129   *
130   * @return  The integer value for this subtree accessibility state.
131   */
132  public int intValue()
133  {
134    return intValue;
135  }
136
137
138
139  /**
140   * Retrieves the name for this subtree accessibility state.
141   *
142   * @return  The name for this subtree accessibility state.
143   */
144  public String getStateName()
145  {
146    return stateName;
147  }
148
149
150
151  /**
152   * Indicates whether this state object represents the ACCESSIBLE state.
153   *
154   * @return  {@code true} if this state object represents the ACCESSIBLE state,
155   *          or {@code false} if not.
156   */
157  public boolean isAccessible()
158  {
159    return (this == ACCESSIBLE);
160  }
161
162
163
164  /**
165   * Indicates whether this state object represents the HIDDEN state.
166   *
167   * @return  {@code true} if this state object represents the HIDDEN state,
168   *          or {@code false} if not.
169   */
170  public boolean isHidden()
171  {
172    return (this == HIDDEN);
173  }
174
175
176
177  /**
178   * Indicates whether this state object represents one of the read-only states.
179   *
180   * @return  {@code true} if this state object represents one of the read-only
181   *          states, or {@code false} if not.
182   */
183  public boolean isReadOnly()
184  {
185    return ((this == READ_ONLY_BIND_ALLOWED) ||
186            (this == READ_ONLY_BIND_DENIED));
187  }
188
189
190
191  /**
192   * Retrieves the subtree accessibility state with the specified integer value.
193   *
194   * @param  intValue  The integer value for the state to retrieve.
195   *
196   * @return  The subtree accessibility state with the specified integer value,
197   *          or {@code null} if there is no accessibility state with the
198   *          specified integer value.
199   */
200  public static SubtreeAccessibilityState valueOf(final int intValue)
201  {
202    switch (intValue)
203    {
204      case 0:
205        return ACCESSIBLE;
206      case 1:
207        return READ_ONLY_BIND_ALLOWED;
208      case 2:
209        return READ_ONLY_BIND_DENIED;
210      case 3:
211        return HIDDEN;
212      default:
213        return null;
214    }
215  }
216
217
218
219  /**
220   * Retrieves the subtree accessibility state with the provided name.
221   *
222   * @param  name  The name for the subtree accessibility state to retrieve.  It
223   *               must not be {@code null}.
224   *
225   * @return  The subtree accessibility state with the specified name, or
226   *          {@code null} if no state has the provided name.
227   */
228  public static SubtreeAccessibilityState forName(final String name)
229  {
230    switch (StaticUtils.toLowerCase(name))
231    {
232      case "accessible":
233        return ACCESSIBLE;
234      case "readonlybindallowed":
235      case "read-only-bind-allowed":
236      case "read_only_bind_allowed":
237        return READ_ONLY_BIND_ALLOWED;
238      case "readonlybinddenied":
239      case "read-only-bind-denied":
240      case "read_only_bind_denied":
241        return READ_ONLY_BIND_DENIED;
242      case "hidden":
243        return HIDDEN;
244      default:
245        return null;
246    }
247  }
248
249
250
251  /**
252   * Retrieves a string representation of this subtree accessibility state.
253   *
254   * @return  A string representation of this subtree accessibility state.
255   */
256  @Override()
257  public String toString()
258  {
259    return stateName;
260  }
261}