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