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