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 org.opends.server.admin.AdministratorAction; 031import org.opends.server.admin.BooleanPropertyDefinition; 032import org.opends.server.admin.ClassPropertyDefinition; 033import org.opends.server.admin.client.AuthorizationException; 034import org.opends.server.admin.client.CommunicationException; 035import org.opends.server.admin.client.ConcurrentModificationException; 036import org.opends.server.admin.client.ManagedObject; 037import org.opends.server.admin.client.MissingMandatoryPropertiesException; 038import org.opends.server.admin.client.OperationRejectedException; 039import org.opends.server.admin.DefaultBehaviorProvider; 040import org.opends.server.admin.DefinedDefaultBehaviorProvider; 041import org.opends.server.admin.ManagedObjectAlreadyExistsException; 042import org.opends.server.admin.ManagedObjectDefinition; 043import org.opends.server.admin.PropertyOption; 044import org.opends.server.admin.PropertyProvider; 045import org.opends.server.admin.server.ConfigurationChangeListener; 046import org.opends.server.admin.server.ServerManagedObject; 047import org.opends.server.admin.std.client.ExternalHTTPAccessLogPublisherCfgClient; 048import org.opends.server.admin.std.server.ExternalHTTPAccessLogPublisherCfg; 049import org.opends.server.admin.std.server.HTTPAccessLogPublisherCfg; 050import org.opends.server.admin.std.server.LogPublisherCfg; 051import org.opends.server.admin.StringPropertyDefinition; 052import org.opends.server.admin.Tag; 053import org.opends.server.admin.UndefinedDefaultBehaviorProvider; 054import org.opends.server.types.DN; 055 056 057 058/** 059 * An interface for querying the External HTTP Access Log Publisher 060 * managed object definition meta information. 061 * <p> 062 * External HTTP Access Log Publishers publish HTTP access messages to 063 * an external handler. 064 */ 065public final class ExternalHTTPAccessLogPublisherCfgDefn extends ManagedObjectDefinition<ExternalHTTPAccessLogPublisherCfgClient, ExternalHTTPAccessLogPublisherCfg> { 066 067 // The singleton configuration definition instance. 068 private static final ExternalHTTPAccessLogPublisherCfgDefn INSTANCE = new ExternalHTTPAccessLogPublisherCfgDefn(); 069 070 071 072 // The "config-file" property definition. 073 private static final StringPropertyDefinition PD_CONFIG_FILE; 074 075 076 077 // The "java-class" property definition. 078 private static final ClassPropertyDefinition PD_JAVA_CLASS; 079 080 081 082 // Build the "config-file" property definition. 083 static { 084 StringPropertyDefinition.Builder builder = StringPropertyDefinition.createBuilder(INSTANCE, "config-file"); 085 builder.setOption(PropertyOption.MANDATORY); 086 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.COMPONENT_RESTART, INSTANCE, "config-file")); 087 builder.setDefaultBehaviorProvider(new UndefinedDefaultBehaviorProvider<String>()); 088 builder.setPattern(".*", "FILE"); 089 PD_CONFIG_FILE = builder.getInstance(); 090 INSTANCE.registerPropertyDefinition(PD_CONFIG_FILE); 091 } 092 093 094 095 // Build the "java-class" property definition. 096 static { 097 ClassPropertyDefinition.Builder builder = ClassPropertyDefinition.createBuilder(INSTANCE, "java-class"); 098 builder.setOption(PropertyOption.MANDATORY); 099 builder.setOption(PropertyOption.ADVANCED); 100 builder.setAdministratorAction(new AdministratorAction(AdministratorAction.Type.NONE, INSTANCE, "java-class")); 101 DefaultBehaviorProvider<String> provider = new DefinedDefaultBehaviorProvider<String>("org.opends.server.loggers.CommonAuditHTTPAccessLogPublisher"); 102 builder.setDefaultBehaviorProvider(provider); 103 builder.addInstanceOf("org.opends.server.loggers.LogPublisher"); 104 PD_JAVA_CLASS = builder.getInstance(); 105 INSTANCE.registerPropertyDefinition(PD_JAVA_CLASS); 106 } 107 108 109 110 // Register the tags associated with this managed object definition. 111 static { 112 INSTANCE.registerTag(Tag.valueOf("logging")); 113 } 114 115 116 117 /** 118 * Get the External HTTP Access Log Publisher configuration 119 * definition singleton. 120 * 121 * @return Returns the External HTTP Access Log Publisher 122 * configuration definition singleton. 123 */ 124 public static ExternalHTTPAccessLogPublisherCfgDefn getInstance() { 125 return INSTANCE; 126 } 127 128 129 130 /** 131 * Private constructor. 132 */ 133 private ExternalHTTPAccessLogPublisherCfgDefn() { 134 super("external-http-access-log-publisher", HTTPAccessLogPublisherCfgDefn.getInstance()); 135 } 136 137 138 139 /** 140 * {@inheritDoc} 141 */ 142 public ExternalHTTPAccessLogPublisherCfgClient createClientConfiguration( 143 ManagedObject<? extends ExternalHTTPAccessLogPublisherCfgClient> impl) { 144 return new ExternalHTTPAccessLogPublisherCfgClientImpl(impl); 145 } 146 147 148 149 /** 150 * {@inheritDoc} 151 */ 152 public ExternalHTTPAccessLogPublisherCfg createServerConfiguration( 153 ServerManagedObject<? extends ExternalHTTPAccessLogPublisherCfg> impl) { 154 return new ExternalHTTPAccessLogPublisherCfgServerImpl(impl); 155 } 156 157 158 159 /** 160 * {@inheritDoc} 161 */ 162 public Class<ExternalHTTPAccessLogPublisherCfg> getServerConfigurationClass() { 163 return ExternalHTTPAccessLogPublisherCfg.class; 164 } 165 166 167 168 /** 169 * Get the "config-file" property definition. 170 * <p> 171 * The JSON configuration file that defines the External HTTP Access 172 * Log Publisher. The content of the JSON configuration file depends 173 * on the type of external audit event handler. The path to the file 174 * is relative to the server root. 175 * 176 * @return Returns the "config-file" property definition. 177 */ 178 public StringPropertyDefinition getConfigFilePropertyDefinition() { 179 return PD_CONFIG_FILE; 180 } 181 182 183 184 /** 185 * Get the "enabled" property definition. 186 * <p> 187 * Indicates whether the External HTTP Access Log Publisher is 188 * enabled for use. 189 * 190 * @return Returns the "enabled" property definition. 191 */ 192 public BooleanPropertyDefinition getEnabledPropertyDefinition() { 193 return HTTPAccessLogPublisherCfgDefn.getInstance().getEnabledPropertyDefinition(); 194 } 195 196 197 198 /** 199 * Get the "java-class" property definition. 200 * <p> 201 * The fully-qualified name of the Java class that provides the 202 * External HTTP Access Log Publisher implementation. 203 * 204 * @return Returns the "java-class" property definition. 205 */ 206 public ClassPropertyDefinition getJavaClassPropertyDefinition() { 207 return PD_JAVA_CLASS; 208 } 209 210 211 212 /** 213 * Managed object client implementation. 214 */ 215 private static class ExternalHTTPAccessLogPublisherCfgClientImpl implements 216 ExternalHTTPAccessLogPublisherCfgClient { 217 218 // Private implementation. 219 private ManagedObject<? extends ExternalHTTPAccessLogPublisherCfgClient> impl; 220 221 222 223 // Private constructor. 224 private ExternalHTTPAccessLogPublisherCfgClientImpl( 225 ManagedObject<? extends ExternalHTTPAccessLogPublisherCfgClient> impl) { 226 this.impl = impl; 227 } 228 229 230 231 /** 232 * {@inheritDoc} 233 */ 234 public String getConfigFile() { 235 return impl.getPropertyValue(INSTANCE.getConfigFilePropertyDefinition()); 236 } 237 238 239 240 /** 241 * {@inheritDoc} 242 */ 243 public void setConfigFile(String value) { 244 impl.setPropertyValue(INSTANCE.getConfigFilePropertyDefinition(), value); 245 } 246 247 248 249 /** 250 * {@inheritDoc} 251 */ 252 public Boolean isEnabled() { 253 return impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 254 } 255 256 257 258 /** 259 * {@inheritDoc} 260 */ 261 public void setEnabled(boolean value) { 262 impl.setPropertyValue(INSTANCE.getEnabledPropertyDefinition(), value); 263 } 264 265 266 267 /** 268 * {@inheritDoc} 269 */ 270 public String getJavaClass() { 271 return impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 272 } 273 274 275 276 /** 277 * {@inheritDoc} 278 */ 279 public void setJavaClass(String value) { 280 impl.setPropertyValue(INSTANCE.getJavaClassPropertyDefinition(), value); 281 } 282 283 284 285 /** 286 * {@inheritDoc} 287 */ 288 public ManagedObjectDefinition<? extends ExternalHTTPAccessLogPublisherCfgClient, ? extends ExternalHTTPAccessLogPublisherCfg> definition() { 289 return INSTANCE; 290 } 291 292 293 294 /** 295 * {@inheritDoc} 296 */ 297 public PropertyProvider properties() { 298 return impl; 299 } 300 301 302 303 /** 304 * {@inheritDoc} 305 */ 306 public void commit() throws ManagedObjectAlreadyExistsException, 307 MissingMandatoryPropertiesException, ConcurrentModificationException, 308 OperationRejectedException, AuthorizationException, 309 CommunicationException { 310 impl.commit(); 311 } 312 313 314 315 /** {@inheritDoc} */ 316 public String toString() { 317 return impl.toString(); 318 } 319 } 320 321 322 323 /** 324 * Managed object server implementation. 325 */ 326 private static class ExternalHTTPAccessLogPublisherCfgServerImpl implements 327 ExternalHTTPAccessLogPublisherCfg { 328 329 // Private implementation. 330 private ServerManagedObject<? extends ExternalHTTPAccessLogPublisherCfg> impl; 331 332 // The value of the "config-file" property. 333 private final String pConfigFile; 334 335 // The value of the "enabled" property. 336 private final boolean pEnabled; 337 338 // The value of the "java-class" property. 339 private final String pJavaClass; 340 341 342 343 // Private constructor. 344 private ExternalHTTPAccessLogPublisherCfgServerImpl(ServerManagedObject<? extends ExternalHTTPAccessLogPublisherCfg> impl) { 345 this.impl = impl; 346 this.pConfigFile = impl.getPropertyValue(INSTANCE.getConfigFilePropertyDefinition()); 347 this.pEnabled = impl.getPropertyValue(INSTANCE.getEnabledPropertyDefinition()); 348 this.pJavaClass = impl.getPropertyValue(INSTANCE.getJavaClassPropertyDefinition()); 349 } 350 351 352 353 /** 354 * {@inheritDoc} 355 */ 356 public void addExternalHTTPAccessChangeListener( 357 ConfigurationChangeListener<ExternalHTTPAccessLogPublisherCfg> listener) { 358 impl.registerChangeListener(listener); 359 } 360 361 362 363 /** 364 * {@inheritDoc} 365 */ 366 public void removeExternalHTTPAccessChangeListener( 367 ConfigurationChangeListener<ExternalHTTPAccessLogPublisherCfg> listener) { 368 impl.deregisterChangeListener(listener); 369 } 370 /** 371 * {@inheritDoc} 372 */ 373 public void addHTTPAccessChangeListener( 374 ConfigurationChangeListener<HTTPAccessLogPublisherCfg> listener) { 375 impl.registerChangeListener(listener); 376 } 377 378 379 380 /** 381 * {@inheritDoc} 382 */ 383 public void removeHTTPAccessChangeListener( 384 ConfigurationChangeListener<HTTPAccessLogPublisherCfg> listener) { 385 impl.deregisterChangeListener(listener); 386 } 387 /** 388 * {@inheritDoc} 389 */ 390 public void addChangeListener( 391 ConfigurationChangeListener<LogPublisherCfg> listener) { 392 impl.registerChangeListener(listener); 393 } 394 395 396 397 /** 398 * {@inheritDoc} 399 */ 400 public void removeChangeListener( 401 ConfigurationChangeListener<LogPublisherCfg> listener) { 402 impl.deregisterChangeListener(listener); 403 } 404 405 406 407 /** 408 * {@inheritDoc} 409 */ 410 public String getConfigFile() { 411 return pConfigFile; 412 } 413 414 415 416 /** 417 * {@inheritDoc} 418 */ 419 public boolean isEnabled() { 420 return pEnabled; 421 } 422 423 424 425 /** 426 * {@inheritDoc} 427 */ 428 public String getJavaClass() { 429 return pJavaClass; 430 } 431 432 433 434 /** 435 * {@inheritDoc} 436 */ 437 public Class<? extends ExternalHTTPAccessLogPublisherCfg> configurationClass() { 438 return ExternalHTTPAccessLogPublisherCfg.class; 439 } 440 441 442 443 /** 444 * {@inheritDoc} 445 */ 446 public DN dn() { 447 return impl.getDN(); 448 } 449 450 451 452 /** {@inheritDoc} */ 453 public String toString() { 454 return impl.toString(); 455 } 456 } 457}