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