001/*
002 * Copyright 2008-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.tasks;
022
023
024
025import java.util.ArrayList;
026import java.util.Collections;
027import java.util.Date;
028import java.util.LinkedHashMap;
029import java.util.List;
030import java.util.Map;
031
032import com.unboundid.ldap.sdk.Attribute;
033import com.unboundid.ldap.sdk.Entry;
034import com.unboundid.util.NotMutable;
035import com.unboundid.util.StaticUtils;
036import com.unboundid.util.ThreadSafety;
037import com.unboundid.util.ThreadSafetyLevel;
038
039import static com.unboundid.ldap.sdk.unboundidds.tasks.TaskMessages.*;
040
041
042
043/**
044 * This class defines a Directory Server task that can be used to cause the
045 * server to leave lockdown mode and resume normal operation.  Note that because
046 * of the nature of lockdown mode, it this task may only be requested by a user
047 * with the lockdown-mode privilege.  Alternately, the server may be restarted
048 * and it will not be placed in lockdown mode at startup unless a significant
049 * problem is encountered in which there may be a risk of unauthorized access to
050 * data.
051 * <BR>
052 * <BLOCKQUOTE>
053 *   <B>NOTE:</B>  This class, and other classes within the
054 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
055 *   supported for use against Ping Identity, UnboundID, and
056 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
057 *   for proprietary functionality or for external specifications that are not
058 *   considered stable or mature enough to be guaranteed to work in an
059 *   interoperable way with other types of LDAP servers.
060 * </BLOCKQUOTE>
061 * <BR>
062 * The leave lockdown mode task does not have any task-specific properties.  See
063 * the {@link EnterLockdownModeTask} class for more information about lockdown
064 * mode and a task that may be used to force the server to enter this state.
065 */
066@NotMutable()
067@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
068public final class LeaveLockdownModeTask
069       extends Task
070{
071  /**
072   * The fully-qualified name of the Java class that is used for the leave
073   * lockdown mode task.
074   */
075  static final String LEAVE_LOCKDOWN_MODE_TASK_CLASS =
076       "com.unboundid.directory.server.tasks.LeaveLockdownModeTask";
077
078
079
080  /**
081   * The name of the attribute used to specify the reason for taking the server
082   * out of lockdown mode.
083   */
084  private static final String ATTR_LEAVE_LOCKDOWN_REASON =
085       "ds-task-leave-lockdown-reason";
086
087
088
089  /**
090   * The task property for the leave-lockdown reason.
091   */
092  private static final TaskProperty PROPERTY_LEAVE_LOCKDOWN_REASON =
093       new TaskProperty(ATTR_LEAVE_LOCKDOWN_REASON,
094                        INFO_DISPLAY_NAME_LEAVE_LOCKDOWN_REASON.get(),
095                        INFO_DESCRIPTION_LEAVE_LOCKDOWN_REASON.get(),
096                        String.class, false, false, false);
097
098
099
100  /**
101   * The name of the object class used in leave-lockdown-mode task entries.
102   */
103  private static final String OC_LEAVE_LOCKDOWN_MODE_TASK =
104      "ds-task-leave-lockdown-mode";
105
106
107
108  /**
109   * The serial version UID for this serializable class.
110   */
111  private static final long serialVersionUID = -1353712468653879793L;
112
113
114
115  // The reason for leaving lockdown mode.
116  private final String reason;
117
118
119
120  /**
121   * Creates a new uninitialized enter lockdown mode task instance which should
122   * only be used for obtaining general information about this task, including
123   * the task name, description, and supported properties.  Attempts to use a
124   * task created with this constructor for any other reason will likely fail.
125   */
126  public LeaveLockdownModeTask()
127  {
128    reason = null;
129  }
130
131
132
133  /**
134   * Creates a new leave lockdown mode task with the specified task ID.
135   *
136   * @param  taskID  The task ID to use for this task.  If it is {@code null}
137   *                 then a UUID will be generated for use as the task ID.
138   */
139  public LeaveLockdownModeTask(final String taskID)
140  {
141    this(taskID, null);
142  }
143
144
145
146  /**
147   * Creates a new leave lockdown mode task with the specified task ID.
148   *
149   * @param  taskID  The task ID to use for this task.  If it is {@code null}
150   *                 then a UUID will be generated for use as the task ID.
151   * @param  reason  The user-specified reason for leaving lockdown mode. This
152   *                 may be {@code null}.
153   */
154  public LeaveLockdownModeTask(final String taskID, final String reason)
155  {
156    this(taskID, reason, null, null, null, null, null);
157  }
158
159
160
161  /**
162   * Creates a new leave lockdown mode task with the provided information.
163   *
164   * @param  taskID                  The task ID to use for this task.  If it is
165   *                                 {@code null} then a UUID will be generated
166   *                                 for use as the task ID.
167   * @param  scheduledStartTime      The time that this task should start
168   *                                 running.
169   * @param  dependencyIDs           The list of task IDs that will be required
170   *                                 to complete before this task will be
171   *                                 eligible to start.
172   * @param  failedDependencyAction  Indicates what action should be taken if
173   *                                 any of the dependencies for this task do
174   *                                 not complete successfully.
175   * @param  notifyOnCompletion      The list of e-mail addresses of individuals
176   *                                 that should be notified when this task
177   *                                 completes.
178   * @param  notifyOnError           The list of e-mail addresses of individuals
179   *                                 that should be notified if this task does
180   *                                 not complete successfully.
181   */
182  public LeaveLockdownModeTask(final String taskID,
183              final Date scheduledStartTime, final List<String> dependencyIDs,
184              final FailedDependencyAction failedDependencyAction,
185              final List<String> notifyOnCompletion,
186              final List<String> notifyOnError)
187  {
188    this(taskID, null, scheduledStartTime, dependencyIDs,
189         failedDependencyAction, notifyOnCompletion, notifyOnError);
190  }
191
192
193
194  /**
195   * Creates a new leave lockdown mode task with the provided information.
196   *
197   * @param  taskID                  The task ID to use for this task.  If it is
198   *                                 {@code null} then a UUID will be generated
199   *                                 for use as the task ID.
200   * @param  reason                  The user-specified reason for leaving
201   *                                 lockdown mode. This may be {@code null}.
202   * @param  scheduledStartTime      The time that this task should start
203   *                                 running.
204   * @param  dependencyIDs           The list of task IDs that will be required
205   *                                 to complete before this task will be
206   *                                 eligible to start.
207   * @param  failedDependencyAction  Indicates what action should be taken if
208   *                                 any of the dependencies for this task do
209   *                                 not complete successfully.
210   * @param  notifyOnCompletion      The list of e-mail addresses of individuals
211   *                                 that should be notified when this task
212   *                                 completes.
213   * @param  notifyOnError           The list of e-mail addresses of individuals
214   *                                 that should be notified if this task does
215   *                                 not complete successfully.
216   */
217  public LeaveLockdownModeTask(final String taskID, final String reason,
218              final Date scheduledStartTime, final List<String> dependencyIDs,
219              final FailedDependencyAction failedDependencyAction,
220              final List<String> notifyOnCompletion,
221              final List<String> notifyOnError)
222  {
223    this(taskID, reason, scheduledStartTime, dependencyIDs,
224         failedDependencyAction, null, notifyOnCompletion, null,
225         notifyOnError, null, null, null);
226  }
227
228
229
230  /**
231   * Creates a new leave lockdown mode task with the provided information.
232   *
233   * @param  taskID                  The task ID to use for this task.  If it is
234   *                                 {@code null} then a UUID will be generated
235   *                                 for use as the task ID.
236   * @param  reason                  The user-specified reason for leaving
237   *                                 lockdown mode. This may be {@code null}.
238   * @param  scheduledStartTime      The time that this task should start
239   *                                 running.
240   * @param  dependencyIDs           The list of task IDs that will be required
241   *                                 to complete before this task will be
242   *                                 eligible to start.
243   * @param  failedDependencyAction  Indicates what action should be taken if
244   *                                 any of the dependencies for this task do
245   *                                 not complete successfully.
246   * @param  notifyOnStart           The list of e-mail addresses of individuals
247   *                                 that should be notified when this task
248   *                                 starts running.
249   * @param  notifyOnCompletion      The list of e-mail addresses of individuals
250   *                                 that should be notified when this task
251   *                                 completes.
252   * @param  notifyOnSuccess         The list of e-mail addresses of individuals
253   *                                 that should be notified if this task
254   *                                 completes successfully.
255   * @param  notifyOnError           The list of e-mail addresses of individuals
256   *                                 that should be notified if this task does
257   *                                 not complete successfully.
258   * @param  alertOnStart            Indicates whether the server should send an
259   *                                 alert notification when this task starts.
260   * @param  alertOnSuccess          Indicates whether the server should send an
261   *                                 alert notification if this task completes
262   *                                 successfully.
263   * @param  alertOnError            Indicates whether the server should send an
264   *                                 alert notification if this task fails to
265   *                                 complete successfully.
266   */
267  public LeaveLockdownModeTask(final String taskID, final String reason,
268              final Date scheduledStartTime, final List<String> dependencyIDs,
269              final FailedDependencyAction failedDependencyAction,
270              final List<String> notifyOnStart,
271              final List<String> notifyOnCompletion,
272              final List<String> notifyOnSuccess,
273              final List<String> notifyOnError, final Boolean alertOnStart,
274              final Boolean alertOnSuccess, final Boolean alertOnError)
275  {
276    super(taskID, LEAVE_LOCKDOWN_MODE_TASK_CLASS, scheduledStartTime,
277         dependencyIDs, failedDependencyAction, notifyOnStart,
278         notifyOnCompletion, notifyOnSuccess, notifyOnError, alertOnStart,
279         alertOnSuccess, alertOnError);
280
281    this.reason = reason;
282  }
283
284
285
286  /**
287   * Creates a new leave lockdown mode task from the provided entry.
288   *
289   * @param  entry  The entry to use to create this leave lockdown mode task.
290   *
291   * @throws  TaskException  If the provided entry cannot be parsed as a leave
292   *                         lockdown mode task entry.
293   */
294  public LeaveLockdownModeTask(final Entry entry)
295         throws TaskException
296  {
297    super(entry);
298
299    // Get the "reason" string if it is present.
300    reason = entry.getAttributeValue(ATTR_LEAVE_LOCKDOWN_REASON);
301  }
302
303
304
305  /**
306   * Creates a new leave lockdown mode task from the provided set of task
307   * properties.
308   *
309   * @param  properties  The set of task properties and their corresponding
310   *                     values to use for the task.  It must not be
311   *                     {@code null}.
312   *
313   * @throws  TaskException  If the provided set of properties cannot be used to
314   *                         create a valid leave lockdown mode task.
315   */
316  public LeaveLockdownModeTask(final Map<TaskProperty,List<Object>> properties)
317         throws TaskException
318  {
319    super(LEAVE_LOCKDOWN_MODE_TASK_CLASS, properties);
320
321    String r = null;
322    for (final Map.Entry<TaskProperty,List<Object>> entry :
323            properties.entrySet())
324    {
325      final TaskProperty p = entry.getKey();
326      final String attrName = p.getAttributeName();
327      final List<Object> values = entry.getValue();
328
329      if (attrName.equalsIgnoreCase(ATTR_LEAVE_LOCKDOWN_REASON))
330      {
331        r = parseString(p, values, null);
332        break;
333      }
334    }
335
336    reason = r;
337  }
338
339
340
341  /**
342   * Retrieves the user-specified reason why the server is leaving lockdown
343   * mode.
344   *
345   * @return  The reason the server is leaving lockdown mode, or {@code null}
346   *          if none was specified.
347   */
348  public String getReason()
349  {
350    return reason;
351  }
352
353
354
355  /**
356   * {@inheritDoc}
357   */
358  @Override()
359  public String getTaskName()
360  {
361    return INFO_TASK_NAME_LEAVE_LOCKDOWN_MODE.get();
362  }
363
364
365
366  /**
367   * {@inheritDoc}
368   */
369  @Override()
370  public String getTaskDescription()
371  {
372    return INFO_TASK_DESCRIPTION_LEAVE_LOCKDOWN_MODE.get();
373  }
374
375
376
377  /**
378   * {@inheritDoc}
379   */
380  @Override()
381  protected List<String> getAdditionalObjectClasses()
382  {
383    return Collections.singletonList(OC_LEAVE_LOCKDOWN_MODE_TASK);
384  }
385
386
387
388  /**
389   * {@inheritDoc}
390   */
391  @Override()
392  protected List<Attribute> getAdditionalAttributes()
393  {
394    final ArrayList<Attribute> attrs = new ArrayList<>(1);
395    if (reason != null)
396    {
397      attrs.add(new Attribute(ATTR_LEAVE_LOCKDOWN_REASON, reason));
398    }
399    return attrs;
400  }
401
402
403
404  /**
405   * {@inheritDoc}
406   */
407  @Override()
408  public List<TaskProperty> getTaskSpecificProperties()
409  {
410    final List<TaskProperty> propList =
411              Collections.singletonList(PROPERTY_LEAVE_LOCKDOWN_REASON);
412
413    return Collections.unmodifiableList(propList);
414  }
415
416
417
418  /**
419   * {@inheritDoc}
420   */
421  @Override()
422  public Map<TaskProperty,List<Object>> getTaskPropertyValues()
423  {
424    final LinkedHashMap<TaskProperty,List<Object>> props =
425         new LinkedHashMap<>(StaticUtils.computeMapCapacity(10));
426
427    if (reason != null)
428    {
429      props.put(PROPERTY_LEAVE_LOCKDOWN_REASON,
430              Collections.<Object>singletonList(reason));
431    }
432
433    props.putAll(super.getTaskPropertyValues());
434    return Collections.unmodifiableMap(props);
435  }
436}