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 java.io.Serializable;
041import java.util.Date;
042
043import com.unboundid.util.NotMutable;
044import com.unboundid.util.NotNull;
045import com.unboundid.util.Nullable;
046import com.unboundid.util.StaticUtils;
047import com.unboundid.util.ThreadSafety;
048import com.unboundid.util.ThreadSafetyLevel;
049
050
051
052/**
053 * This class defines a data structure with information about a subtree with
054 * restricted access, as may be included in a
055 * {@link GetSubtreeAccessibilityExtendedResult}.
056 * <BR>
057 * <BLOCKQUOTE>
058 *   <B>NOTE:</B>  This class, and other classes within the
059 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
060 *   supported for use against Ping Identity, UnboundID, and
061 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
062 *   for proprietary functionality or for external specifications that are not
063 *   considered stable or mature enough to be guaranteed to work in an
064 *   interoperable way with other types of LDAP servers.
065 * </BLOCKQUOTE>
066 */
067@NotMutable()
068@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
069public final class SubtreeAccessibilityRestriction
070       implements Serializable
071{
072  /**
073   * The serial version UID for this serializable class.
074   */
075  private static final long serialVersionUID = -1893365464740536092L;
076
077
078
079  // The time the subtree accessibility restriction was created.
080  @NotNull private final Date effectiveTime;
081
082  // The DN of a user allowed to bypass any associated restrictions.
083  @Nullable private final String bypassUserDN;
084
085  // The base DN of the affected subtree.
086  @NotNull private final String subtreeBaseDN;
087
088  // The accessibility state of the affected subtree.
089  @NotNull private final SubtreeAccessibilityState accessibilityState;
090
091
092
093  /**
094   * Creates a new subtree accessibility restriction object with the provided
095   * information.
096   *
097   * @param  subtreeBaseDN       The base DN of the affected subtree.
098   * @param  accessibilityState  The accessibility state of the affected
099   *                             subtree.
100   * @param  bypassUserDN        The DN of a user allowed to bypass any
101   *                             associated restrictions, if defined.
102   * @param  effectiveTime       The time this restriction was put into place.
103   */
104  public SubtreeAccessibilityRestriction(@NotNull final String subtreeBaseDN,
105              @NotNull final SubtreeAccessibilityState accessibilityState,
106              @Nullable final String bypassUserDN,
107              @NotNull final Date effectiveTime)
108  {
109    this.subtreeBaseDN      = subtreeBaseDN;
110    this.accessibilityState = accessibilityState;
111    this.bypassUserDN       = bypassUserDN;
112    this.effectiveTime      = effectiveTime;
113  }
114
115
116
117  /**
118   * Retrieves the base DN for the affected subtree.
119   *
120   * @return  The base DN for the affected subtree.
121   */
122  @NotNull()
123  public String getSubtreeBaseDN()
124  {
125    return subtreeBaseDN;
126  }
127
128
129
130  /**
131   * Retrieves the accessibility state for the affected subtree.
132   *
133   * @return  The accessibility state for the affected subtree.
134   */
135  @NotNull()
136  public SubtreeAccessibilityState getAccessibilityState()
137  {
138    return accessibilityState;
139  }
140
141
142
143  /**
144   * Retrieves the DN of a user that will be allowed to bypass any restrictions
145   * on the affected subtree.
146   *
147   * @return  The DN of a user that will be allowed to bypass any restrictions
148   *          on the affected subtree, or {@code null} if no bypass user is
149   *          defined.
150   */
151  @Nullable()
152  public String getBypassUserDN()
153  {
154    return bypassUserDN;
155  }
156
157
158
159  /**
160   * Retrieves the time the accessibility restriction was put into place.
161   *
162   * @return  The time the accessibility restriction was put into place.
163   */
164  @NotNull()
165  public Date getEffectiveTime()
166  {
167    return effectiveTime;
168  }
169
170
171
172  /**
173   * Retrieves a string representation of this accessibility restriction.
174   *
175   * @return  A string representation of this accessibility restriction.
176   */
177  @Override()
178  @NotNull()
179  public String toString()
180  {
181    final StringBuilder buffer = new StringBuilder();
182    toString(buffer);
183    return buffer.toString();
184  }
185
186
187
188  /**
189   * Appends a string representation of this accessibility restriction to the
190   * provided buffer.
191   *
192   * @param  buffer  The buffer to which the information should be appended.
193   */
194  public void toString(@NotNull final StringBuilder buffer)
195  {
196    buffer.append("SubtreeAccessibilityRestriction(base='");
197    buffer.append(subtreeBaseDN.replace("\\\"", "\\22"));
198    buffer.append("', state='");
199    buffer.append(accessibilityState.getStateName());
200    buffer.append('\'');
201
202    if (bypassUserDN != null)
203    {
204      buffer.append(", bypassUser='");
205      buffer.append(bypassUserDN.replace("\\\"", "\\22"));
206      buffer.append('\'');
207    }
208
209    buffer.append(", effectiveTime='");
210    buffer.append(StaticUtils.encodeGeneralizedTime(effectiveTime));
211    buffer.append("')");
212  }
213}