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