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 enter lockdown mode, in which case it will only allow requests 045 * from users with the lockdown-mode privilege. Lockdown mode is intended to 046 * allow administrators to perform operations with the server online but without 047 * worrying about the impact that those operations may have on other users. In 048 * In some special cases, the server may place itself in lockdown mode as a 049 * defense mechanism rather than risking the exposure of sensitive information. 050 * For example, if the server detects any malformed access control rules at 051 * startup, then it will place itself in lockdown mode rather than attempt to 052 * run without that rule in effect since it could have been intended to prevent 053 * unauthorized users from accessing certain data. 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 * <BR> 065 * The enter lockdown mode task does not have any task-specific properties. See 066 * the {@link LeaveLockdownModeTask} class for the corresponding mechanism to 067 * bring the server out of lockdown mode. 068 */ 069@NotMutable() 070@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE) 071public final class EnterLockdownModeTask 072 extends Task 073{ 074 /** 075 * The fully-qualified name of the Java class that is used for the enter 076 * lockdown mode task. 077 */ 078 static final String ENTER_LOCKDOWN_MODE_TASK_CLASS = 079 "com.unboundid.directory.server.tasks.EnterLockdownModeTask"; 080 081 082 083 /** 084 * The name of the attribute used to specify the reason for putting the server 085 * into lockdown mode. 086 */ 087 private static final String ATTR_ENTER_LOCKDOWN_REASON = 088 "ds-task-enter-lockdown-reason"; 089 090 091 092 /** 093 * The task property for the enter-lockdown reason. 094 */ 095 private static final TaskProperty PROPERTY_ENTER_LOCKDOWN_REASON = 096 new TaskProperty(ATTR_ENTER_LOCKDOWN_REASON, 097 INFO_DISPLAY_NAME_ENTER_LOCKDOWN_REASON.get(), 098 INFO_DESCRIPTION_ENTER_LOCKDOWN_REASON.get(), 099 String.class, false, false, false); 100 101 102 103 /** 104 * The name of the object class used in enter-lockdown-mode task entries. 105 */ 106 private static final String OC_ENTER_LOCKDOWN_MODE_TASK = 107 "ds-task-enter-lockdown-mode"; 108 109 110 111 /** 112 * The serial version UID for this serializable class. 113 */ 114 private static final long serialVersionUID = -4104020769734351458L; 115 116 117 118 // The reason for entering lockdown mode. 119 private final String reason; 120 121 122 123 /** 124 * Creates a new uninitialized enter lockdown mode task instance which should 125 * only be used for obtaining general information about this task, including 126 * the task name, description, and supported properties. Attempts to use a 127 * task created with this constructor for any other reason will likely fail. 128 */ 129 public EnterLockdownModeTask() 130 { 131 reason = null; 132 } 133 134 135 136 /** 137 * Creates a new enter lockdown mode task with the specified task ID. 138 * 139 * @param taskID The task ID to use for this task. If it is {@code null} 140 * then a UUID will be generated for use as the task ID. 141 */ 142 public EnterLockdownModeTask(final String taskID) 143 { 144 this(taskID, null); 145 } 146 147 148 149 /** 150 * Creates a new enter lockdown mode task with the specified task ID. 151 * 152 * @param taskID The task ID to use for this task. If it is {@code null} 153 * then a UUID will be generated for use as the task ID. 154 * @param reason The user-specified reason for entering lockdown mode. This 155 * may be {@code null}. 156 */ 157 public EnterLockdownModeTask(final String taskID, final String reason) 158 { 159 this(taskID, reason, null, null, null, null, null); 160 } 161 162 163 164 /** 165 * Creates a new enter lockdown mode task with the provided information. 166 * 167 * @param taskID The task ID to use for this task. If it is 168 * {@code null} then a UUID will be generated 169 * for use as the task ID. 170 * @param scheduledStartTime The time that this task should start 171 * running. 172 * @param dependencyIDs The list of task IDs that will be required 173 * to complete before this task will be 174 * eligible to start. 175 * @param failedDependencyAction Indicates what action should be taken if 176 * any of the dependencies for this task do 177 * not complete successfully. 178 * @param notifyOnCompletion The list of e-mail addresses of individuals 179 * that should be notified when this task 180 * completes. 181 * @param notifyOnError The list of e-mail addresses of individuals 182 * that should be notified if this task does 183 * not complete successfully. 184 */ 185 public EnterLockdownModeTask(final String taskID, 186 final Date scheduledStartTime, final List<String> dependencyIDs, 187 final FailedDependencyAction failedDependencyAction, 188 final List<String> notifyOnCompletion, 189 final List<String> notifyOnError) 190 { 191 this(taskID, null, scheduledStartTime, dependencyIDs, 192 failedDependencyAction, notifyOnCompletion, notifyOnError); 193 } 194 195 196 197 /** 198 * Creates a new enter lockdown mode task with the provided information. 199 * 200 * @param taskID The task ID to use for this task. If it is 201 * {@code null} then a UUID will be generated 202 * for use as the task ID. 203 * @param reason The user-specified reason for entering 204 * lockdown mode. This may be {@code null}. 205 * @param scheduledStartTime The time that this task should start 206 * running. 207 * @param dependencyIDs The list of task IDs that will be required 208 * to complete before this task will be 209 * eligible to start. 210 * @param failedDependencyAction Indicates what action should be taken if 211 * any of the dependencies for this task do 212 * not complete successfully. 213 * @param notifyOnCompletion The list of e-mail addresses of individuals 214 * that should be notified when this task 215 * completes. 216 * @param notifyOnError The list of e-mail addresses of individuals 217 * that should be notified if this task does 218 * not complete successfully. 219 */ 220 public EnterLockdownModeTask(final String taskID, final String reason, 221 final Date scheduledStartTime, final List<String> dependencyIDs, 222 final FailedDependencyAction failedDependencyAction, 223 final List<String> notifyOnCompletion, 224 final List<String> notifyOnError) 225 { 226 this(taskID, reason, scheduledStartTime, dependencyIDs, 227 failedDependencyAction, null, notifyOnCompletion, null, 228 notifyOnError, null, null, null); 229 } 230 231 232 233 /** 234 * Creates a new enter lockdown mode task with the provided information. 235 * 236 * @param taskID The task ID to use for this task. If it is 237 * {@code null} then a UUID will be generated 238 * for use as the task ID. 239 * @param reason The user-specified reason for entering 240 * lockdown mode. This may be {@code null}. 241 * @param scheduledStartTime The time that this task should start 242 * running. 243 * @param dependencyIDs The list of task IDs that will be required 244 * to complete before this task will be 245 * eligible to start. 246 * @param failedDependencyAction Indicates what action should be taken if 247 * any of the dependencies for this task do 248 * not complete successfully. 249 * @param notifyOnStart The list of e-mail addresses of individuals 250 * that should be notified when this task 251 * starts running. 252 * @param notifyOnCompletion The list of e-mail addresses of individuals 253 * that should be notified when this task 254 * completes. 255 * @param notifyOnSuccess The list of e-mail addresses of individuals 256 * that should be notified if this task 257 * completes successfully. 258 * @param notifyOnError The list of e-mail addresses of individuals 259 * that should be notified if this task does 260 * not complete successfully. 261 * @param alertOnStart Indicates whether the server should send an 262 * alert notification when this task starts. 263 * @param alertOnSuccess Indicates whether the server should send an 264 * alert notification if this task completes 265 * successfully. 266 * @param alertOnError Indicates whether the server should send an 267 * alert notification if this task fails to 268 * complete successfully. 269 */ 270 public EnterLockdownModeTask(final String taskID, final String reason, 271 final Date scheduledStartTime, final List<String> dependencyIDs, 272 final FailedDependencyAction failedDependencyAction, 273 final List<String> notifyOnStart, 274 final List<String> notifyOnCompletion, 275 final List<String> notifyOnSuccess, 276 final List<String> notifyOnError, final Boolean alertOnStart, 277 final Boolean alertOnSuccess, final Boolean alertOnError) 278 { 279 super(taskID, ENTER_LOCKDOWN_MODE_TASK_CLASS, scheduledStartTime, 280 dependencyIDs, failedDependencyAction, notifyOnStart, 281 notifyOnCompletion, notifyOnSuccess, notifyOnError, alertOnStart, 282 alertOnSuccess, alertOnError); 283 284 this.reason = reason; 285 } 286 287 288 289 /** 290 * Creates a new enter lockdown mode task from the provided entry. 291 * 292 * @param entry The entry to use to create this enter lockdown mode task. 293 * 294 * @throws TaskException If the provided entry cannot be parsed as an enter 295 * lockdown mode task entry. 296 */ 297 public EnterLockdownModeTask(final Entry entry) 298 throws TaskException 299 { 300 super(entry); 301 302 // Get the "reason" string if it is present. 303 reason = entry.getAttributeValue(ATTR_ENTER_LOCKDOWN_REASON); 304 } 305 306 307 308 /** 309 * Creates a new enter lockdown mode task from the provided set of task 310 * properties. 311 * 312 * @param properties The set of task properties and their corresponding 313 * values to use for the task. It must not be 314 * {@code null}. 315 * 316 * @throws TaskException If the provided set of properties cannot be used to 317 * create a valid enter lockdown mode task. 318 */ 319 public EnterLockdownModeTask(final Map<TaskProperty,List<Object>> properties) 320 throws TaskException 321 { 322 super(ENTER_LOCKDOWN_MODE_TASK_CLASS, properties); 323 324 String r = null; 325 for (final Map.Entry<TaskProperty,List<Object>> entry : 326 properties.entrySet()) 327 { 328 final TaskProperty p = entry.getKey(); 329 final String attrName = p.getAttributeName(); 330 final List<Object> values = entry.getValue(); 331 332 if (attrName.equalsIgnoreCase(ATTR_ENTER_LOCKDOWN_REASON)) 333 { 334 r = parseString(p, values, null); 335 break; 336 } 337 } 338 339 reason = r; 340 } 341 342 343 344 /** 345 * Retrieves the user-specified reason why the server is entering lockdown 346 * mode. 347 * 348 * @return The reason the server is entering lockdown mode, or {@code null} 349 * if none was specified. 350 */ 351 public String getReason() 352 { 353 return reason; 354 } 355 356 357 358 /** 359 * {@inheritDoc} 360 */ 361 @Override() 362 public String getTaskName() 363 { 364 return INFO_TASK_NAME_ENTER_LOCKDOWN_MODE.get(); 365 } 366 367 368 369 /** 370 * {@inheritDoc} 371 */ 372 @Override() 373 public String getTaskDescription() 374 { 375 return INFO_TASK_DESCRIPTION_ENTER_LOCKDOWN_MODE.get(); 376 } 377 378 379 380 /** 381 * {@inheritDoc} 382 */ 383 @Override() 384 protected List<String> getAdditionalObjectClasses() 385 { 386 return Collections.singletonList(OC_ENTER_LOCKDOWN_MODE_TASK); 387 } 388 389 390 391 /** 392 * {@inheritDoc} 393 */ 394 @Override() 395 protected List<Attribute> getAdditionalAttributes() 396 { 397 final ArrayList<Attribute> attrs = new ArrayList<>(1); 398 if (reason != null) 399 { 400 attrs.add(new Attribute(ATTR_ENTER_LOCKDOWN_REASON, reason)); 401 } 402 return attrs; 403 } 404 405 406 407 /** 408 * {@inheritDoc} 409 */ 410 @Override() 411 public List<TaskProperty> getTaskSpecificProperties() 412 { 413 final List<TaskProperty> propList = 414 Collections.singletonList(PROPERTY_ENTER_LOCKDOWN_REASON); 415 416 return Collections.unmodifiableList(propList); 417 } 418 419 420 421 /** 422 * {@inheritDoc} 423 */ 424 @Override() 425 public Map<TaskProperty,List<Object>> getTaskPropertyValues() 426 { 427 final LinkedHashMap<TaskProperty,List<Object>> props = 428 new LinkedHashMap<>(10); 429 430 if (reason != null) 431 { 432 props.put(PROPERTY_ENTER_LOCKDOWN_REASON, 433 Collections.<Object>singletonList(reason)); 434 } 435 436 props.putAll(super.getTaskPropertyValues()); 437 return Collections.unmodifiableMap(props); 438 } 439}