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