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.forgerock.opendj.ldap.AddressMask; 033import org.opends.server.admin.AdministratorAction; 034import org.opends.server.admin.AliasDefaultBehaviorProvider; 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.IPAddressMaskPropertyDefinition; 044import org.opends.server.admin.ManagedObjectAlreadyExistsException; 045import org.opends.server.admin.ManagedObjectDefinition; 046import org.opends.server.admin.PropertyOption; 047import org.opends.server.admin.PropertyProvider; 048import org.opends.server.admin.server.ConfigurationChangeListener; 049import org.opends.server.admin.server.ServerManagedObject; 050import org.opends.server.admin.std.client.ConnectionHandlerCfgClient; 051import org.opends.server.admin.std.server.ConnectionHandlerCfg; 052import org.opends.server.admin.Tag; 053import org.opends.server.admin.TopCfgDefn; 054import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 055import org.opends.server.types.DN; 056 057 058 059/** 060 * An interface for querying the Connection Handler managed object 061 * definition meta information. 062 * <p> 063 * Connection Handlers are responsible for handling all interaction 064 * with the clients, including accepting the connections, reading 065 * requests, and sending responses. 066 */ 067public final class ConnectionHandlerCfgDefn extends ManagedObjectDefinition<ConnectionHandlerCfgClient, ConnectionHandlerCfg> { 068 069 // The singleton configuration definition instance. 070 private static final ConnectionHandlerCfgDefn INSTANCE = new ConnectionHandlerCfgDefn(); 071 072 073 074 // The "allowed-client" property definition. 075 private static final IPAddressMaskPropertyDefinition PD_ALLOWED_CLIENT; 076 077 078 079 // The "denied-client" property definition. 080 private static final IPAddressMaskPropertyDefinition PD_DENIED_CLIENT; 081 082 083 084 // The "enabled" property definition. 085 private static final BooleanPropertyDefinition PD_ENABLED; 086 087 088 089 // The "java-class" property definition. 090 private static final ClassPropertyDefinition PD_JAVA_CLASS; 091 092 093 094 // Build the "allowed-client" property definition. 095 static { 096 IPAddressMaskPropertyDefinition.Builder builder = IPAddressMaskPropertyDefinition.createBuilder(INSTANCE, "allowed-client"); 097 builder.setOption(PropertyOption.MULTI_VALUED); 098 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "allowed-client")); 099 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<AddressMask>(INSTANCE, "allowed-client")); 100 PD_ALLOWED_CLIENT = builder.getInstance(); 101 INSTANCE.registerPropertyDefinition(PD_ALLOWED_CLIENT); 102 } 103 104 105 106 // Build the "denied-client" property definition. 107 static { 108 IPAddressMaskPropertyDefinition.Builder builder = IPAddressMaskPropertyDefinition.createBuilder(INSTANCE, "denied-client"); 109 builder.setOption(PropertyOption.MULTI_VALUED); 110 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "denied-client")); 111 builder.setDefaultBehaviorProvider(new AliasDefaultBehaviorProvider<AddressMask>(INSTANCE, "denied-client")); 112 PD_DENIED_CLIENT = builder.getInstance(); 113 INSTANCE.registerPropertyDefinition(PD_DENIED_CLIENT); 114 } 115 116 117 118 // Build the "enabled" property definition. 119 static { 120 BooleanPropertyDefinition.Builder builder = BooleanPropertyDefinition.createBuilder(INSTANCE, "enabled"); 121 builder.setOption(PropertyOption.MANDATORY); 122 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "enabled")); 123 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<Boolean>()); 124 PD_ENABLED = builder.getInstance(); 125 INSTANCE.registerPropertyDefinition(PD_ENABLED); 126 } 127 128 129 130 // Build the "java-class" property definition. 131 static { 132 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 133 builder.setOption(PropertyOption.MANDATORY); 134 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "java-class")); 135 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 136 builder.addInstanceOf("org.opends.server.api.ConnectionHandler"); 137 PD_JAVA_CLASS = builder.getInstance(); 138 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 139 } 140 141 142 143 // Register the tags associated with this managed object definition. 144 static { 145 INSTANCE.registerTag(Tag.valueOf("core-server")); 146 } 147 148 149 150 /** 151 * Get the Connection Handler configuration definition singleton. 152 * 153 * @return Returns the Connection Handler configuration definition 154 * singleton. 155 */ 156 public static ConnectionHandlerCfgDefn getInstance() { 157 return INSTANCE; 158 } 159 160 161 162 /** 163 * Private constructor. 164 */ 165 private ConnectionHandlerCfgDefn() { 166 super("connection-handler", TopCfgDefn.getInstance()); 167 } 168 169 170 171 /** 172 * {@inheritDoc} 173 */ 174 public ConnectionHandlerCfgClient createClientConfiguration( 175 ManagedObject<? extends ConnectionHandlerCfgClient> impl) { 176 return new ConnectionHandlerCfgClientImpl(impl); 177 } 178 179 180 181 /** 182 * {@inheritDoc} 183 */ 184 public ConnectionHandlerCfg createServerConfiguration( 185 ServerManagedObject<? extends ConnectionHandlerCfg> impl) { 186 return new ConnectionHandlerCfgServerImpl(impl); 187 } 188 189 190 191 /** 192 * {@inheritDoc} 193 */ 194 public Class<ConnectionHandlerCfg> getServerConfigurationClass() { 195 return ConnectionHandlerCfg.class; 196 } 197 198 199 200 /** 201 * Get the "allowed-client" property definition. 202 * <p> 203 * Specifies a set of host names or address masks that determine the 204 * clients that are allowed to establish connections to this 205 * Connection Handler. 206 * <p> 207 * Valid values include a host name, a fully qualified domain name, 208 * a domain name, an IP address, or a subnetwork with subnetwork 209 * mask. 210 * 211 * @return Returns the "allowed-client" property definition. 212 */ 213 public IPAddressMaskPropertyDefinition getAllowedClientPropertyDefinition() { 214 return PD_ALLOWED_CLIENT; 215 } 216 217 218 219 /** 220 * Get the "denied-client" property definition. 221 * <p> 222 * Specifies a set of host names or address masks that determine the 223 * clients that are not allowed to establish connections to this 224 * Connection Handler. 225 * <p> 226 * Valid values include a host name, a fully qualified domain name, 227 * a domain name, an IP address, or a subnetwork with subnetwork 228 * mask. If both allowed and denied client masks are defined and a 229 * client connection matches one or more masks in both lists, then 230 * the connection is denied. If only a denied list is specified, then 231 * any client not matching a mask in that list is allowed. 232 * 233 * @return Returns the "denied-client" property definition. 234 */ 235 public IPAddressMaskPropertyDefinition getDeniedClientPropertyDefinition() { 236 return PD_DENIED_CLIENT; 237 } 238 239 240 241 /** 242 * Get the "enabled" property definition. 243 * <p> 244 * Indicates whether the Connection Handler is enabled. 245 * 246 * @return Returns the "enabled" property definition. 247 */ 248 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 249 return PD_ENABLED; 250 } 251 252 253 254 /** 255 * Get the "java-class" property definition. 256 * <p> 257 * Specifies the fully-qualified name of the Java class that 258 * provides the Connection Handler implementation. 259 * 260 * @return Returns the "java-class" property definition. 261 */ 262 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 263 return PD_JAVA_CLASS; 264 } 265 266 267 268 /** 269 * Managed object client implementation. 270 */ 271 private static class ConnectionHandlerCfgClientImpl implements 272 ConnectionHandlerCfgClient { 273 274 // Private implementation. 275 private ManagedObject<? extends ConnectionHandlerCfgClient> impl; 276 277 278 279 // Private constructor. 280 private ConnectionHandlerCfgClientImpl( 281 ManagedObject<? extends ConnectionHandlerCfgClient> impl) { 282 this.impl = impl; 283 } 284 285 286 287 /** 288 * {@inheritDoc} 289 */ 290 public SortedSet<AddressMask> getAllowedClient() { 291 return impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition()); 292 } 293 294 295 296 /** 297 * {@inheritDoc} 298 */ 299 public void setAllowedClient(Collection<AddressMask> values) { 300 impl.setPropertyValues(INSTANCE.getAllowedClientPropertyDefinition(), values); 301 } 302 303 304 305 /** 306 * {@inheritDoc} 307 */ 308 public SortedSet<AddressMask> getDeniedClient() { 309 return impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition()); 310 } 311 312 313 314 /** 315 * {@inheritDoc} 316 */ 317 public void setDeniedClient(Collection<AddressMask> values) { 318 impl.setPropertyValues(INSTANCE.getDeniedClientPropertyDefinition(), values); 319 } 320 321 322 323 /** 324 * {@inheritDoc} 325 */ 326 public Boolean isEnabled() { 327 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 328 } 329 330 331 332 /** 333 * {@inheritDoc} 334 */ 335 public void setEnabled(boolean value) { 336 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 337 } 338 339 340 341 /** 342 * {@inheritDoc} 343 */ 344 public String getJavaClass() { 345 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 346 } 347 348 349 350 /** 351 * {@inheritDoc} 352 */ 353 public void setJavaClass(String value) { 354 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 355 } 356 357 358 359 /** 360 * {@inheritDoc} 361 */ 362 public ManagedObjectDefinition<? extends ConnectionHandlerCfgClient, ? extends ConnectionHandlerCfg> definition() { 363 return INSTANCE; 364 } 365 366 367 368 /** 369 * {@inheritDoc} 370 */ 371 public PropertyProvider properties() { 372 return impl; 373 } 374 375 376 377 /** 378 * {@inheritDoc} 379 */ 380 public void commit() throws ManagedObjectAlreadyExistsException, 381 MissingMandatoryPropertiesException, ConcurrentModificationException, 382 OperationRejectedException, AuthorizationException, 383 CommunicationException { 384 impl.commit(); 385 } 386 387 } 388 389 390 391 /** 392 * Managed object server implementation. 393 */ 394 private static class ConnectionHandlerCfgServerImpl implements 395 ConnectionHandlerCfg { 396 397 // Private implementation. 398 private ServerManagedObject<? extends ConnectionHandlerCfg> impl; 399 400 // The value of the "allowed-client" property. 401 private final SortedSet<AddressMask> pAllowedClient; 402 403 // The value of the "denied-client" property. 404 private final SortedSet<AddressMask> pDeniedClient; 405 406 // The value of the "enabled" property. 407 private final boolean pEnabled; 408 409 // The value of the "java-class" property. 410 private final String pJavaClass; 411 412 413 414 // Private constructor. 415 private ConnectionHandlerCfgServerImpl(ServerManagedObject<? extends ConnectionHandlerCfg> impl) { 416 this.impl = impl; 417 this.pAllowedClient = impl.getPropertyValues(INSTANCE.getAllowedClientPropertyDefinition()); 418 this.pDeniedClient = impl.getPropertyValues(INSTANCE.getDeniedClientPropertyDefinition()); 419 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 420 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 421 } 422 423 424 425 /** 426 * {@inheritDoc} 427 */ 428 public void addChangeListener( 429 ConfigurationChangeListener<ConnectionHandlerCfg> listener) { 430 impl.registerChangeListener(listener); 431 } 432 433 434 435 /** 436 * {@inheritDoc} 437 */ 438 public void removeChangeListener( 439 ConfigurationChangeListener<ConnectionHandlerCfg> listener) { 440 impl.deregisterChangeListener(listener); 441 } 442 443 444 445 /** 446 * {@inheritDoc} 447 */ 448 public SortedSet<AddressMask> getAllowedClient() { 449 return pAllowedClient; 450 } 451 452 453 454 /** 455 * {@inheritDoc} 456 */ 457 public SortedSet<AddressMask> getDeniedClient() { 458 return pDeniedClient; 459 } 460 461 462 463 /** 464 * {@inheritDoc} 465 */ 466 public boolean isEnabled() { 467 return pEnabled; 468 } 469 470 471 472 /** 473 * {@inheritDoc} 474 */ 475 public String getJavaClass() { 476 return pJavaClass; 477 } 478 479 480 481 /** 482 * {@inheritDoc} 483 */ 484 public Class<? extends ConnectionHandlerCfg> configurationClass() { 485 return ConnectionHandlerCfg.class; 486 } 487 488 489 490 /** 491 * {@inheritDoc} 492 */ 493 public DN dn() { 494 return impl.getDN(); 495 } 496 497 } 498}