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.Arrays; 027import java.util.Collections; 028import java.util.Date; 029import java.util.LinkedHashMap; 030import java.util.List; 031import java.util.Map; 032 033import com.unboundid.ldap.sdk.Attribute; 034import com.unboundid.ldap.sdk.Entry; 035import com.unboundid.util.NotMutable; 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 Alcatel-Lucent 8661 056 * server products. These classes provide support for proprietary 057 * functionality or for external specifications that are not considered stable 058 * or mature enough to be guaranteed to work in an interoperable way with 059 * 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 super(taskID, LEAVE_LOCKDOWN_MODE_TASK_CLASS, scheduledStartTime, 224 dependencyIDs, failedDependencyAction, notifyOnCompletion, 225 notifyOnError); 226 227 this.reason = reason; 228 } 229 230 231 232 /** 233 * Creates a new leave lockdown mode task from the provided entry. 234 * 235 * @param entry The entry to use to create this leave lockdown mode task. 236 * 237 * @throws TaskException If the provided entry cannot be parsed as a leave 238 * lockdown mode task entry. 239 */ 240 public LeaveLockdownModeTask(final Entry entry) 241 throws TaskException 242 { 243 super(entry); 244 245 // Get the "reason" string if it is present. 246 reason = entry.getAttributeValue(ATTR_LEAVE_LOCKDOWN_REASON); 247 } 248 249 250 251 /** 252 * Creates a new leave lockdown mode task from the provided set of task 253 * properties. 254 * 255 * @param properties The set of task properties and their corresponding 256 * values to use for the task. It must not be 257 * {@code null}. 258 * 259 * @throws TaskException If the provided set of properties cannot be used to 260 * create a valid leave lockdown mode task. 261 */ 262 public LeaveLockdownModeTask(final Map<TaskProperty,List<Object>> properties) 263 throws TaskException 264 { 265 super(LEAVE_LOCKDOWN_MODE_TASK_CLASS, properties); 266 267 String r = null; 268 for (final Map.Entry<TaskProperty,List<Object>> entry : 269 properties.entrySet()) 270 { 271 final TaskProperty p = entry.getKey(); 272 final String attrName = p.getAttributeName(); 273 final List<Object> values = entry.getValue(); 274 275 if (attrName.equalsIgnoreCase(ATTR_LEAVE_LOCKDOWN_REASON)) 276 { 277 r = parseString(p, values, null); 278 break; 279 } 280 } 281 282 reason = r; 283 } 284 285 286 287 /** 288 * Retrieves the user-specified reason why the server is leaving lockdown 289 * mode. 290 * 291 * @return The reason the server is leaving lockdown mode, or {@code null} 292 * if none was specified. 293 */ 294 public String getReason() 295 { 296 return reason; 297 } 298 299 300 301 /** 302 * {@inheritDoc} 303 */ 304 @Override() 305 public String getTaskName() 306 { 307 return INFO_TASK_NAME_LEAVE_LOCKDOWN_MODE.get(); 308 } 309 310 311 312 /** 313 * {@inheritDoc} 314 */ 315 @Override() 316 public String getTaskDescription() 317 { 318 return INFO_TASK_DESCRIPTION_LEAVE_LOCKDOWN_MODE.get(); 319 } 320 321 322 323 /** 324 * {@inheritDoc} 325 */ 326 @Override() 327 protected List<String> getAdditionalObjectClasses() 328 { 329 return Arrays.asList(OC_LEAVE_LOCKDOWN_MODE_TASK); 330 } 331 332 333 334 /** 335 * {@inheritDoc} 336 */ 337 @Override() 338 protected List<Attribute> getAdditionalAttributes() 339 { 340 final ArrayList<Attribute> attrs = new ArrayList<Attribute>(1); 341 if(reason != null) 342 { 343 attrs.add(new Attribute(ATTR_LEAVE_LOCKDOWN_REASON, reason)); 344 } 345 return attrs; 346 } 347 348 349 350 /** 351 * {@inheritDoc} 352 */ 353 @Override() 354 public List<TaskProperty> getTaskSpecificProperties() 355 { 356 final List<TaskProperty> propList = 357 Arrays.asList(PROPERTY_LEAVE_LOCKDOWN_REASON); 358 359 return Collections.unmodifiableList(propList); 360 } 361 362 363 364 /** 365 * {@inheritDoc} 366 */ 367 @Override() 368 public Map<TaskProperty,List<Object>> getTaskPropertyValues() 369 { 370 final LinkedHashMap<TaskProperty,List<Object>> props = 371 new LinkedHashMap<TaskProperty,List<Object>>(); 372 373 if(reason != null) 374 { 375 props.put(PROPERTY_LEAVE_LOCKDOWN_REASON, 376 Collections.<Object>unmodifiableList(Arrays.asList(reason))); 377 } 378 379 props.putAll(super.getTaskPropertyValues()); 380 return Collections.unmodifiableMap(props); 381 } 382}