001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2008 Sun Microsystems, Inc. 015 */ 016package org.opends.server.admin.std.meta; 017 018 019 020import org.forgerock.opendj.ldap.DN; 021import org.opends.server.admin.AdministratorAction; 022import org.opends.server.admin.BooleanPropertyDefinition; 023import org.opends.server.admin.ClassPropertyDefinition; 024import org.opends.server.admin.client.AuthorizationException; 025import org.opends.server.admin.client.CommunicationException; 026import org.opends.server.admin.client.ConcurrentModificationException; 027import org.opends.server.admin.client.ManagedObject; 028import org.opends.server.admin.client.MissingMandatoryPropertiesException; 029import org.opends.server.admin.client.OperationRejectedException; 030import org.opends.server.admin.ManagedObjectAlreadyExistsException; 031import org.opends.server.admin.ManagedObjectDefinition; 032import org.opends.server.admin.PropertyOption; 033import org.opends.server.admin.PropertyProvider; 034import org.opends.server.admin.server.ConfigurationChangeListener; 035import org.opends.server.admin.server.ServerManagedObject; 036import org.opends.server.admin.std.client.CertificateMapperCfgClient; 037import org.opends.server.admin.std.server.CertificateMapperCfg; 038import org.opends.server.admin.Tag; 039import org.opends.server.admin.TopCfgDefn; 040import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 041 042 043 044/** 045 * An interface for querying the Certificate Mapper managed object 046 * definition meta information. 047 * <p> 048 * Certificate Mappers are responsible for establishing a mapping 049 * between a client certificate and the entry for the user that 050 * corresponds to that certificate. 051 */ 052public final class CertificateMapperCfgDefn extends ManagedObjectDefinition<CertificateMapperCfgClient, CertificateMapperCfg> { 053 054 // The singleton configuration definition instance. 055 private static final CertificateMapperCfgDefn INSTANCE = new CertificateMapperCfgDefn(); 056 057 058 059 // The "enabled" property definition. 060 private static final BooleanPropertyDefinition PD_ENABLED; 061 062 063 064 // The "java-class" property definition. 065 private static final ClassPropertyDefinition PD_JAVA_CLASS; 066 067 068 069 // Build the "enabled" property definition. 070 static { 071 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 072 builder.setOption(PropertyOption.MANDATORY); 073 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 074 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 075 PD_ENABLED = builder.getInstance(); 076 INSTANCE.registerPropertyDefinition(PD_ENABLED); 077 } 078 079 080 081 // Build the "java-class" property definition. 082 static { 083 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 084 builder.setOption(PropertyOption.MANDATORY); 085 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 086 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 087 builder.addInstanceOf("org.opends.server.api.CertificateMapper"); 088 PD_JAVA_CLASS = builder.getInstance(); 089 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 090 } 091 092 093 094 // Register the tags associated with this managed object definition. 095 static { 096 INSTANCE.registerTag(Tag.valueOf("security")); 097 INSTANCE.registerTag(Tag.valueOf("user-management")); 098 } 099 100 101 102 /** 103 * Get the Certificate Mapper configuration definition singleton. 104 * 105 * @return Returns the Certificate Mapper configuration definition 106 * singleton. 107 */ 108 public static CertificateMapperCfgDefn getInstance() { 109 return INSTANCE; 110 } 111 112 113 114 /** 115 * Private constructor. 116 */ 117 private CertificateMapperCfgDefn() { 118 super("certificate-mapper", TopCfgDefn.getInstance()); 119 } 120 121 122 123 /** 124 * {@inheritDoc} 125 */ 126 public CertificateMapperCfgClient createClientConfiguration( 127 ManagedObject<? extends CertificateMapperCfgClient> impl) { 128 return new CertificateMapperCfgClientImpl(impl); 129 } 130 131 132 133 /** 134 * {@inheritDoc} 135 */ 136 public CertificateMapperCfg createServerConfiguration( 137 ServerManagedObject<? extends CertificateMapperCfg> impl) { 138 return new CertificateMapperCfgServerImpl(impl); 139 } 140 141 142 143 /** 144 * {@inheritDoc} 145 */ 146 public Class<CertificateMapperCfg> getServerConfigurationClass() { 147 return CertificateMapperCfg.class; 148 } 149 150 151 152 /** 153 * Get the "enabled" property definition. 154 * <p> 155 * Indicates whether the Certificate Mapper is enabled. 156 * 157 * @return Returns the "enabled" property definition. 158 */ 159 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 160 return PD_ENABLED; 161 } 162 163 164 165 /** 166 * Get the "java-class" property definition. 167 * <p> 168 * Specifies the fully-qualified name of the Java class that 169 * provides the Certificate Mapper implementation. 170 * 171 * @return Returns the "java-class" property definition. 172 */ 173 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 174 return PD_JAVA_CLASS; 175 } 176 177 178 179 /** 180 * Managed object client implementation. 181 */ 182 private static class CertificateMapperCfgClientImpl implements 183 CertificateMapperCfgClient { 184 185 // Private implementation. 186 private ManagedObject<? extends CertificateMapperCfgClient> impl; 187 188 189 190 // Private constructor. 191 private CertificateMapperCfgClientImpl( 192 ManagedObject<? extends CertificateMapperCfgClient> impl) { 193 this.impl = impl; 194 } 195 196 197 198 /** 199 * {@inheritDoc} 200 */ 201 public Boolean isEnabled() { 202 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 203 } 204 205 206 207 /** 208 * {@inheritDoc} 209 */ 210 public void setEnabled(boolean value) { 211 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 212 } 213 214 215 216 /** 217 * {@inheritDoc} 218 */ 219 public String getJavaClass() { 220 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 221 } 222 223 224 225 /** 226 * {@inheritDoc} 227 */ 228 public void setJavaClass(String value) { 229 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 230 } 231 232 233 234 /** 235 * {@inheritDoc} 236 */ 237 public ManagedObjectDefinition<? extends CertificateMapperCfgClient, ? extends CertificateMapperCfg> definition() { 238 return INSTANCE; 239 } 240 241 242 243 /** 244 * {@inheritDoc} 245 */ 246 public PropertyProvider properties() { 247 return impl; 248 } 249 250 251 252 /** 253 * {@inheritDoc} 254 */ 255 public void commit() throws ManagedObjectAlreadyExistsException, 256 MissingMandatoryPropertiesException, ConcurrentModificationException, 257 OperationRejectedException, AuthorizationException, 258 CommunicationException { 259 impl.commit(); 260 } 261 262 263 264 /** {@inheritDoc} */ 265 public String toString() { 266 return impl.toString(); 267 } 268 } 269 270 271 272 /** 273 * Managed object server implementation. 274 */ 275 private static class CertificateMapperCfgServerImpl implements 276 CertificateMapperCfg { 277 278 // Private implementation. 279 private ServerManagedObject<? extends CertificateMapperCfg> impl; 280 281 // The value of the "enabled" property. 282 private final boolean pEnabled; 283 284 // The value of the "java-class" property. 285 private final String pJavaClass; 286 287 288 289 // Private constructor. 290 private CertificateMapperCfgServerImpl(ServerManagedObject<? extends CertificateMapperCfg> impl) { 291 this.impl = impl; 292 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 293 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 294 } 295 296 297 298 /** 299 * {@inheritDoc} 300 */ 301 public void addChangeListener( 302 ConfigurationChangeListener<CertificateMapperCfg> listener) { 303 impl.registerChangeListener(listener); 304 } 305 306 307 308 /** 309 * {@inheritDoc} 310 */ 311 public void removeChangeListener( 312 ConfigurationChangeListener<CertificateMapperCfg> listener) { 313 impl.deregisterChangeListener(listener); 314 } 315 316 317 318 /** 319 * {@inheritDoc} 320 */ 321 public boolean isEnabled() { 322 return pEnabled; 323 } 324 325 326 327 /** 328 * {@inheritDoc} 329 */ 330 public String getJavaClass() { 331 return pJavaClass; 332 } 333 334 335 336 /** 337 * {@inheritDoc} 338 */ 339 public Class<? extends CertificateMapperCfg> configurationClass() { 340 return CertificateMapperCfg.class; 341 } 342 343 344 345 /** 346 * {@inheritDoc} 347 */ 348 public DN dn() { 349 return impl.getDN(); 350 } 351 352 353 354 /** {@inheritDoc} */ 355 public String toString() { 356 return impl.toString(); 357 } 358 } 359}