001 /* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at 010 * trunk/opends/resource/legal-notices/OpenDS.LICENSE 011 * or https://OpenDS.dev.java.net/OpenDS.LICENSE. 012 * See the License for the specific language governing permissions 013 * and limitations under the License. 014 * 015 * When distributing Covered Code, include this CDDL HEADER in each 016 * file and include the License file at 017 * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, 018 * add the following below this CDDL HEADER, with the fields enclosed 019 * by brackets "[]" replaced with your own identifying information: 020 * Portions Copyright [yyyy] [name of copyright owner] 021 * 022 * CDDL HEADER END 023 * 024 * 025 * Copyright 2008 Sun Microsystems, Inc. 026 */ 027 package org.opends.server.tasks; 028 import org.opends.messages.Message; 029 030 031 032 import java.net.InetAddress; 033 034 import org.opends.server.backends.task.Task; 035 import org.opends.server.backends.task.TaskState; 036 import org.opends.server.core.DirectoryServer; 037 import org.opends.server.types.DirectoryException; 038 import org.opends.server.types.DN; 039 import org.opends.server.types.Operation; 040 import org.opends.server.types.ResultCode; 041 042 import static org.opends.messages.TaskMessages.*; 043 044 045 046 /** 047 * This class provides an implementation of a Directory Server task that can be 048 * used bring the server out of lockdown mode. 049 */ 050 public class LeaveLockdownModeTask 051 extends Task 052 { 053 054 /** 055 * {@inheritDoc} 056 */ 057 public Message getDisplayName() { 058 return INFO_TASK_LEAVE_LOCKDOWN_MODE_NAME.get(); 059 } 060 061 /** 062 * {@inheritDoc} 063 */ 064 @Override 065 public void initializeTask() 066 throws DirectoryException 067 { 068 // If the client connection is available, then make sure it is authorized 069 // as a root user. 070 Operation operation = getOperation(); 071 if (operation != null) 072 { 073 DN authzDN = operation.getAuthorizationDN(); 074 if ((authzDN == null) || (! DirectoryServer.isRootDN(authzDN))) 075 { 076 Message message = ERR_TASK_LEAVELOCKDOWN_NOT_ROOT.get(); 077 throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); 078 } 079 080 InetAddress clientAddress = 081 operation.getClientConnection().getRemoteAddress(); 082 if ((clientAddress != null) && (! clientAddress.isLoopbackAddress())) 083 { 084 Message message = ERR_TASK_LEAVELOCKDOWN_NOT_LOOPBACK.get(); 085 throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message); 086 } 087 } 088 } 089 090 091 092 /** 093 * {@inheritDoc} 094 */ 095 protected TaskState runTask() 096 { 097 DirectoryServer.setLockdownMode(false); 098 return TaskState.COMPLETED_SUCCESSFULLY; 099 } 100 } 101