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 2006-2009 Sun Microsystems, Inc. 015 * Portions Copyright 2011-2015 ForgeRock AS. 016 */ 017package org.opends.server.loggers; 018import java.util.Collection; 019 020import org.forgerock.i18n.LocalizableMessage; 021import org.opends.server.admin.ClassPropertyDefinition; 022import org.opends.server.admin.std.meta.AccessLogPublisherCfgDefn; 023import org.opends.server.admin.std.server.AccessLogPublisherCfg; 024import org.opends.server.api.ClientConnection; 025import org.opends.server.core.*; 026import org.opends.server.types.DisconnectReason; 027import org.opends.server.types.SearchResultEntry; 028import org.opends.server.types.SearchResultReference; 029 030import static org.opends.messages.ConfigMessages.*; 031 032/** 033 * This class defines the wrapper that will invoke all registered access loggers 034 * for each type of request received or response sent. 035 */ 036public class AccessLogger extends AbstractLogger 037 <AccessLogPublisher<AccessLogPublisherCfg>, AccessLogPublisherCfg> 038{ 039 040 private static LoggerStorage 041 <AccessLogPublisher<AccessLogPublisherCfg>, AccessLogPublisherCfg> 042 loggerStorage = new LoggerStorage<>(); 043 044 /** The singleton instance of this class. */ 045 private static final AccessLogger instance = new AccessLogger(); 046 047 /** 048 * The constructor for this class. 049 */ 050 private AccessLogger() 051 { 052 super((Class) AccessLogPublisher.class, 053 ERR_CONFIG_LOGGER_INVALID_ACCESS_LOGGER_CLASS); 054 } 055 056 /** {@inheritDoc} */ 057 @Override 058 protected ClassPropertyDefinition getJavaClassPropertyDefinition() 059 { 060 return AccessLogPublisherCfgDefn.getInstance() 061 .getJavaClassPropertyDefinition(); 062 } 063 064 /** {@inheritDoc} */ 065 @Override 066 protected Collection<AccessLogPublisher<AccessLogPublisherCfg>> getLogPublishers() 067 { 068 return loggerStorage.getLogPublishers(); 069 } 070 071 /** 072 * Retrieve the singleton instance of this class. 073 * 074 * @return The singleton instance of this logger. 075 */ 076 public static AccessLogger getInstance() 077 { 078 return instance; 079 } 080 081 /** 082 * Returns all the registered access log publishers. 083 * 084 * @return a Collection of {@link AccessLogPublisher} objects 085 */ 086 private static Collection 087 <AccessLogPublisher<AccessLogPublisherCfg>> getAccessLogPublishers() 088 { 089 return loggerStorage.getLogPublishers(); 090 } 091 092 093 /** 094 * Writes a message to the access logger with information about a new client 095 * connection that has been established, regardless of whether it will be 096 * immediately terminated. 097 * 098 * @param clientConnection The client connection that has been established. 099 */ 100 public static void logConnect(ClientConnection clientConnection) 101 { 102 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 103 { 104 publisher.logConnect(clientConnection); 105 } 106 } 107 108 109 110 /** 111 * Writes a message to the access logger with information about the 112 * termination of an existing client connection. 113 * 114 * @param clientConnection The client connection that has been terminated. 115 * @param disconnectReason A generic disconnect reason for the connection 116 * termination. 117 * @param message A human-readable message that can provide 118 * additional information about the disconnect. 119 */ 120 public static void logDisconnect(ClientConnection clientConnection, 121 DisconnectReason disconnectReason, 122 LocalizableMessage message) 123 { 124 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 125 { 126 publisher.logDisconnect(clientConnection, disconnectReason, message); 127 } 128 } 129 130 131 132 /** 133 * Writes a message to the access logger with information about the abandon 134 * request associated with the provided abandon operation. 135 * 136 * @param abandonOperation The abandon operation containing the information 137 * to use to log the abandon request. 138 */ 139 public static void logAbandonRequest(AbandonOperation abandonOperation) 140 { 141 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 142 { 143 publisher.logAbandonRequest(abandonOperation); 144 } 145 } 146 147 148 149 /** 150 * Writes a message to the access logger with information about the result of 151 * the provided abandon operation. 152 * 153 * @param abandonOperation The abandon operation containing the information 154 * to use to log the abandon result. 155 */ 156 public static void logAbandonResult(AbandonOperation abandonOperation) 157 { 158 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 159 { 160 publisher.logAbandonResult(abandonOperation); 161 } 162 } 163 164 165 166 /** 167 * Writes a message to the access logger with information about the add 168 * request associated with the provided add operation. 169 * 170 * @param addOperation The add operation containing the information to use 171 * to log the add request. 172 */ 173 public static void logAddRequest(AddOperation addOperation) 174 { 175 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 176 { 177 publisher.logAddRequest(addOperation); 178 } 179 } 180 181 182 183 /** 184 * Writes a message to the access logger with information about the add 185 * response associated with the provided add operation. 186 * 187 * @param addOperation The add operation containing the information to use 188 * to log the add response. 189 */ 190 public static void logAddResponse(AddOperation addOperation) 191 { 192 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 193 { 194 publisher.logAddResponse(addOperation); 195 } 196 } 197 198 199 200 /** 201 * Writes a message to the access logger with information about the bind 202 * request associated with the provided bind operation. 203 * 204 * @param bindOperation The bind operation containing the information to use 205 * to log the bind request. 206 */ 207 public static void logBindRequest(BindOperation bindOperation) 208 { 209 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 210 { 211 publisher.logBindRequest(bindOperation); 212 } 213 } 214 215 216 217 /** 218 * Writes a message to the access logger with information about the bind 219 * response associated with the provided bind operation. 220 * 221 * @param bindOperation The bind operation containing the information to use 222 * to log the bind response. 223 */ 224 public static void logBindResponse(BindOperation bindOperation) 225 { 226 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 227 { 228 publisher.logBindResponse(bindOperation); 229 } 230 } 231 232 233 234 /** 235 * Writes a message to the access logger with information about the compare 236 * request associated with the provided compare operation. 237 * 238 * @param compareOperation The compare operation containing the information 239 * to use to log the compare request. 240 */ 241 public static void logCompareRequest(CompareOperation compareOperation) 242 { 243 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 244 { 245 publisher.logCompareRequest(compareOperation); 246 } 247 } 248 249 250 251 /** 252 * Writes a message to the access logger with information about the compare 253 * response associated with the provided compare operation. 254 * 255 * @param compareOperation The compare operation containing the information 256 * to use to log the compare response. 257 */ 258 public static void logCompareResponse(CompareOperation compareOperation) 259 { 260 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 261 { 262 publisher.logCompareResponse(compareOperation); 263 } 264 } 265 266 267 268 /** 269 * Writes a message to the access logger with information about the delete 270 * request associated with the provided delete operation. 271 * 272 * @param deleteOperation The delete operation containing the information to 273 * use to log the delete request. 274 */ 275 public static void logDeleteRequest(DeleteOperation deleteOperation) 276 { 277 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 278 { 279 publisher.logDeleteRequest(deleteOperation); 280 } 281 } 282 283 284 285 /** 286 * Writes a message to the access logger with information about the delete 287 * response associated with the provided delete operation. 288 * 289 * @param deleteOperation The delete operation containing the information to 290 * use to log the delete response. 291 */ 292 public static void logDeleteResponse(DeleteOperation deleteOperation) 293 { 294 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 295 { 296 publisher.logDeleteResponse(deleteOperation); 297 } 298 } 299 300 301 302 /** 303 * Writes a message to the access logger with information about the extended 304 * request associated with the provided extended operation. 305 * 306 * @param extendedOperation The extended operation containing the 307 * information to use to log the extended request. 308 */ 309 public static void logExtendedRequest(ExtendedOperation extendedOperation) 310 { 311 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 312 { 313 publisher.logExtendedRequest(extendedOperation); 314 } 315 } 316 317 318 319 /** 320 * Writes a message to the access logger with information about the extended 321 * response associated with the provided extended operation. 322 * 323 * @param extendedOperation The extended operation containing the 324 * information to use to log the extended response. 325 */ 326 public static void logExtendedResponse(ExtendedOperation extendedOperation) 327 { 328 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 329 { 330 publisher.logExtendedResponse(extendedOperation); 331 } 332 } 333 334 335 336 /** 337 * Writes a message to the access logger with information about the modify 338 * request associated with the provided modify operation. 339 * 340 * @param modifyOperation The modify operation containing the information to 341 * use to log the modify request. 342 */ 343 public static void logModifyRequest(ModifyOperation modifyOperation) 344 { 345 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 346 { 347 publisher.logModifyRequest(modifyOperation); 348 } 349 } 350 351 352 353 /** 354 * Writes a message to the access logger with information about the modify 355 * response associated with the provided modify operation. 356 * 357 * @param modifyOperation The modify operation containing the information to 358 * use to log the modify response. 359 */ 360 public static void logModifyResponse(ModifyOperation modifyOperation) 361 { 362 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 363 { 364 publisher.logModifyResponse(modifyOperation); 365 } 366 } 367 368 369 370 /** 371 * Writes a message to the access logger with information about the modify DN 372 * request associated with the provided modify DN operation. 373 * 374 * @param modifyDNOperation The modify DN operation containing the 375 * information to use to log the modify DN request. 376 */ 377 public static void logModifyDNRequest(ModifyDNOperation modifyDNOperation) 378 { 379 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 380 { 381 publisher.logModifyDNRequest(modifyDNOperation); 382 } 383 } 384 385 386 387 /** 388 * Writes a message to the access logger with information about the modify DN 389 * response associated with the provided modify DN operation. 390 * 391 * @param modifyDNOperation The modify DN operation containing the 392 * information to use to log the modify DN 393 * response. 394 */ 395 public static void logModifyDNResponse(ModifyDNOperation modifyDNOperation) 396 { 397 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 398 { 399 publisher.logModifyDNResponse(modifyDNOperation); 400 } 401 } 402 403 404 405 /** 406 * Writes a message to the access logger with information about the search 407 * request associated with the provided search operation. 408 * 409 * @param searchOperation The search operation containing the information to 410 * use to log the search request. 411 */ 412 public static void logSearchRequest(SearchOperation searchOperation) 413 { 414 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 415 { 416 publisher.logSearchRequest(searchOperation); 417 } 418 } 419 420 421 422 /** 423 * Writes a message to the access logger with information about the search 424 * result entry that matches the criteria associated with the provided search 425 * operation. 426 * 427 * @param searchOperation The search operation with which the search result 428 * entry is associated. 429 * @param searchEntry The search result entry to be logged. 430 */ 431 public static void logSearchResultEntry(SearchOperation searchOperation, 432 SearchResultEntry searchEntry) 433 { 434 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 435 { 436 publisher.logSearchResultEntry(searchOperation, searchEntry); 437 } 438 } 439 440 441 442 /** 443 * Writes a message to the access logger with information about the search 444 * result reference returned while processing the associated search operation. 445 * 446 * @param searchOperation The search operation with which the search result 447 * reference is associated. 448 * @param searchReference The search result reference to be logged. 449 */ 450 public static void logSearchResultReference(SearchOperation searchOperation, 451 SearchResultReference searchReference) 452 { 453 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 454 { 455 publisher.logSearchResultReference(searchOperation, searchReference); 456 } 457 } 458 459 460 461 /** 462 * Writes a message to the access logger with information about the completion 463 * of the provided search operation. 464 * 465 * @param searchOperation The search operation containing the information 466 * to use to log the search result done message. 467 */ 468 public static void logSearchResultDone(SearchOperation searchOperation) 469 { 470 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 471 { 472 publisher.logSearchResultDone(searchOperation); 473 } 474 } 475 476 477 478 /** 479 * Writes a message to the access logger with information about the unbind 480 * request associated with the provided unbind operation. 481 * 482 * @param unbindOperation The unbind operation containing the information to 483 * use to log the unbind request. 484 */ 485 public static void logUnbind(UnbindOperation unbindOperation) 486 { 487 for (AccessLogPublisher<?> publisher : getAccessLogPublishers()) 488 { 489 publisher.logUnbind(unbindOperation); 490 } 491 } 492 493 /** {@inheritDoc} */ 494 @Override 495 public final synchronized void addLogPublisher( 496 AccessLogPublisher<AccessLogPublisherCfg> publisher) 497 { 498 loggerStorage.addLogPublisher(publisher); 499 } 500 501 /** {@inheritDoc} */ 502 @Override 503 public final synchronized boolean removeLogPublisher( 504 AccessLogPublisher<AccessLogPublisherCfg> publisher) 505 { 506 return loggerStorage.removeLogPublisher(publisher); 507 } 508 509 @Override 510 public final synchronized void removeAllLogPublishers() 511 { 512 loggerStorage.removeAllLogPublishers(); 513 // Access logger may have not been fully initialized 514 if (getServerContext() != null && getServerContext().getCommonAudit() != null) 515 { 516 getServerContext().getCommonAudit().shutdown(); 517 } 518 } 519} 520