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