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 legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2008 Sun Microsystems, Inc. 025 */ 026package org.opends.server.admin.std.meta; 027 028 029 030import java.util.Collection; 031import java.util.SortedSet; 032import org.opends.server.admin.AdministratorAction; 033import org.opends.server.admin.AliasDefaultBehaviorProvider; 034import org.opends.server.admin.AttributeTypePropertyDefinition; 035import org.opends.server.admin.BooleanPropertyDefinition; 036import org.opends.server.admin.ClassPropertyDefinition; 037import org.opends.server.admin.client.AuthorizationException; 038import org.opends.server.admin.client.CommunicationException; 039import org.opends.server.admin.client.ConcurrentModificationException; 040import org.opends.server.admin.client.ManagedObject; 041import org.opends.server.admin.client.MissingMandatoryPropertiesException; 042import org.opends.server.admin.client.OperationRejectedException; 043import org.opends.server.admin.DefaultBehaviorProvider; 044import org.opends.server.admin.DefinedDefaultBehaviorProvider; 045import org.opends.server.admin.DNPropertyDefinition; 046import org.opends.server.admin.ManagedObjectAlreadyExistsException; 047import org.opends.server.admin.ManagedObjectDefinition; 048import org.opends.server.admin.PropertyOption; 049import org.opends.server.admin.PropertyProvider; 050import org.opends.server.admin.server.ConfigurationChangeListener; 051import org.opends.server.admin.server.ServerManagedObject; 052import org.opends.server.admin.std.client.SubjectDNToUserAttributeCertificateMapperCfgClient; 053import org.opends.server.admin.std.server.CertificateMapperCfg; 054import org.opends.server.admin.std.server.SubjectDNToUserAttributeCertificateMapperCfg; 055import org.opends.server.admin.Tag; 056import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 057import org.opends.server.types.AttributeType; 058import org.opends.server.types.DN; 059 060 061 062/** 063 * An interface for querying the Subject DN To User Attribute 064 * Certificate Mapper managed object definition meta information. 065 * <p> 066 * The Subject DN To User Attribute Certificate Mapper maps client 067 * certificates to user entries by looking for the certificate subject 068 * DN in a specified attribute of user entries. 069 */ 070public final class SubjectDNToUserAttributeCertificateMapperCfgDefn extends ManagedObjectDefinition<SubjectDNToUserAttributeCertificateMapperCfgClient, SubjectDNToUserAttributeCertificateMapperCfg> { 071 072 // The singleton configuration definition instance. 073 private static final SubjectDNToUserAttributeCertificateMapperCfgDefn INSTANCE = new SubjectDNToUserAttributeCertificateMapperCfgDefn(); 074 075 076 077 // The "java-class" property definition. 078 private static final ClassPropertyDefinition PD_JAVA_CLASS; 079 080 081 082 // The "subject-attribute" property definition. 083 private static final AttributeTypePropertyDefinition PD_SUBJECT_ATTRIBUTE; 084 085 086 087 // The "user-base-dn" property definition. 088 private static final DNPropertyDefinition PD_USER_BASE_DN; 089 090 091 092 // Build the "java-class" property definition. 093 static { 094 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 095 builder.setOption(PropertyOption.MANDATORY); 096 builder.setOption(PropertyOption.ADVANCED); 097 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 098 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.extensions.SubjectDNToUserAttributeCertificateMapper"); 099 builder.setDefaultBehaviorProvider(provider); 100 builder.addInstanceOf("org.opends.server.api.CertificateMapper"); 101 PD_JAVA_CLASS = builder.getInstance(); 102 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 103 } 104 105 106 107 // Build the "subject-attribute" property definition. 108 static { 109 AttributeTypePropertyDefinition.Builder builder = AttributeTypePropertyDefinition.createBuilder(INSTANCE, "subject-attribute"); 110 builder.setOption(PropertyOption.MANDATORY); 111 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "subject-attribute")); 112 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<AttributeType>()); 113 PD_SUBJECT_ATTRIBUTE = builder.getInstance(); 114 INSTANCE.registerPropertyDefinition(PD_SUBJECT_ATTRIBUTE); 115 } 116 117 118 119 // Build the "user-base-dn" property definition. 120 static { 121 DNPropertyDefinition.Builder builder = DNPropertyDefinition.createBuilder(INSTANCE, "user-base-dn"); 122 builder.setOption(PropertyOption.MULTI_VALUED); 123 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "user-base-dn")); 124 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<DN>(INSTANCE, "user-base-dn")); 125 PD_USER_BASE_DN = builder.getInstance(); 126 INSTANCE.registerPropertyDefinition(PD_USER_BASE_DN); 127 } 128 129 130 131 // Register the tags associated with this managed object definition. 132 static { 133 INSTANCE.registerTag(Tag.valueOf("security")); 134 INSTANCE.registerTag(Tag.valueOf("user-management")); 135 } 136 137 138 139 /** 140 * Get the Subject DN To User Attribute Certificate Mapper 141 * configuration definition singleton. 142 * 143 * @return Returns the Subject DN To User Attribute Certificate 144 * Mapper configuration definition singleton. 145 */ 146 public static SubjectDNToUserAttributeCertificateMapperCfgDefn getInstance() { 147 return INSTANCE; 148 } 149 150 151 152 /** 153 * Private constructor. 154 */ 155 private SubjectDNToUserAttributeCertificateMapperCfgDefn() { 156 super("subject-dn-to-user-attribute-certificate-mapper", CertificateMapperCfgDefn.getInstance()); 157 } 158 159 160 161 /** 162 * {@inheritDoc} 163 */ 164 public SubjectDNToUserAttributeCertificateMapperCfgClient createClientConfiguration( 165 ManagedObject<? extends SubjectDNToUserAttributeCertificateMapperCfgClient> impl) { 166 return new SubjectDNToUserAttributeCertificateMapperCfgClientImpl(impl); 167 } 168 169 170 171 /** 172 * {@inheritDoc} 173 */ 174 public SubjectDNToUserAttributeCertificateMapperCfg createServerConfiguration( 175 ServerManagedObject<? extends SubjectDNToUserAttributeCertificateMapperCfg> impl) { 176 return new SubjectDNToUserAttributeCertificateMapperCfgServerImpl(impl); 177 } 178 179 180 181 /** 182 * {@inheritDoc} 183 */ 184 public Class<SubjectDNToUserAttributeCertificateMapperCfg> getServerConfigurationClass() { 185 return SubjectDNToUserAttributeCertificateMapperCfg.class; 186 } 187 188 189 190 /** 191 * Get the "enabled" property definition. 192 * <p> 193 * Indicates whether the Subject DN To User Attribute Certificate 194 * Mapper is enabled. 195 * 196 * @return Returns the "enabled" property definition. 197 */ 198 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 199 return CertificateMapperCfgDefn.getInstance().getEnabledPropertyDefinition(); 200 } 201 202 203 204 /** 205 * Get the "java-class" property definition. 206 * <p> 207 * Specifies the fully-qualified name of the Java class that 208 * provides the Subject DN To User Attribute Certificate Mapper 209 * implementation. 210 * 211 * @return Returns the "java-class" property definition. 212 */ 213 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 214 return PD_JAVA_CLASS; 215 } 216 217 218 219 /** 220 * Get the "subject-attribute" property definition. 221 * <p> 222 * Specifies the name or OID of the attribute whose value should 223 * exactly match the certificate subject DN. 224 * 225 * @return Returns the "subject-attribute" property definition. 226 */ 227 public AttributeTypePropertyDefinition getSubjectAttributePropertyDefinition() { 228 return PD_SUBJECT_ATTRIBUTE; 229 } 230 231 232 233 /** 234 * Get the "user-base-dn" property definition. 235 * <p> 236 * Specifies the base DNs that should be used when performing 237 * searches to map the client certificate to a user entry. 238 * 239 * @return Returns the "user-base-dn" property definition. 240 */ 241 public DNPropertyDefinition getUserBaseDNPropertyDefinition() { 242 return PD_USER_BASE_DN; 243 } 244 245 246 247 /** 248 * Managed object client implementation. 249 */ 250 private static class SubjectDNToUserAttributeCertificateMapperCfgClientImpl implements 251 SubjectDNToUserAttributeCertificateMapperCfgClient { 252 253 // Private implementation. 254 private ManagedObject<? extends SubjectDNToUserAttributeCertificateMapperCfgClient> impl; 255 256 257 258 // Private constructor. 259 private SubjectDNToUserAttributeCertificateMapperCfgClientImpl( 260 ManagedObject<? extends SubjectDNToUserAttributeCertificateMapperCfgClient> impl) { 261 this.impl = impl; 262 } 263 264 265 266 /** 267 * {@inheritDoc} 268 */ 269 public Boolean isEnabled() { 270 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 271 } 272 273 274 275 /** 276 * {@inheritDoc} 277 */ 278 public void setEnabled(boolean value) { 279 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 280 } 281 282 283 284 /** 285 * {@inheritDoc} 286 */ 287 public String getJavaClass() { 288 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 289 } 290 291 292 293 /** 294 * {@inheritDoc} 295 */ 296 public void setJavaClass(String value) { 297 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 298 } 299 300 301 302 /** 303 * {@inheritDoc} 304 */ 305 public AttributeType getSubjectAttribute() { 306 return impl.getPropertyValue(INSTANCE.getSubjectAttributePropertyDefinition()); 307 } 308 309 310 311 /** 312 * {@inheritDoc} 313 */ 314 public void setSubjectAttribute(AttributeType value) { 315 impl.setPropertyValue(INSTANCE.getSubjectAttributePropertyDefinition(), value); 316 } 317 318 319 320 /** 321 * {@inheritDoc} 322 */ 323 public SortedSet<DN> getUserBaseDN() { 324 return impl.getPropertyValues(INSTANCE.getUserBaseDNPropertyDefinition()); 325 } 326 327 328 329 /** 330 * {@inheritDoc} 331 */ 332 public void setUserBaseDN(Collection<DN> values) { 333 impl.setPropertyValues(INSTANCE.getUserBaseDNPropertyDefinition(), values); 334 } 335 336 337 338 /** 339 * {@inheritDoc} 340 */ 341 public ManagedObjectDefinition<? extends SubjectDNToUserAttributeCertificateMapperCfgClient, ? extends SubjectDNToUserAttributeCertificateMapperCfg> definition() { 342 return INSTANCE; 343 } 344 345 346 347 /** 348 * {@inheritDoc} 349 */ 350 public PropertyProvider properties() { 351 return impl; 352 } 353 354 355 356 /** 357 * {@inheritDoc} 358 */ 359 public void commit() throws ManagedObjectAlreadyExistsException, 360 MissingMandatoryPropertiesException, ConcurrentModificationException, 361 OperationRejectedException, AuthorizationException, 362 CommunicationException { 363 impl.commit(); 364 } 365 366 367 368 /** {@inheritDoc} */ 369 public String toString() { 370 return impl.toString(); 371 } 372 } 373 374 375 376 /** 377 * Managed object server implementation. 378 */ 379 private static class SubjectDNToUserAttributeCertificateMapperCfgServerImpl implements 380 SubjectDNToUserAttributeCertificateMapperCfg { 381 382 // Private implementation. 383 private ServerManagedObject<? extends SubjectDNToUserAttributeCertificateMapperCfg> impl; 384 385 // The value of the "enabled" property. 386 private final boolean pEnabled; 387 388 // The value of the "java-class" property. 389 private final String pJavaClass; 390 391 // The value of the "subject-attribute" property. 392 private final AttributeType pSubjectAttribute; 393 394 // The value of the "user-base-dn" property. 395 private final SortedSet<DN> pUserBaseDN; 396 397 398 399 // Private constructor. 400 private SubjectDNToUserAttributeCertificateMapperCfgServerImpl(ServerManagedObject<? extends SubjectDNToUserAttributeCertificateMapperCfg> impl) { 401 this.impl = impl; 402 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 403 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 404 this.pSubjectAttribute = impl.getPropertyValue(INSTANCE.getSubjectAttributePropertyDefinition()); 405 this.pUserBaseDN = impl.getPropertyValues(INSTANCE.getUserBaseDNPropertyDefinition()); 406 } 407 408 409 410 /** 411 * {@inheritDoc} 412 */ 413 public void addSubjectDNToUserAttributeChangeListener( 414 ConfigurationChangeListener<SubjectDNToUserAttributeCertificateMapperCfg> listener) { 415 impl.registerChangeListener(listener); 416 } 417 418 419 420 /** 421 * {@inheritDoc} 422 */ 423 public void removeSubjectDNToUserAttributeChangeListener( 424 ConfigurationChangeListener<SubjectDNToUserAttributeCertificateMapperCfg> listener) { 425 impl.deregisterChangeListener(listener); 426 } 427 /** 428 * {@inheritDoc} 429 */ 430 public void addChangeListener( 431 ConfigurationChangeListener<CertificateMapperCfg> listener) { 432 impl.registerChangeListener(listener); 433 } 434 435 436 437 /** 438 * {@inheritDoc} 439 */ 440 public void removeChangeListener( 441 ConfigurationChangeListener<CertificateMapperCfg> listener) { 442 impl.deregisterChangeListener(listener); 443 } 444 445 446 447 /** 448 * {@inheritDoc} 449 */ 450 public boolean isEnabled() { 451 return pEnabled; 452 } 453 454 455 456 /** 457 * {@inheritDoc} 458 */ 459 public String getJavaClass() { 460 return pJavaClass; 461 } 462 463 464 465 /** 466 * {@inheritDoc} 467 */ 468 public AttributeType getSubjectAttribute() { 469 return pSubjectAttribute; 470 } 471 472 473 474 /** 475 * {@inheritDoc} 476 */ 477 public SortedSet<DN> getUserBaseDN() { 478 return pUserBaseDN; 479 } 480 481 482 483 /** 484 * {@inheritDoc} 485 */ 486 public Class<? extends SubjectDNToUserAttributeCertificateMapperCfg> configurationClass() { 487 return SubjectDNToUserAttributeCertificateMapperCfg.class; 488 } 489 490 491 492 /** 493 * {@inheritDoc} 494 */ 495 public DN dn() { 496 return impl.getDN(); 497 } 498 499 500 501 /** {@inheritDoc} */ 502 public String toString() { 503 return impl.toString(); 504 } 505 } 506}