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 * Portions Copyright 2013-2015 ForgeRock AS 025 */ 026package org.opends.server.loggers; 027 028import static org.opends.messages.ConfigMessages.*; 029 030import java.util.Collection; 031 032import org.opends.server.admin.ClassPropertyDefinition; 033import org.opends.server.admin.std.meta.HTTPAccessLogPublisherCfgDefn; 034import org.opends.server.admin.std.server.HTTPAccessLogPublisherCfg; 035 036/** 037 * This class defines the wrapper that will invoke all registered HTTP access 038 * loggers for each type of request received or response sent. 039 */ 040public class HTTPAccessLogger extends AbstractLogger 041<HTTPAccessLogPublisher<HTTPAccessLogPublisherCfg>, HTTPAccessLogPublisherCfg> 042{ 043 044 private static LoggerStorage 045 <HTTPAccessLogPublisher<HTTPAccessLogPublisherCfg>, HTTPAccessLogPublisherCfg> 046 loggerStorage = new LoggerStorage<>(); 047 048 /** The singleton instance of this class for configuration purposes. */ 049 private static final HTTPAccessLogger instance = new HTTPAccessLogger(); 050 051 /** 052 * The constructor for this class. 053 */ 054 private HTTPAccessLogger() 055 { 056 super((Class) HTTPAccessLogPublisher.class, 057 ERR_CONFIG_LOGGER_INVALID_HTTP_ACCESS_LOGGER_CLASS); 058 } 059 060 /** {@inheritDoc} */ 061 @Override 062 protected ClassPropertyDefinition getJavaClassPropertyDefinition() 063 { 064 return HTTPAccessLogPublisherCfgDefn.getInstance() 065 .getJavaClassPropertyDefinition(); 066 } 067 068 /** {@inheritDoc} */ 069 @Override 070 protected Collection<HTTPAccessLogPublisher<HTTPAccessLogPublisherCfg>> getLogPublishers() 071 { 072 return loggerStorage.getLogPublishers(); 073 } 074 075 /** 076 * Retrieve the singleton instance of this class. 077 * 078 * @return The singleton instance of this logger. 079 */ 080 public static HTTPAccessLogger getInstance() 081 { 082 return instance; 083 } 084 085 /** 086 * Returns all the registered HTTP access log publishers. 087 * 088 * @return a Collection of {@link HTTPAccessLogPublisher} objects 089 */ 090 public static Collection<HTTPAccessLogPublisher<HTTPAccessLogPublisherCfg>> 091 getHTTPAccessLogPublishers() 092 { 093 return loggerStorage.getLogPublishers(); 094 } 095 096 /** 097 * Logs the given HTTPRequestInfo. 098 * 099 * @param requestInfo 100 * the HTTP request info to log 101 */ 102 public static void logRequestInfo(HTTPRequestInfo requestInfo) 103 { 104 for (HTTPAccessLogPublisher<?> publisher : loggerStorage.getLogPublishers()) 105 { 106 publisher.logRequestInfo(requestInfo); 107 } 108 } 109 110 /** {@inheritDoc} */ 111 @Override 112 public final synchronized void addLogPublisher( 113 HTTPAccessLogPublisher<HTTPAccessLogPublisherCfg> publisher) 114 { 115 loggerStorage.addLogPublisher(publisher); 116 } 117 118 /** {@inheritDoc} */ 119 @Override 120 public final synchronized boolean removeLogPublisher( 121 HTTPAccessLogPublisher<HTTPAccessLogPublisherCfg> publisher) 122 { 123 return loggerStorage.removeLogPublisher(publisher); 124 } 125 126 @Override 127 public final synchronized void removeAllLogPublishers() 128 { 129 loggerStorage.removeAllLogPublishers(); 130 // Access logger may have not been fully initialized 131 if (getServerContext() != null && getServerContext().getCommonAudit() != null) 132 { 133 getServerContext().getCommonAudit().shutdown(); 134 } 135 } 136 137}