e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi/*
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * CDDL HEADER START
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi *
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * The contents of this file are subject to the terms of the
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * Common Development and Distribution License, Version 1.0 only
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * (the "License"). You may not use this file except in compliance
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * with the License.
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi *
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * or http://forgerock.org/license/CDDLv1.0.html.
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * See the License for the specific language governing permissions
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * and limitations under the License.
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi *
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * When distributing Covered Code, include this CDDL HEADER in each
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * file and include the License file at legal-notices/CDDLv1_0.txt.
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * If applicable, add the following below this CDDL HEADER, with the
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * fields enclosed by brackets "[]" replaced with your own identifying
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * information:
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * Portions Copyright [yyyy] [name of copyright owner]
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi *
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * CDDL HEADER END
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi *
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi *
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * Copyright 2013-2015 ForgeRock AS
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi */
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponipackage org.opends.server.protocols.http;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponiimport org.forgerock.http.Filter;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponiimport org.forgerock.http.Handler;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponiimport org.forgerock.http.protocol.Request;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponiimport org.forgerock.http.protocol.Response;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponiimport org.forgerock.services.context.Context;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponiimport org.forgerock.util.promise.NeverThrowsException;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponiimport org.forgerock.util.promise.Promise;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponiimport org.opends.server.core.ServerContext;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi/**
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * Filter that checks if at least one HTTP access logger is enabled for common audit, and short-circuit
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi * the corresponding filter if this is not the case.
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi */
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponiclass CommonAuditHttpAccessCheckEnabledFilter implements Filter
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi{
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi private final ServerContext serverContext;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi /** The HTTP access audit filter to go through if HTTP access logger is enabled. */
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi private final Filter httpAccessAuditFilter;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi CommonAuditHttpAccessCheckEnabledFilter(ServerContext serverContext, Filter httpAccessAuditFilter)
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi {
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi this.serverContext = serverContext;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi this.httpAccessAuditFilter = httpAccessAuditFilter;
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi }
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi @Override
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi public Promise<Response, NeverThrowsException> filter(
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi final Context context, final Request request, final Handler next)
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi {
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi if (serverContext.getCommonAudit().isHttpAccessLogEnabled())
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi {
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi // introduce HttpAccessAuditFilter into the filter chain
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi return httpAccessAuditFilter.filter(context, request, next);
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi }
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi // avoid HttpAccessAuditFilter, follow the filter chain
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi return next.handle(context, request);
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi }
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi
e433824f46514e6ed863eb6b95c70038331c8c24Nicolas Capponi}