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 2015 ForgeRock AS.
015 */
016package org.forgerock.audit;
017
018import static java.util.Collections.emptyList;
019
020import java.util.LinkedHashMap;
021import java.util.List;
022import java.util.Map;
023
024import com.fasterxml.jackson.annotation.JsonProperty;
025import com.fasterxml.jackson.annotation.JsonPropertyDescription;
026import org.forgerock.audit.filter.FilterPolicy;
027
028/**
029 * Configuration of the audit service.
030 * <p>
031 * This configuration object can be created from JSON. Example of valid JSON configuration:
032 * <pre>
033 *   {
034 *     "handlerForQueries" : "csv",
035 *     "availableAuditEventHandlers" : [
036 *          "org.forgerock.audit.events.handler.MyHandler",
037 *          "org.forgerock.audit.events.handler.AnotherHandler"
038 *     ],
039 *     "filterPolicies" : {
040 *         "field" : {
041 *             "excludeIf" : [],
042 *             "includeIf" : [
043 *                  "/access/filter/field"
044 *             ]
045 *         },
046 *         "value" : {
047 *             "excludeIf" : [],
048 *             "includeIf" : [
049 *                  "/access/filter/value"
050 *             ]
051 *         }
052 *     }
053 *   }
054 * </pre>
055 */
056public class AuditServiceConfiguration {
057
058    @JsonProperty(required = true)
059    @JsonPropertyDescription("audit.service.handlerForQueries")
060    private String handlerForQueries;
061
062    @JsonPropertyDescription("audit.service.availableAuditEventHandlers")
063    private List<String> availableAuditEventHandlers;
064
065    @JsonPropertyDescription("audit.service.filter.policies")
066    private Map<String, FilterPolicy> filterPolicies = new LinkedHashMap<>();
067
068    /**
069     * Empty constructor.
070     */
071    public AuditServiceConfiguration() {
072        // empty constructor
073    }
074
075    /**
076     * Copy-constructor, in order to obtain a copy from an existing configuration.
077     *
078     * @param config an existing configuration
079     */
080    public AuditServiceConfiguration(AuditServiceConfiguration config) {
081        handlerForQueries = config.getHandlerForQueries();
082        availableAuditEventHandlers = config.availableAuditEventHandlers;
083    }
084
085    /**
086     * Returns the name of the handler to use for querying the audit events.
087     *
088     * @return the name of the handler.
089     */
090    public String getHandlerForQueries() {
091        return handlerForQueries;
092    }
093
094    /**
095     * Sets the name of the handler to use for querying the audit events.
096     *
097     * @param name
098     *            the name of the handler.
099     */
100    public void setHandlerForQueries(String name) {
101        handlerForQueries = name;
102    }
103
104    /**
105     * Returns a list of class names of available audit event handlers.
106     *
107     * @return the list of available audit event handlers.
108     */
109    public List<String> getAvailableAuditEventHandlers() {
110        if (availableAuditEventHandlers == null) {
111            return emptyList();
112        } else {
113            return availableAuditEventHandlers;
114        }
115    }
116
117    /**
118     * Sets the list of available audit event handlers.
119     *
120     * @param availableAuditEventHandlers the list of available audit event handlers.
121     */
122    public void setAvailableAuditEventHandlers(List<String> availableAuditEventHandlers) {
123        this.availableAuditEventHandlers = availableAuditEventHandlers;
124    }
125
126    public Map<String, FilterPolicy> getFilterPolicies() {
127        return filterPolicies;
128    }
129
130    public void setFilterPolicies(Map<String, FilterPolicy> filterPolicies) {
131        this.filterPolicies.putAll(filterPolicies);
132    }
133}