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