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 * docs/licenses/cddl.txt 011 * or http://www.opensource.org/licenses/cddl1.php. 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 * docs/licenses/cddl.txt. 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 2010-2012 UnboundID Corp. 026 */ 027 package com.unboundid.directory.sdk.common.api; 028 029 030 031 import java.util.Collections; 032 import java.util.List; 033 import java.util.Map; 034 import javax.net.ssl.KeyManager; 035 036 import com.unboundid.directory.sdk.common.config.KeyManagerProviderConfig; 037 import com.unboundid.directory.sdk.common.internal.ExampleUsageProvider; 038 import com.unboundid.directory.sdk.common.internal.Reconfigurable; 039 import com.unboundid.directory.sdk.common.internal.UnboundIDExtension; 040 import com.unboundid.directory.sdk.common.types.ServerContext; 041 import com.unboundid.directory.sdk.ds.internal.DirectoryServerExtension; 042 import com.unboundid.directory.sdk.proxy.internal.DirectoryProxyServerExtension; 043 import com.unboundid.directory.sdk.sync.internal.SynchronizationServerExtension; 044 import com.unboundid.ldap.sdk.LDAPException; 045 import com.unboundid.ldap.sdk.ResultCode; 046 import com.unboundid.util.Extensible; 047 import com.unboundid.util.ThreadSafety; 048 import com.unboundid.util.ThreadSafetyLevel; 049 import com.unboundid.util.args.ArgumentException; 050 import com.unboundid.util.args.ArgumentParser; 051 052 053 054 /** 055 * This class defines an API that must be implemented by extensions which 056 * provide access to key managers. Key managers allow the server to access 057 * certificates in a form that can be presented to another system during SSL or 058 * StartTLS negotiation. If the server is configured to accept secure 059 * communication from clients, then a key manager provider will be used to 060 * access the certificate that the server presents to the client. If the server 061 * needs to establish a secure connection to another system (e.g., the Directory 062 * Proxy Server connecting to a backend Directory Server instance), then the 063 * key manager provider may also be used to obtain a client certificate that may 064 * be used for authentication. 065 * <BR> 066 * <H2>Configuring Key Manager Providers</H2> 067 * In order to configure a key manager provider created using this API, use a 068 * command like: 069 * <PRE> 070 * dsconfig create-key-manager-provider \ 071 * --provider-name "<I>{provider-name}</I>" \ 072 * --type third-party \ 073 * --set enabled:true \ 074 * --set "extension-class:<I>{class-name}</I>" \ 075 * --set "extension-argument:<I>{name=value}</I>" 076 * </PRE> 077 * where "<I>{provider-name}</I>" is the name to use for the key manager 078 * provider instance, "<I>{class-name}</I>" is the fully-qualified name of the 079 * Java class that extends 080 * {@code com.unboundid.directory.sdk.common.api.KeyManagerProvider}, and 081 * "<I>{name=value}</I>" represents name-value pairs for any arguments to 082 * provide to the key manager provider. If multiple arguments should be 083 * provided to the key manager provider, then the 084 * "<CODE>--set extension-argument:<I>{name=value}</I></CODE>" option should be 085 * provided multiple times. 086 */ 087 @Extensible() 088 @DirectoryServerExtension() 089 @DirectoryProxyServerExtension(appliesToLocalContent=true, 090 appliesToRemoteContent=false) 091 @SynchronizationServerExtension(appliesToLocalContent=true, 092 appliesToSynchronizedContent=false) 093 @ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 094 public abstract class KeyManagerProvider 095 implements UnboundIDExtension, Reconfigurable<KeyManagerProviderConfig>, 096 ExampleUsageProvider 097 { 098 /** 099 * Creates a new instance of this key manager provider. All key manager 100 * provider implementations must include a default constructor, but any 101 * initialization should generally be done in the 102 * {@code initializeKeyManagerProvider} method. 103 */ 104 public KeyManagerProvider() 105 { 106 // No implementation is required. 107 } 108 109 110 111 /** 112 * {@inheritDoc} 113 */ 114 public abstract String getExtensionName(); 115 116 117 118 /** 119 * {@inheritDoc} 120 */ 121 public abstract String[] getExtensionDescription(); 122 123 124 125 /** 126 * {@inheritDoc} 127 */ 128 public void defineConfigArguments(final ArgumentParser parser) 129 throws ArgumentException 130 { 131 // No arguments will be allowed by default. 132 } 133 134 135 136 /** 137 * Initializes this key manager provider. 138 * 139 * @param serverContext A handle to the server context for the server in 140 * which this extension is running. 141 * @param config The general configuration for this key manager 142 * provider. 143 * @param parser The argument parser which has been initialized from 144 * the configuration for this key manager provider. 145 * 146 * @throws LDAPException If a problem occurs while initializing this 147 * key manager provider. 148 */ 149 public void initializeKeyManagerProvider(final ServerContext serverContext, 150 final KeyManagerProviderConfig config, 151 final ArgumentParser parser) 152 throws LDAPException 153 { 154 // No initialization will be performed by default. 155 } 156 157 158 159 /** 160 * {@inheritDoc} 161 */ 162 public boolean isConfigurationAcceptable( 163 final KeyManagerProviderConfig config, 164 final ArgumentParser parser, 165 final List<String> unacceptableReasons) 166 { 167 // No extended validation will be performed by default. 168 return true; 169 } 170 171 172 173 /** 174 * {@inheritDoc} 175 */ 176 public ResultCode applyConfiguration(final KeyManagerProviderConfig config, 177 final ArgumentParser parser, 178 final List<String> adminActionsRequired, 179 final List<String> messages) 180 { 181 // By default, no configuration changes will be applied. If there are any 182 // arguments, then add an admin action message indicating that the extension 183 // needs to be restarted for any changes to take effect. 184 if (! parser.getNamedArguments().isEmpty()) 185 { 186 adminActionsRequired.add( 187 "No configuration change has actually been applied. The new " + 188 "configuration will not take effect until this key manager " + 189 "provider is disabled and re-enabled or until the server is " + 190 "restarted."); 191 } 192 193 return ResultCode.SUCCESS; 194 } 195 196 197 198 /** 199 * Performs any cleanup which may be necessary when this key manager provider 200 * is to be taken out of service. 201 */ 202 public void finalizeKeyManagerProvider() 203 { 204 // No implementation is required. 205 } 206 207 208 209 /** 210 * Retrieves a set of key managers that may be used for operations within 211 * the server which may require access to certificates. 212 * 213 * @return The set of key managers that may be used for operations within the 214 * server which may require access to certificates. 215 * 216 * @throws LDAPException If a problem occurs while attempting to retrieve 217 * the key managers. 218 */ 219 public abstract KeyManager[] getKeyManagers() 220 throws LDAPException; 221 222 223 224 /** 225 * {@inheritDoc} 226 */ 227 public Map<List<String>,String> getExamplesArgumentSets() 228 { 229 return Collections.emptyMap(); 230 } 231 }