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 java.io.Serializable;
026 import java.util.Date;
027
028 import com.unboundid.util.NotMutable;
029 import com.unboundid.util.StaticUtils;
030 import com.unboundid.util.ThreadSafety;
031 import com.unboundid.util.ThreadSafetyLevel;
032
033
034
035 /**
036 * <BLOCKQUOTE>
037 * <B>NOTE:</B> This class is part of the Commercial Edition of the UnboundID
038 * LDAP SDK for Java. It is not available for use in applications that
039 * include only the Standard Edition of the LDAP SDK, and is not supported for
040 * use in conjunction with non-UnboundID products.
041 * </BLOCKQUOTE>
042 * This class defines a data structure with information about a subtree with
043 * restricted access, as may be included in a
044 * {@link GetSubtreeAccessibilityExtendedResult}.
045 */
046 @NotMutable()
047 @ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
048 public final class SubtreeAccessibilityRestriction
049 implements Serializable
050 {
051 /**
052 * The serial version UID for this serializable class.
053 */
054 private static final long serialVersionUID = -1893365464740536092L;
055
056
057
058 // The time the subtree accessibility restriction was created.
059 private final Date effectiveTime;
060
061 // The DN of a user allowed to bypass any associated restrictions.
062 private final String bypassUserDN;
063
064 // The base DN of the affected subtree.
065 private final String subtreeBaseDN;
066
067 // The accessibility state of the affected subtree.
068 private final SubtreeAccessibilityState accessibilityState;
069
070
071
072 /**
073 * Creates a new subtree accessibility restriction object with the provided
074 * information.
075 *
076 * @param subtreeBaseDN The base DN of the affected subtree.
077 * @param accessibilityState The accessibility state of the affected
078 * subtree.
079 * @param bypassUserDN The DN of a user allowed to bypass any
080 * associated restrictions, if defined.
081 * @param effectiveTime The time this restriction was put into place.
082 */
083 public SubtreeAccessibilityRestriction(final String subtreeBaseDN,
084 final SubtreeAccessibilityState accessibilityState,
085 final String bypassUserDN, final Date effectiveTime)
086 {
087 this.subtreeBaseDN = subtreeBaseDN;
088 this.accessibilityState = accessibilityState;
089 this.bypassUserDN = bypassUserDN;
090 this.effectiveTime = effectiveTime;
091 }
092
093
094
095 /**
096 * Retrieves the base DN for the affected subtree.
097 *
098 * @return The base DN for the affected subtree.
099 */
100 public String getSubtreeBaseDN()
101 {
102 return subtreeBaseDN;
103 }
104
105
106
107 /**
108 * Retrieves the accessibility state for the affected subtree.
109 *
110 * @return The accessibility state for the affected subtree.
111 */
112 public SubtreeAccessibilityState getAccessibilityState()
113 {
114 return accessibilityState;
115 }
116
117
118
119 /**
120 * Retrieves the DN of a user that will be allowed to bypass any restrictions
121 * on the affected subtree.
122 *
123 * @return The DN of a user that will be allowed to bypass any restrictions
124 * on the affected subtree, or {@code null} if no bypass user is
125 * defined.
126 */
127 public String getBypassUserDN()
128 {
129 return bypassUserDN;
130 }
131
132
133
134 /**
135 * Retrieves the time the accessibility restriction was put into place.
136 *
137 * @return The time the accessibility restriction was put into place.
138 */
139 public Date getEffectiveTime()
140 {
141 return effectiveTime;
142 }
143
144
145
146 /**
147 * Retrieves a string representation of this accessibility restriction.
148 *
149 * @return A string representation of this accessibility restriction.
150 */
151 @Override()
152 public String toString()
153 {
154 final StringBuilder buffer = new StringBuilder();
155 toString(buffer);
156 return buffer.toString();
157 }
158
159
160
161 /**
162 * Appends a string representation of this accessibility restriction to the
163 * provided buffer.
164 *
165 * @param buffer The buffer to which the information should be appended.
166 */
167 public void toString(final StringBuilder buffer)
168 {
169 buffer.append("SubtreeAccessibilityRestriction(base='");
170 buffer.append(subtreeBaseDN.replace("\\\"", "\\22"));
171 buffer.append("', state='");
172 buffer.append(accessibilityState.getStateName());
173 buffer.append('\'');
174
175 if (bypassUserDN != null)
176 {
177 buffer.append(", bypassUser='");
178 buffer.append(bypassUserDN.replace("\\\"", "\\22"));
179 buffer.append('\'');
180 }
181
182 buffer.append(", effectiveTime='");
183 buffer.append(StaticUtils.encodeGeneralizedTime(effectiveTime));
184 buffer.append("')");
185 }
186 }