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