001    /*
002     * Copyright 2012-2015 UnboundID Corp.
003     * All Rights Reserved.
004     */
005    /*
006     * Copyright (C) 2015 UnboundID Corp.
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     */
021    package com.unboundid.ldap.sdk.unboundidds.extensions;
022    
023    
024    
025    import com.unboundid.util.StaticUtils;
026    
027    
028    
029    /**
030     * <BLOCKQUOTE>
031     *   <B>NOTE:</B>  This class is part of the Commercial Edition of the UnboundID
032     *   LDAP SDK for Java.  It is not available for use in applications that
033     *   include only the Standard Edition of the LDAP SDK, and is not supported for
034     *   use in conjunction with non-UnboundID products.
035     * </BLOCKQUOTE>
036     * This enum defines the set of allowed accessibility states that may be used
037     * with the {@link SetSubtreeAccessibilityExtendedRequest}.
038     */
039    public enum SubtreeAccessibilityState
040    {
041      /**
042       * Indicates that the subtree should return to normal accessibility so that
043       * all appropriately-authorized users will be able to perform all kinds of
044       * operations in the target subtree.
045       */
046      ACCESSIBLE(0, "accessible"),
047    
048    
049    
050      /**
051       * Indicates that the subtree should be made read-only so that search and
052       * compare operations targeting those entries will be allowed, but add,
053       * delete, modify, and modify DN operations will only be allowed for one
054       * specified user (as indicated in the set subtree accessibility request).
055       * Bind operations will be allowed, but any changes intended to update
056       * password policy or other account state (e.g., to record failed
057       * authentication attempts or update last login time) will not be applied.
058       */
059      READ_ONLY_BIND_ALLOWED(1, "read-only-bind-allowed"),
060    
061    
062    
063      /**
064       * Indicates that the subtree should be made read-only so that search and
065       * compare operations targeting those entries will be allowed, but add,
066       * delete, modify, and modify DN operations will only be allowed for one
067       * specified user (as indicated in the set subtree accessibility request).
068       * Bind operations will not be allowed for any user in the specified subtree.
069       */
070      READ_ONLY_BIND_DENIED(2, "read-only-bind-denied"),
071    
072    
073    
074      /**
075       * Indicates that the subtree should be made hidden so that is is not
076       * accessible to most clients for any kinds of operations.  The subtree will
077       * be available to one specified user (as indicated in the set subtree
078       * accessibility request) for add, compare, delete, modify, modify DN, and
079       * search operations.  Bind operations will not be allowed for any user in a
080       * hidden subtree.
081       */
082      HIDDEN(3, "hidden");
083    
084    
085    
086      // The integer value for this subtree accessibility state.
087      private final int intValue;
088    
089      // The name for this subtree accessibility state.
090      private final String stateName;
091    
092    
093    
094      /**
095       * Creates a new subtree accessibility state with the provided integer value.
096       *
097       * @param  intValue   The integer value for this subtree accessibility state.
098       * @param  stateName  The name for this subtree accessibility state.
099       */
100      SubtreeAccessibilityState(final int intValue, final String stateName)
101      {
102        this.intValue  = intValue;
103        this.stateName = stateName;
104      }
105    
106    
107    
108      /**
109       * Retrieves the integer value for this subtree accessibility state.
110       *
111       * @return  The integer value for this subtree accessibility state.
112       */
113      public int intValue()
114      {
115        return intValue;
116      }
117    
118    
119    
120      /**
121       * Retrieves the name for this subtree accessibility state.
122       *
123       * @return  The name for this subtree accessibility state.
124       */
125      public String getStateName()
126      {
127        return stateName;
128      }
129    
130    
131    
132      /**
133       * Indicates whether this state object represents the ACCESSIBLE state.
134       *
135       * @return  {@code true} if this state object represents the ACCESSIBLE state,
136       *          or {@code false} if not.
137       */
138      public boolean isAccessible()
139      {
140        return (this == ACCESSIBLE);
141      }
142    
143    
144    
145      /**
146       * Indicates whether this state object represents the HIDDEN state.
147       *
148       * @return  {@code true} if this state object represents the HIDDEN state,
149       *          or {@code false} if not.
150       */
151      public boolean isHidden()
152      {
153        return (this == HIDDEN);
154      }
155    
156    
157    
158      /**
159       * Indicates whether this state object represents one of the read-only states.
160       *
161       * @return  {@code true} if this state object represents one of the read-only
162       *          states, or {@code false} if not.
163       */
164      public boolean isReadOnly()
165      {
166        return ((this == READ_ONLY_BIND_ALLOWED) ||
167                (this == READ_ONLY_BIND_DENIED));
168      }
169    
170    
171    
172      /**
173       * Retrieves the subtree accessibility state with the specified integer value.
174       *
175       * @param  intValue  The integer value for the state to retrieve.
176       *
177       * @return  The subtree accessibility state with the specified integer value,
178       *          or {@code null} if there is no accessibility state with the
179       *          specified integer value.
180       */
181      public static SubtreeAccessibilityState valueOf(final int intValue)
182      {
183        switch (intValue)
184        {
185          case 0:
186            return ACCESSIBLE;
187          case 1:
188            return READ_ONLY_BIND_ALLOWED;
189          case 2:
190            return READ_ONLY_BIND_DENIED;
191          case 3:
192            return HIDDEN;
193          default:
194            return null;
195        }
196      }
197    
198    
199    
200      /**
201       * Retrieves the subtree accessibility state with the provided name.
202       *
203       * @param  name  The name for the subtree accessibility state to retrieve.
204       *
205       * @return  The subtree accessibility state with the specified name, or
206       *          {@code null} if no state has the provided name.
207       */
208      public static SubtreeAccessibilityState forName(final String name)
209      {
210        final String lowerName = StaticUtils.toLowerCase(name).replace('_', '-');
211        for (final SubtreeAccessibilityState s : values())
212        {
213          if (s.stateName.equals(lowerName))
214          {
215            return s;
216          }
217        }
218    
219        return null;
220      }
221    
222    
223    
224      /**
225       * Retrieves a string representation of this subtree accessibility state.
226       *
227       * @return  A string representation of this subtree accessibility state.
228       */
229      @Override()
230      public String toString()
231      {
232        return stateName;
233      }
234    }