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-2013 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.TrustManager; 035 036 import com.unboundid.directory.sdk.common.config.TrustManagerProviderConfig; 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.metrics.internal.MetricsEngineExtension; 043 import com.unboundid.directory.sdk.proxy.internal.DirectoryProxyServerExtension; 044 import com.unboundid.directory.sdk.sync.internal.SynchronizationServerExtension; 045 import com.unboundid.ldap.sdk.LDAPException; 046 import com.unboundid.ldap.sdk.ResultCode; 047 import com.unboundid.util.Extensible; 048 import com.unboundid.util.ThreadSafety; 049 import com.unboundid.util.ThreadSafetyLevel; 050 import com.unboundid.util.args.ArgumentException; 051 import com.unboundid.util.args.ArgumentParser; 052 053 054 055 /** 056 * This class defines an API that must be implemented by extensions which 057 * provide access to trust managers which are used to determine whether to trust 058 * a certificate that has been presented to the server. Trust managers are 059 * generally used when performing cryptographic operations, including SSL and 060 * StartTLS communication, in which a certificate is presented to the server. 061 * In such cases, the secure communication will only be allowed if the trust 062 * managers determine that the presented certificate chain is trustworthy. 063 * <BR> 064 * <H2>Configuring Trust Manager Providers</H2> 065 * In order to configure a trust manager provider created using this API, use a 066 * command like: 067 * <PRE> 068 * dsconfig create-trust-manager-provider \ 069 * --provider-name "<I>{provider-name}</I>" \ 070 * --type third-party \ 071 * --set enabled:true \ 072 * --set "extension-class:<I>{class-name}</I>" \ 073 * --set "extension-argument:<I>{name=value}</I>" 074 * </PRE> 075 * where "<I>{provider-name}</I>" is the name to use for the trust manager 076 * provider instance, "<I>{class-name}</I>" is the fully-qualified name of the 077 * Java class that extends 078 * {@code com.unboundid.directory.sdk.common.api.TrustManagerProvider}, and 079 * "<I>{name=value}</I>" represents name-value pairs for any arguments to 080 * provide to the trust manager provider. If multiple arguments should be 081 * provided to the trust manager provider, then the 082 * "<CODE>--set extension-argument:<I>{name=value}</I></CODE>" option should be 083 * provided multiple times. 084 */ 085 @Extensible() 086 @DirectoryServerExtension() 087 @DirectoryProxyServerExtension(appliesToLocalContent=true, 088 appliesToRemoteContent=false) 089 @SynchronizationServerExtension(appliesToLocalContent=true, 090 appliesToSynchronizedContent=false) 091 @MetricsEngineExtension() 092 @ThreadSafety(level=ThreadSafetyLevel.INTERFACE_THREADSAFE) 093 public abstract class TrustManagerProvider 094 implements UnboundIDExtension, 095 Reconfigurable<TrustManagerProviderConfig>, 096 ExampleUsageProvider 097 { 098 /** 099 * Creates a new instance of this trust manager provider. All trust manager 100 * provider implementations must include a default constructor, but any 101 * initialization should generally be done in the 102 * {@code initializeTrustManagerProvider} method. 103 */ 104 public TrustManagerProvider() 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 trust 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 trust manager 142 * provider. 143 * @param parser The argument parser which has been initialized from 144 * the configuration for this trust manager provider. 145 * 146 * @throws LDAPException If a problem occurs while initializing this 147 * trust manager provider. 148 */ 149 public void initializeTrustManagerProvider(final ServerContext serverContext, 150 final TrustManagerProviderConfig 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 TrustManagerProviderConfig 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 TrustManagerProviderConfig 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 trust 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 trust manager 200 * provider is to be taken out of service. 201 */ 202 public void finalizeTrustManagerProvider() 203 { 204 // No implementation is required. 205 } 206 207 208 209 /** 210 * Retrieves a set of trust managers that may be used for operations within 211 * the server which may need to determine whether to trust a presented 212 * certificate chain. 213 * 214 * @return The set of trust managers that may be used for operations within 215 * the server which may need to determine whether to trust a 216 * presented certificate chain. 217 * 218 * @throws LDAPException If a problem occurs while attempting to retrieve 219 * the trust managers. 220 */ 221 public abstract TrustManager[] getTrustManagers() 222 throws LDAPException; 223 224 225 226 /** 227 * {@inheritDoc} 228 */ 229 public Map<List<String>,String> getExamplesArgumentSets() 230 { 231 return Collections.emptyMap(); 232 } 233 }